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

[BUGFIX] Clarifying error message for polymorphic types #5518

Merged
merged 3 commits into from
Jul 10, 2018
Merged
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
3 changes: 2 additions & 1 deletion addon/-debug/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ if (DEBUG) {
let relationshipModelName = relationshipMeta.type;
let relationshipClass = store.modelFor(relationshipModelName);
let addedClass = store.modelFor(addedInternalModel.modelName);
let assertionMessage = `You cannot add a record of modelClass '${addedModelName}' to the '${parentModelName}.${key}' relationship (only '${relationshipModelName}' allowed)`;

let assertionMessage = `The '${addedModelName}' type does not implement '${relationshipModelName}' and thus cannot be assigned to the '${key}' relationship in '${parentModelName}'. Make it a descendant of '${relationshipModelName}' or use a mixin of the same name.`;

assert(assertionMessage, checkPolymorphic(relationshipClass, addedClass));
};
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/references/belongs-to-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ testInDebug('push(record) asserts for invalid modelClass', function(assert) {
run(function() {
familyReference.push(anotherPerson);
});
}, "You cannot add a record of modelClass 'person' to the 'person.family' relationship (only 'family' allowed)");
}, "The 'person' type does not implement 'family' and thus cannot be assigned to the 'family' relationship in 'person'. Make it a descendant of 'family' or use a mixin of the same name.");
});

testInDebug('push(record) works with polymorphic modelClass', function(assert) {
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/references/has-many-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ testInDebug('push(array) asserts polymorphic type', function(assert) {

personsReference.push(data);
});
}, "You cannot add a record of modelClass 'family' to the 'family.persons' relationship (only 'person' allowed)");
}, "The 'family' type does not implement 'person' and thus cannot be assigned to the 'persons' relationship in 'family'. Make it a descendant of 'person' or use a mixin of the same name.");
});

testInDebug('push(object) supports legacy, non-JSON-API-conform payload', function(assert) {
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/relationships/belongs-to-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ testInDebug(
}).then(records => {
assert.expectAssertion(() => {
records.post.set('user', records.comment);
}, /You cannot add a record of modelClass 'comment' to the 'post.user' relationship/);
}, /The 'comment' type does not implement 'user' and thus cannot be assigned to the 'user' relationship in 'post'/);
});
});
}
Expand Down Expand Up @@ -372,7 +372,7 @@ testInDebug(

assert.expectAssertion(() => {
comment.set('message', records.user);
}, /You cannot add a record of modelClass 'user' to the 'comment.message' relationship \(only 'message' allowed\)/);
}, /The 'user' type does not implement 'message' and thus cannot be assigned to the 'message' relationship in 'comment'. Make it a descendant of 'message'/);
});
});
}
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/relationships/has-many-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1751,7 +1751,7 @@ testInDebug(
) {
assert.expectAssertion(function() {
records[0].get('comments').pushObject(records[1]);
}, /You cannot add a record of modelClass 'post' to the 'post.comments' relationship \(only 'comment' allowed\)/);
}, /The 'post' type does not implement 'comment' and thus cannot be assigned to the 'comments' relationship in 'post'/);
});
});
}
Expand Down Expand Up @@ -1823,7 +1823,7 @@ testInDebug(

assert.expectAssertion(function() {
records.messages.pushObject(records.anotherUser);
}, /You cannot add a record of modelClass 'user' to the 'user.messages' relationship \(only 'message' allowed\)/);
}, /The 'user' type does not implement 'message' and thus cannot be assigned to the 'messages' relationship in 'user'. Make it a descendant of 'message'/);
});
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ testInDebug(
run(function() {
assert.expectAssertion(function() {
user.set('bestMessage', video);
}, /You cannot add a record of modelClass 'not-message' to the 'user.bestMessage' relationship \(only 'message' allowed\)/);
}, /The 'not-message' type does not implement 'message' and thus cannot be assigned to the 'bestMessage' relationship in 'user'. Make it a descendant of 'message'/);
});
}
);
Expand Down Expand Up @@ -248,7 +248,7 @@ testInDebug(
run(function() {
assert.expectAssertion(function() {
user.set('bestMessage', video);
}, /You cannot add a record of modelClass 'not-message' to the 'user.bestMessage' relationship \(only 'message' allowed\)/);
}, /The 'not-message' type does not implement 'message' and thus cannot be assigned to the 'bestMessage' relationship in 'user'. Make it a descendant of 'message'/);
});
} finally {
resetModelFactoryInjections();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ testInDebug(
user.get('messages').then(function(fetchedMessages) {
assert.expectAssertion(function() {
fetchedMessages.pushObject(notMessage);
}, /You cannot add a record of modelClass 'not-message' to the 'user.messages' relationship \(only 'message' allowed\)/);
}, /The 'not-message' type does not implement 'message' and thus cannot be assigned to the 'messages' relationship in 'user'. Make it a descendant of 'message/);
});
});
}
Expand Down Expand Up @@ -278,7 +278,7 @@ testInDebug(
user.get('messages').then(function(fetchedMessages) {
assert.expectAssertion(function() {
fetchedMessages.pushObject(notMessage);
}, /You cannot add a record of modelClass 'not-message' to the 'user.messages' relationship \(only 'message' allowed\)/);
}, /The 'not-message' type does not implement 'message' and thus cannot be assigned to the 'messages' relationship in 'user'. Make it a descendant of 'message'/);
});
});
} finally {
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/utils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ testInDebug('assertPolymorphicType works for subclasses', function(assert) {

assert.expectAssertion(() => {
assertPolymorphicType(user, relationship, person, env.store);
}, "You cannot add a record of modelClass 'person' to the 'user.messages' relationship (only 'message' allowed)");
}, "The 'person' type does not implement 'message' and thus cannot be assigned to the 'messages' relationship in 'user'. Make it a descendant of 'message' or use a mixin of the same name.");
});

test('modelHasAttributeOrRelationshipNamedType', function(assert) {
Expand Down Expand Up @@ -147,5 +147,5 @@ testInDebug('assertPolymorphicType works for mixins', function(assert) {

assert.expectAssertion(() => {
assertPolymorphicType(post, relationship, person, env.store);
}, "You cannot add a record of modelClass 'person' to the 'post.medias' relationship (only 'medium' allowed)");
}, "The 'person' type does not implement 'medium' and thus cannot be assigned to the 'medias' relationship in 'post'. Make it a descendant of 'medium' or use a mixin of the same name.");
});