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

Failing test to show that afterMake is run before the model's onLoad hook #259

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions tests/dummy/app/models/model-with-onload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Model from 'ember-data/model';
import attr from 'ember-data/attr';

export default Model.extend({
name: attr('string'),
derivedName: undefined,
didLoad() {
this._super();
this.set('derivedName', `${this.get('name')} -set in model#didLoad-`);
}
});
10 changes: 10 additions & 0 deletions tests/dummy/app/tests/factories/model-with-onload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import FactoryGuy from 'ember-data-factory-guy';

FactoryGuy.define('model-with-onload', {
default: {
name: 'Some name'
},
afterMake: function(model) {
model.set('name', `${model.get('name')} -set in afterMake-`);
}
});
9 changes: 9 additions & 0 deletions tests/unit/shared-factory-guy-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,15 @@ SharedBehavior.makeTests = function () {
});
});

test("afterMake is called before the model's onLoad hook", function(assert) {
assert.expect(2);
Ember.run(function() {
let property = FactoryGuy.make('model-with-onload', {name: 'name'});
equal(property.get('name'), 'name -set in afterMake-', `afterMake is called and sets name`);
equal(property.get('derivedName'), 'name -set in afterMake- -set in model#didLoad-', `afterMake should be called before the model's didLoad hook`);
});
});

test("hasMany associations assigned with ids", function () {
let project1 = make('project', {id: 1, title: 'Project One'});
let project2 = make('project', {id: 2, title: 'Project Two'});
Expand Down