Skip to content

Commit

Permalink
Merge pull request #266 from lorcan/lorcan/assert-fail-on-missing-traits
Browse files Browse the repository at this point in the history
Use assert rather than warn for missing traits
  • Loading branch information
danielspaniel committed Dec 16, 2016
2 parents 928aa95 + 3e03303 commit 20ba57c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
4 changes: 1 addition & 3 deletions addon/model-definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,7 @@ class ModelDefinition {
build(name, opts, traitArgs) {
let traitsObj = {};
traitArgs.forEach((trait)=> {
if (!this.traits[trait]) {
Ember.warn(`[ember-data-factory-guy] You're trying to use a trait [${trait}] for model ${this.modelName} but that trait can not be found.`, null, { id: 'ember-data-factory-guy-trait-does-not-exist' });
}
Ember.assert(`You're trying to use a trait [${trait}] for model ${this.modelName} but that trait can't be found.`, this.traits[trait]);
$.extend(traitsObj, this.traits[trait]);
});
let modelAttributes = this.namedModels[name] || {};
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/factory-guy-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,12 @@ test("can use non model attributes to help setup attributes", function(assert) {
assert.equal(dog2.get('sound'), `${volume} Woof`, 'uses your extra attribute');
});

test("emits warning when trait is not found", function(assert) {
sinon.spy(Ember, 'warn');
// Ember.warn = (args)=> console.log('do doo', args);
build('user', "non_existent_trait");
assert.ok(Ember.warn.getCall(0).args[0].match('non_existent_trait'));
Ember.warn.restore();
test("causes an assertion error when a trait is not found", function(assert) {
try {
build('user', 'non_existent_trait');
} catch (error) {
assert.equal(error.message, "Assertion Failed: You're trying to use a trait [non_existent_trait] for model user but that trait can't be found.");
}
});

test("handles hash attribute with hash value as default value", function(assert) {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/mock-request-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ test("with errors in response", function(assert) {
const done = assert.async();

const response = { errors: { description: ['bad'] } };
const mock = mockFindRecord('profile', 1).fails({ response });
const mock = mockFindRecord('profile').fails({ response });

FactoryGuy.store.findRecord('profile', 1)
.catch((res)=> {
Expand Down

0 comments on commit 20ba57c

Please sign in to comment.