test("The store can save an async polymorphic belongsTo association", function() { ajaxResponse({ my_post: { id: "1", name: "Awesome" } }); var post = store.push('myPost', { id: "1", name: "OMG" }); var comment = store.createRecord('myComment', { id: "2", name: "Awesome"}); comment.set('message', post); comment.save().then(async(function(comment) { ajaxParams = lastAjaxCall(); equal(ajaxParams.passedUrl, "/my_comments"); equal(ajaxParams.passedVerb, "POST"); deepEqual(ajaxParams.passedHash.data, { my_comment: { id: "2", name: "Awesome", message: {id: "1", type: "my_post"}, user_id: null } }); equal(comment.get('isDirty'), false, "the post isn't dirty anymore"); equal(comment.get('name'), "Awesome", "the post was updated"); })); }); test("The store can save an async polymorphic hasMany association", function() { ajaxResponse({ my_user: { id: "1", name: "Cedric Fluck", messages: [{ type: "my_comment", id: 2 }] } }); var comment = store.push('myComment', {id: 2, name: "OMG!!"}); var user = store.createRecord('myUser', {name: "Cyril Fluck"}); user.get('messages').pushObject( comment ); user.save().then(async(function(user) { ajaxParams = lastAjaxCall(); equal(ajaxParams.passedUrl, "/my_users"); equal(ajaxParams.passedVerb, "POST"); deepEqual(ajaxParams.passedHash.data, { my_user: { name: "Cyril Fluck" }}); equal(user.get('isDirty'), false, "the user isn't dirty anymore"); equal(user.get('id'), "1", "the user was updated"); equal(user.get('messages.length'), 1, "The user still has one message"); })); });