From 9b2b261ef5cbb8ebdcf7f7248e03cbbb736843d9 Mon Sep 17 00:00:00 2001 From: Timothy Krell Date: Fri, 12 Sep 2014 14:03:01 -0400 Subject: [PATCH] Add failing test for hasChanges after loading relations --- .../datastore/sync_methods/hasChanges.test.js | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/test/integration/datastore/sync_methods/hasChanges.test.js b/test/integration/datastore/sync_methods/hasChanges.test.js index 55c1257..9ac1d26 100644 --- a/test/integration/datastore/sync_methods/hasChanges.test.js +++ b/test/integration/datastore/sync_methods/hasChanges.test.js @@ -32,4 +32,48 @@ describe('DS.hasChanges(resourceName, id)', function () { assert.isTrue(DS.hasChanges('post', 5)); }); + it('should return false for resources with defined methods', function () { + var Person = DS.defineResource({ + name: 'person', + methods: { + fullName: function () { + return this.first + ' ' + this.last; + } + } + }); + + DS.inject('person', { + first: 'John', + last: 'Anderson', + id: 1 + }); + + assert.isFalse(DS.hasChanges('person', 1)); + }); + it('should return false after loading relations', function() { + DS.inject('user', user10); + + $httpBackend.expectGET('http://test.angular-cache.com/organization/14?userId=10').respond(200, organization14); + $httpBackend.expectGET('http://test.angular-cache.com/user/10/comment?userId=10').respond(200, [ + comment11, + comment12, + comment13 + ]); + $httpBackend.expectGET('http://test.angular-cache.com/profile?userId=10').respond(200, profile15); + + DS.loadRelations('user', 10, ['comment', 'profile', 'organization'], { params: { approvedBy: 10 } }).then(function (user) { + assert.isFalse(DS.hasChanges('user', 10)); + }, fail); + + $httpBackend.flush(); + + // try a comment that has a belongsTo relationship to multiple users: + DS.inject('comment', comment19); + $httpBackend.expectGET('http://test.angular-cache.com/user/20').respond(200, user20); + $httpBackend.expectGET('http://test.angular-cache.com/user/19').respond(200, user19); + DS.loadRelations('comment', 19, ['user']).then(function (comment) { + assert.isFalse(DS.hasChanges('comment', 19)); + }, fail); + $httpBackend.flush(); + }); });