Releases: adopted-ember-addons/ember-data-factory-guy
v2.13.11
v2.13.10
- Does not blow up anymore when using fastboot #282
- Switched to using pretender from jquery.mockjax
- No more jquery bower dependency ( though Ember still uses it )
- Of course you can not use factory guy to produce fastboot data since pretender does not support fetch
Since mockjax is gone, I added a simple mock
command for allowing ad hoc mocking of urls
Where you used to do this:
$.mockjax({url:'/bugs-bunny', type: 'GET', responseText: { says: "what's up doc"}});
Now you would do this:
import {mock} from 'ember-data-factory-guy';
mock({url:'/bugs-bunny', type: 'GET', responseText: { says: "what's up doc"}});
One more thing to remember, mockjax was nice in that it only mocked what you told it to, and everything else passed through to be a real network request. Pretender stops everything from getting through so you have to setup passThrough url's if you want them to get through the pretender firewall.
Unfortunately you can not do passthroughs yet .. but you will soon.
v2.13.8
v2.13.7
v2.13.6
v2.13.5
- new method
singleUse()
added to mock requests- sets a mock to be single use, so it will disable itself after it handles a request
Example:
You want to be able to mock that 2 models are created, with different id's.
let user1 = build('user');
let user2 = build('user');
mockCreate('user').returns({ attrs: { id: user1.get('id') } }).singleUse();
mockCreate('user').returns({ attrs: { id: user2.get('id') } });
Ember.run(async () => {
let model1 = FactoryGuy.store.createRecord('user', user1.get());
await model1.save();
assert.equal(model1.id, user1.get('id'));
});
Ember.run(async () => {
let model2 = FactoryGuy.store.createRecord('user', user2.get());
await model2.save();
assert.equal(model2.id, user2.get('id'));
});
The url for mockCreate('user') is '/users' so the first mock will be used every time since it matches '/users'.
Unless you turn that first mock off you can't mockCreate the same model more than once in a test and therefore in you application code that makes a few of the same models.
v2.13.4
- Fixing issue when mockFindAll is used before mockQuery #298
- mockFindAll was handing a mockQuery request when the mockFindAll was declared before the mockQuery
Now, with the fix, the order does not matter. Though, take note, that the mockFindAll ( when declared before a mockQuery ) will still match a store.query request IF you don't actually query for anything, like this for example: this.store.query('users', {})
v2.13.3
- fixes
mockFindRecord('modelName').returns({json})
when the json payload was a plain javascript object.- sometimes you just want to throw some plain json into the returns, and not a build('modelName') payload. And that was not working
Example:
// usually you would do this
let json = build('user', {name: 'Bob'});
let mock = mockFindRecord('modelName').returns({json});
mock.get('id') //=> 1
// but if you did this:
let json = {data: {id: 1, type: 'user', attributes: { name: 'Bob' }}}; // your own custom payload
let mock = mockFindRecord('modelName').returns({json});
mock.get('id') //=> thew exception
v2.13.2
- fixture converter now passes attribute transformer
serialize
function that is properly scoped to the transformer- without this fix the serialize method had no scope .. so you could not access any properties the transformer might offer you.
v2.13.1
- Can now pass adapterOptions to findRecord and findAll
Example:
let mock1 = mockFindRecord('user').adapterOptions({friendly: true});
let mock2 = mockFindAll('user').adapterOptions({friendly: true});
Therefore, if you have an adapter method 'urlForFindRecord' or 'urlForFindAll', these adapterOptions will be passed in like so.
urlForFindRecord(id, modelName, snapshot) {
if (snapshot && snapshot.adapterOptions) {
let { adapterOptions } = snapshot;
... blah blah blah
}
... blah blah
}