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

resetModels when usingFixtureAdapter? #56

Closed
blimmer opened this issue Jan 19, 2015 · 6 comments
Closed

resetModels when usingFixtureAdapter? #56

blimmer opened this issue Jan 19, 2015 · 6 comments

Comments

@blimmer
Copy link

blimmer commented Jan 19, 2015

We override the useFixtureAdapter call in FactoryGuyTestMixin because it conveniently sets all fixtures to an empty array. If we don't call it, we get these errors:

Error: Error: Assertion Failed: Unable to find fixtures for model type App.ModelType)

We override the FactoryGuyTestMixin like this to fix the problem:

Ember.lookup.TestHelper = (Ember.Object.extend FactoryGuyTestMixin,
  useFixtureAdapter: ->
    @_super.apply(@, arguments)
    FactoryGuy.resetModels(@getStore())
).create()

Is there any downside to having FactoryGuy do resetModels when calling useFixtureAdapter? I'm happy to do the PR if this behavior is acceptable.

@danielspaniel
Copy link
Collaborator

@blimmer , hmm .. I am thinking that this is not a great way to go, since the resetModels is usually called at the end of the test run in teardown .. or can also be called at the beginning. I see what you mean though about wanting to reset the Fixture arrays, but maybe you can call this in your test setup or override the setup method in the FactoryGuyTestMixin to accomplish the same thing?

@blimmer
Copy link
Author

blimmer commented Jan 19, 2015

The part of resetModels that is helpful where it iterates over all the factory definitions and sets the .FIXTURES to an empty array. I like using resetModels because it iterates over all of the factories and initializes the arrays properly.

I am not really relying on anything else that resetModels does. I could create empty fixture definitions for all of them in the model definition, but it's code that's not useful in a production environment since I only use fixtures in test.

No big deal, this might not be useful for the ED FactoryGuy community as a whole just wanted to bring it up.

@danielspaniel
Copy link
Collaborator

Just curious @blimmer, have you tried NOT using FixtureAdapter in your tests, and using the REST or ActiveModel adapter instead ( assuming you are using one of those in your application )? Most people don't ever need to use FixtureAdapter when using FactoryGuy, since it handles the REST adapters just fine.

@ksykulev
Copy link
Contributor

@blimmer - Just curious, what are you calling to get

Error: Error: Assertion Failed: Unable to find fixtures for model type App.ModelType)

Are you invoking some sort of store.find on a model? Do you happen to have any small snippets of example tests you can share?

Perhaps we can do something at the store level when using the fixture adapter to lazily add an empty fixture array if it's not already present.

@danielspaniel
Copy link
Collaborator

Going to close this, since the fixture adapter is no longer supported.

@ksykulev
Copy link
Contributor

👍

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

3 participants