Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

You can no longer create model fragments on their own using make or makeList #238

Closed
patocallaghan opened this issue Sep 5, 2016 · 6 comments

Comments

@patocallaghan
Copy link
Collaborator

Since 8e2dca2, which removes ids from model fragments, you can no longer make or makeList model fragments on their own. This is something we do in some our component integration tests where the components operate solely on model fragments, rather than the whole model.

Trying to do so results in the following error: Assertion Failed: You must include an 'id' for ... in an object passed to 'push', I guess because we are trying to push models to the store which have no id.

I understand this is working as expected, and the way it worked before was probably a bit of a hack. We can get around the problem by creating the parent ember data model and accessing the fragments through that but requires a bit more work, e.g. setting up associations etc.

Unless you have any other ideas?

@danielspaniel
Copy link
Collaborator

Boy, this is a tricky one.
Mmm .. pondering .. mmm ..

How about maybe set a flag like showMeTheIdPlease: true ? in the modelDefinition ??
or something slightly less ridiculous.

@danielspaniel
Copy link
Collaborator

or maybe use transient attributes and afterMake function
https://github.com/danielspaniel/ember-data-factory-guy#callbacks
would that work?

@patocallaghan
Copy link
Collaborator Author

Yeah, I know this is working as expected now so I don't necessarily expect it to be something that's supported. If it's a hacky fix I'd been inclined to leave it as is. One thing I did find when I was trying to make models inline in the test it didn't work as I expected it to. It seemed to be expected the property name to be the name of the factory which isn't the case. I'll try and add a test to replicate.

I'll give that afterMake a shot.

@danielspaniel
Copy link
Collaborator

I wish I could understand why you need this kind of thing ( to make a fragment on it'd own ) .. and then put it in the store.
Maybe I would get more ideas.

I definitely make fragments in my tests but I always build them ( not make ) and then pass them to the model or whatever.

@patocallaghan
Copy link
Collaborator Author

Well I guess it's just a shortcut. The components I'm testing don't get passed the whole ember data model, just the model fragment. So in my tests rather than having to create the whole model we were just creating the fragment on its own using make and passing that. It's an edge-case I know, but was just surprised when I tried updating factory guy today and had 30 failing tests.

I can resolve it by just creating the parent ember model instead, but was just checking if you had any ideas for a workaround. I wouldn't waste time on supporting this as in fairness it is working as expected 😄

@patocallaghan
Copy link
Collaborator Author

Going to close this as I don't think it's actionable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants