Ember CLI Fixture Loader
An ember-cli addon to keep your fixtures separate from your models.
Install
Install the addon and run the ember-cli blueprint.
npm install ember-cli-fixture-loader --save
Fixture Generation
To generate fixture with standard syntax:
ember generate fixture <model-name>
ember generate fixture <model-name> --pod
It will generate app/fixtures/tag.js
and app/pods/tag/fixture.js
respectively
Configuration
This addon can be configured in environment config:
ENVFIXTURES = enabled: true;
enabled: true/false
- control whether fixture addon will search for fixtures or not.
Also you can use this setting in adapter to control which adapter should be used.
Usage
Model.reopenClass({...})
will be handled automatically based on where fixture for model can be found:
Example /app/models/post.js
; Model;
Example /app/fixtures/post.js
or /app/pods/post/fixture.js
id: 1 title: 'Example' id: 2 title: 'Example 2' ;
FixtureAdapter per environment control
If you want to dynamically control adapter based on enabled or disabled Fixtures setting, you can do it easily in application adapter:
;; var adapter = DSRESTAdapter; if ConfigurationFIXTURESenabled adapter = DSFixtureAdapter; ;
Also you can control adapter by each model type, consider case when part of the API was released but other part is in development.
Troubleshooting
Error while processing route: templates Assertion Failed: Unable to find fixtures for model type
you have enabled Fixture adapter for the model, which do not have fixtures but you request this model via store. Add fixture for this model.
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request