From fcbda253b9e31c67ea3df7ca218011217a519d99 Mon Sep 17 00:00:00 2001 From: pete Date: Mon, 2 Jul 2018 11:20:05 -0700 Subject: [PATCH 1/2] [BUGFIX] Adding tests to assert exception when saving unloaded record --- tests/integration/records/save-test.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/integration/records/save-test.js b/tests/integration/records/save-test.js index 86abd1f34fa..58164fd38ac 100644 --- a/tests/integration/records/save-test.js +++ b/tests/integration/records/save-test.js @@ -182,3 +182,25 @@ test('Will reject save on invalid', function(assert) { ); }); }); + +test('Will error when saving after unloading record via the store', function(assert) { + assert.expect(1); + let post = env.store.createRecord('post', { title: 'toto' }); + run(function() { + env.store.unloadAll('post'); + assert.throws(function() { + post.save(); + }, 'Attempting to save the unloaded record threw an error'); + }); +}); + +test('Will error when saving after unloading record', function(assert) { + assert.expect(1); + let post = env.store.createRecord('post', { title: 'toto' }); + run(function() { + post.unloadRecord(); + assert.throws(function() { + post.save(); + }, 'Attempting to save the unloaded record threw an error'); + }); +}); From 098cd62d37dd350e2f165e787e3187b7749351ff Mon Sep 17 00:00:00 2001 From: pete Date: Thu, 5 Jul 2018 11:13:30 -0700 Subject: [PATCH 2/2] Clarifying error message for polymorphic types --- addon/-debug/index.js | 3 ++- tests/integration/references/belongs-to-test.js | 2 +- tests/integration/references/has-many-test.js | 2 +- tests/integration/relationships/belongs-to-test.js | 4 ++-- tests/integration/relationships/has-many-test.js | 4 ++-- .../relationships/polymorphic-mixins-belongs-to-test.js | 4 ++-- .../relationships/polymorphic-mixins-has-many-test.js | 4 ++-- tests/unit/utils-test.js | 4 ++-- 8 files changed, 14 insertions(+), 13 deletions(-) diff --git a/addon/-debug/index.js b/addon/-debug/index.js index 240e5031959..900c34edf6b 100644 --- a/addon/-debug/index.js +++ b/addon/-debug/index.js @@ -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)); }; diff --git a/tests/integration/references/belongs-to-test.js b/tests/integration/references/belongs-to-test.js index cda9590dff6..c8ce17a0ddb 100644 --- a/tests/integration/references/belongs-to-test.js +++ b/tests/integration/references/belongs-to-test.js @@ -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) { diff --git a/tests/integration/references/has-many-test.js b/tests/integration/references/has-many-test.js index 9682b97754c..3491a24fbb8 100755 --- a/tests/integration/references/has-many-test.js +++ b/tests/integration/references/has-many-test.js @@ -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) { diff --git a/tests/integration/relationships/belongs-to-test.js b/tests/integration/relationships/belongs-to-test.js index 6049031bd9f..3616e0efe2b 100644 --- a/tests/integration/relationships/belongs-to-test.js +++ b/tests/integration/relationships/belongs-to-test.js @@ -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'/); }); }); } @@ -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'/); }); }); } diff --git a/tests/integration/relationships/has-many-test.js b/tests/integration/relationships/has-many-test.js index 2a44b221369..86f00bffc7f 100644 --- a/tests/integration/relationships/has-many-test.js +++ b/tests/integration/relationships/has-many-test.js @@ -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'/); }); }); } @@ -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'/); }); }); } diff --git a/tests/integration/relationships/polymorphic-mixins-belongs-to-test.js b/tests/integration/relationships/polymorphic-mixins-belongs-to-test.js index 3259d0b8a48..1f1167783f3 100644 --- a/tests/integration/relationships/polymorphic-mixins-belongs-to-test.js +++ b/tests/integration/relationships/polymorphic-mixins-belongs-to-test.js @@ -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'/); }); } ); @@ -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(); diff --git a/tests/integration/relationships/polymorphic-mixins-has-many-test.js b/tests/integration/relationships/polymorphic-mixins-has-many-test.js index 4d3ecd0ff7d..39a343b0803 100644 --- a/tests/integration/relationships/polymorphic-mixins-has-many-test.js +++ b/tests/integration/relationships/polymorphic-mixins-has-many-test.js @@ -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/); }); }); } @@ -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 { diff --git a/tests/unit/utils-test.js b/tests/unit/utils-test.js index b1019afdd80..3bddc49fb10 100644 --- a/tests/unit/utils-test.js +++ b/tests/unit/utils-test.js @@ -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) { @@ -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."); });