From 647e80a647d43ccc028c964f3f35fe203f202539 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Grosjean?= Date: Thu, 23 Oct 2014 00:31:43 +0300 Subject: [PATCH] Add failing test on PromiseArray.createRecord when called before hasMany is loaded --- .../relationships/has-many-test.js | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/integration/relationships/has-many-test.js b/tests/integration/relationships/has-many-test.js index 122873d950b..913b029ca7f 100644 --- a/tests/integration/relationships/has-many-test.js +++ b/tests/integration/relationships/has-many-test.js @@ -2475,3 +2475,40 @@ test("Updated related link should take precedence over local data", function(ass }); }); }); + +test("PromiseArray proxies createRecord to its ManyArray before the hasMany is loaded", function(assert) { + assert.expect(1); + + Post.reopen({ + comments: DS.hasMany('comment', { async: true }) + }); + + env.adapter.findHasMany = function(store, record, link, relationship) { + return Ember.RSVP.resolve([ + { id: 1, body: "First" }, + { id: 2, body: "Second" } + ]); + }; + + run(function() { + var post = env.store.push({ + data: { + type: 'post', + id: 1, + relationships: { + comments: { + links: { + related: 'someLink' + } + } + } + } + }); + + var comments = post.get('comments'); + comments.createRecord(); + comments.then(function(comments) { + assert.equal(comments.get('length'), 3, "comments have 3 length, including new record"); + }); + }); +});