From f59b63d9859b749303427d5afe56386913458aaf Mon Sep 17 00:00:00 2001 From: nick dreckshage Date: Tue, 6 May 2014 22:56:10 -0400 Subject: [PATCH] Failing test for https://github.com/ebryn/ember-model/issues/245 --- .../has_many/nonembedded_objects_save_test.js | 51 ++++++++++++++++++- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/packages/ember-model/tests/has_many/nonembedded_objects_save_test.js b/packages/ember-model/tests/has_many/nonembedded_objects_save_test.js index f5885f6..8d1bf6a 100644 --- a/packages/ember-model/tests/has_many/nonembedded_objects_save_test.js +++ b/packages/ember-model/tests/has_many/nonembedded_objects_save_test.js @@ -29,7 +29,7 @@ test("new records should remain after parent is saved", function() { resolve(json); }); }; - + var article = Article.create({ title: 'bar' }); @@ -77,7 +77,7 @@ test("saving child objects", function() { }); Article.adapter = Ember.RESTAdapter.create(); Article.url = '/articles'; - + var article = Article.create(); var comment = Comment.create(); @@ -92,3 +92,50 @@ test("saving child objects", function() { }); stop(); }); + +test("parent should not be dirty after new child created", function() { + expect(3); + + var articleJSON = { + id: 76, + title: '?', + comment_ids: [] + }; + + var commentJSON = { + id:111, + title:':}}' + }; + + var Comment = Ember.Model.extend({ + id: attr(), + text: attr() + }); + Comment.adapter = Ember.RESTAdapter.create(); + Comment.url = '/comments'; + Comment.adapter._ajax = function() { + return new Ember.RSVP.Promise(function(resolve) { + resolve(commentJSON); + }); + }; + + var Article = Ember.Model.extend({ + id: attr(), + title: attr(), + comments: Ember.hasMany(Comment, { key: 'comment_ids' }) + }); + Article.adapter = Ember.RESTAdapter.create(); + Article.url = '/articles'; + + var article = Article.create(); + Ember.run(article, article.load, articleJSON.id, articleJSON); + + Comment.create().save().then(function(record){ + start(); + equal(article.get('isDirty'), false); + equal(record.get('isDirty'), false); + article.get('comments').addObject(record); + equal(article.get('isDirty'), false); + }); + stop(); +});