Releases: adopted-ember-addons/ember-data-factory-guy
Releases · adopted-ember-addons/ember-data-factory-guy
v3.0.1
v2.18.0
v2.16.0
v2.15.0
v3.0.0
v2.13.27
- adding the method attributesFor to allow you to make attributes for a model
- use the traits and object override format just like with build/make
- For now the relationships are NOT available. That will have to wait for future release .. so stay tuned
Example:
import { attributesFor } from 'ember-data-factory-guy';
let attrs = attributesFor('user'); // =>
/**
{
"name": "User1",
"style": "normal"
};
*/
attrs = attributesFor('user' , 'silly'); // =>
/**
{
"name": "User1",
"style": "silly"
};
*/
v2.13.26
- fixes #328 @Turbo87
- adds new setupFactoryGuy(hooks) method for use in tests ( acceptance, integration, unit )
Sample usage:
module('Acceptance | User View', function(hooks) {
setupApplicationTest(hooks);
setupFactoryGuy(hooks);
test("blah blah", async function(assert) {
await visit('work');
assert.ok('bah was spoken');
});
});
v2.13.25
- mock now allows for inline returns
let users = buildList('user', 4);
let userMock = mock({url: '/users'}).returns(users);
v2.13.24
Streamline manualSetup usage to only need this:
hooks.beforeEach(async function() {
manualSetup(this); // <= easy peasy
]);
Add support for links tags in a payload ( for async belongsTo/hasMany relationships )
- Links can be setup in factories
import FactoryGuy from 'ember-data-factory-guy';
FactoryGuy.define("user", {
default: { // the () around the links objects is needed
company: (f) => ({links: `/users/${f.id}/company`})
},
traits: {
// luckily traits can use functions, so the settup is easy
propertiesLink: (f) => {
f.properties = {links: `/users/${f.id}/properties`}
}
}
});
- or, you can pass the links values when you make / build a model like:
let user1 = make('user', {properties: {links: '/users/1/properties'}});
let user2 = build('user', {properties: {links: '/users/2/properties'}});
- Then use mock and build / buildList to return a payload
let user = make('user', 'propertiesLink');
let propertiesLink = user.hasMany('properties').link();
let noProperties = buildList('property', 0);
mock({url: propertiesLink}).returns(noProperties);
- For future I would like to have a nicer way to mock those links
- [ Open to ideas ]
// maybe something like this ??
let user = make('user', 'propertiesLink');
let noProperties = buildList('property', 0);
mockLinks(user, 'properties').returns(noProperties);
v2.13.22
- allow traits to be functions, for example
FactoryGuy.define("project", {
default: {
title: (f) => `Project ${f.id}`
},
traits: {
// this trait is a function
// note that the fixure is passed in that will have
// default attributes like id at a minimum and in this
// case also a title ( `Project 1` ) which is default
medium: (f) => {
f.title = `Medium Project ${f.id}`
},
goofy: (f) => {
f.title = `Goofy ${f.title}`
}
}
});
So, when you make / build a project like:
let project = make('project', 'medium');
project.get('title'); //=> 'Medium Project 1'
let project2 = build('project', 'goofy');
project2.get('title'); //=> 'Goofy Project 2'
Your trait function assigns the title as you described in the function