Releases: adopted-ember-addons/ember-data-factory-guy
Releases · adopted-ember-addons/ember-data-factory-guy
v3.2.1
- BREAKING change for links syntax
- You can setup data AND links for your async relationship
- Need special care with multiple traits setting links
FactoryGuy.define('user', {
traits: {
withCompanyLink(f): {
// since you can assign many different links with different traits,
// you should Object.assign so that you add to the links hash rather
// than set it directly ( assuming you want to use this feature )
f.links = Object.assign({company: `/users/${f.id}/company`}, f.links);
},
withPropertiesLink(f) {
f.links = Object.assign({properties: `/users/${f.id}/properties`}, f.links);
}
}
});
let company = make('company')
// Setting a company model AND links for your async company relationship
let user = make('user', 'withCompanyLink', 'withPropertiesLink', {company});
// both links are setup
user.hasMany('properties').link(); // => "/users/1/properties"
user.belongsTo('company').link(); // => "/users/1/company"
// the company async relationship has a company AND link to fetch it again
user.get('company.content') // => company
// when you reload that relationship
user.belongsTo('company').reload() // would use that link "/users/1/company" to reload company
Sorry to change this syntax, but the syntax and behaviour now exactly matches how Ember Data handles links,
and this give you way more power than previous versions of FactoryGuy allowed you to have.
v3.2.0
- bump Ember Data and friends to 3.2
- clean up helper utilities to no longer use
__container__
and just use owner
v3.1.7
- made parseUrl more robust ( was affecting mockLinks update from v.3.1.6 )
v3.1.6
- Improve mockLinks to handle url with query parameters.
- links are kind of a black box that you can not touch very easily, and the mockLinks helper allows you to mock a links relationship, but now that works for links with query parameters so life is better again
Example:
let propertiesLink = '/users/1/properties?dudes=2',
user = make('user', {properties: {links: propertiesLink}}),
json = buildList('property', 1),
mockProperties = mockLinks(user, 'properties').returns({json});
const properties = await user.properties.toArray(); // 1 property model
-
mockLinks automatically breaks that url apart into the url and query params for you
-
alternatively you could use mock
mock({url: '/users/1/properties/'}).withParams({dudes: 2}).returns(json);
v3.1.5
- fixes using makeList, buildList when specifying 0 #348 @patocallaghan @lorcan
Example:
let noUsers1 = makeList('user', 0);
let noUsers2 = makeList('user', 0, 'with_hats', {name: 'Pat'});
Both of these now correctly give you no users ( empty list )
v3.1.4
- mock ( used for mocking any url ) can now handle query parameters
Example:
const type = 'GET',
url = '/api/get-stuff',
whatsUp = {whats: 'up'},
message = {message: 'nothing much doc'}
let theMock = mock({url}).withParams(whatsUp).returns(message);
let json = await Ember.$.ajax({type, url, data: whatsUp});
json // => {message: 'nothing much doc'}
v3.1.3
- fixes #344 to pass in request body when matching mockUpdates with function @roschaefer
mockCreate('project').match(requestBody => {
return requestBody.data.attributes.title === 'titleToMatch';
});
v3.1.2
v3.1.1
- use run.join in make function #339 @Subtletree
- add getPretender function #338 @ryedeer
v3.1.0
- bump ember source/ data / cli to 3.1