Skip to content

Commit 137b2c0

Browse files
committed
Closes #187.
1 parent 036e946 commit 137b2c0

20 files changed

+294
-201
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
- #171 - "not in" query
1313
- #177 - Allow promises to be returned in lifecycle hooks
1414
- #182 - option to force trailing slash (DSHttpAdapterProvider.defaults.forceTrailingSlash)
15+
- #185 - eagerInject/eagerEject should default to definition's options
16+
- #186 - eagerInject doesn't add the model to the list after HTTP success
17+
- #187 - Proxy some static methods to instance methods
1518

1619
###### Backwards compatible bug fixes
1720
- #156 - cached findAll pending query doesn't get removed sometimes

dist/angular-data.js

+14
Original file line numberDiff line numberDiff line change
@@ -5440,6 +5440,20 @@ function defineResource(definition) {
54405440
};
54415441
}
54425442

5443+
def[def.class].prototype.DSUpdate = function () {
5444+
var args = Array.prototype.slice.call(arguments);
5445+
args.unshift(this[def.idAttribute]);
5446+
args.unshift(def.name);
5447+
return DS.update.apply(DS, args);
5448+
};
5449+
5450+
def[def.class].prototype.DSSave = function () {
5451+
var args = Array.prototype.slice.call(arguments);
5452+
args.unshift(this[def.idAttribute]);
5453+
args.unshift(def.name);
5454+
return DS.save.apply(DS, args);
5455+
};
5456+
54435457
// Initialize store data for the new resource
54445458
DS.store[def.name] = {
54455459
collection: [],

dist/angular-data.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/datastore/sync_methods/defineResource.js

+14
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,20 @@ function defineResource(definition) {
268268
};
269269
}
270270

271+
def[def.class].prototype.DSUpdate = function () {
272+
var args = Array.prototype.slice.call(arguments);
273+
args.unshift(this[def.idAttribute]);
274+
args.unshift(def.name);
275+
return DS.update.apply(DS, args);
276+
};
277+
278+
def[def.class].prototype.DSSave = function () {
279+
var args = Array.prototype.slice.call(arguments);
280+
args.unshift(this[def.idAttribute]);
281+
args.unshift(def.name);
282+
return DS.save.apply(DS, args);
283+
};
284+
271285
// Initialize store data for the new resource
272286
DS.store[def.name] = {
273287
collection: [],

test/integration/datastore/DSCacheFactory.test.js

+12-14
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,21 @@ describe('DSCacheFactory integration', function () {
2020
});
2121

2222
DS.find('Comment', 5).then(function (comment) {
23-
assert.deepEqual(comment, {
23+
assert.deepEqual(angular.toJson(comment), angular.toJson({
2424
id: 5,
2525
text: 'test'
26-
});
26+
}));
2727
}, function (err) {
2828
console.error(err.stack);
2929
fail('Should not have rejected!');
3030
});
3131

3232
$httpBackend.flush();
3333

34-
assert.deepEqual(DS.get('Comment', 5), {
34+
assert.deepEqual(angular.toJson(DS.get('Comment', 5)), angular.toJson({
3535
id: 5,
3636
text: 'test'
37-
}, 'The comment is now in the store');
37+
}), 'The comment is now in the store');
3838
assert.isNumber(DS.lastModified('Comment', 5));
3939
assert.isNumber(DS.lastSaved('Comment', 5));
4040

@@ -65,32 +65,30 @@ describe('DSCacheFactory integration', function () {
6565
});
6666

6767
DS.find('Comment', 5).then(function (comment) {
68-
assert.deepEqual(comment, {
68+
assert.deepEqual(angular.toJson(comment), angular.toJson({
6969
id: 5,
7070
text: 'test'
71-
});
71+
}));
7272
}, function (err) {
7373
console.error(err.stack);
7474
fail('Should not have rejected!');
7575
});
7676

7777
$httpBackend.flush();
7878

79-
assert.deepEqual(DS.get('Comment', 5), {
79+
assert.deepEqual(angular.toJson(DS.get('Comment', 5)), angular.toJson({
8080
id: 5,
8181
text: 'test'
82-
}, 'The comment is now in the store');
82+
}), 'The comment is now in the store');
8383
assert.isNumber(DS.lastModified('Comment', 5));
8484
assert.isNumber(DS.lastSaved('Comment', 5));
8585

86+
var c = DS.get('Comment', 5);
8687
setTimeout(function () {
8788
assert.isUndefined(DS.get('Comment', 5));
8889

8990
assert.equal(DS.definitions.Comment.onExpire.callCount, 1, 'onExpire should have been called once');
90-
assert.isTrue(DS.definitions.Comment.onExpire.calledWithExactly('5', {
91-
id: 5,
92-
text: 'test'
93-
}), 'onExpire should have been called with the right arguments');
91+
assert.isTrue(DS.definitions.Comment.onExpire.calledWithExactly('5', c), 'onExpire should have been called with the right arguments');
9492
assert.equal(lifecycle.beforeInject.callCount, 1, 'beforeInject should have been called');
9593
assert.equal(lifecycle.afterInject.callCount, 1, 'afterInject should have been called');
9694
assert.equal(lifecycle.serialize.callCount, 0, 'serialize should have been called');
@@ -102,10 +100,10 @@ describe('DSCacheFactory integration', function () {
102100
});
103101

104102
DS.find('Comment', 5).then(function (comment) {
105-
assert.deepEqual(comment, {
103+
assert.deepEqual(angular.toJson(comment), angular.toJson({
106104
id: 5,
107105
text: 'test'
108-
});
106+
}));
109107
}, function (err) {
110108
console.error(err.stack);
111109
fail('Should not have rejected!');

test/integration/datastore/async_methods/create.test.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe('DS.create(resourceName, attrs[, options])', function () {
2626
$httpBackend.expectPOST('http://test.angular-cache.com/posts').respond(200, p1);
2727

2828
DS.create('post', { author: 'John', age: 30 }).then(function (post) {
29-
assert.deepEqual(post, p1, 'post 5 should have been created');
29+
assert.deepEqual(angular.toJson(post), angular.toJson(p1), 'post 5 should have been created');
3030
}, function (err) {
3131
console.error(err.stack);
3232
fail('should not have rejected');
@@ -40,14 +40,14 @@ describe('DS.create(resourceName, attrs[, options])', function () {
4040
assert.equal(lifecycle.afterInject.callCount, 1, 'afterInject should have been called');
4141
assert.equal(lifecycle.serialize.callCount, 1, 'serialize should have been called');
4242
assert.equal(lifecycle.deserialize.callCount, 1, 'deserialize should have been called');
43-
assert.deepEqual(DS.get('post', 5), p1);
43+
assert.deepEqual(angular.toJson(DS.get('post', 5)), angular.toJson(p1));
4444
});
4545
it('should create an item and save it to the server but not inject the result', function () {
4646
DSHttpAdapter.defaults.forceTrailingSlash = true;
4747
$httpBackend.expectPOST('http://test.angular-cache.com/posts/').respond(200, p1);
4848

4949
DS.create('post', { author: 'John', age: 30 }, { cacheResponse: false }).then(function (post) {
50-
assert.deepEqual(post, p1, 'post 5 should have been created');
50+
assert.deepEqual(angular.toJson(post), angular.toJson(p1), 'post 5 should have been created');
5151
}, function (err) {
5252
console.error(err.stack);
5353
fail('should not have rejected');
@@ -68,7 +68,7 @@ describe('DS.create(resourceName, attrs[, options])', function () {
6868
$httpBackend.expectPUT('http://test.angular-cache.com/posts/5').respond(200, p1);
6969

7070
DS.create('post', { author: 'John', age: 30, id: 5 }).then(function (post) {
71-
assert.deepEqual(post, p1, 'post 5 should have been created');
71+
assert.deepEqual(angular.toJson(post), angular.toJson(p1), 'post 5 should have been created');
7272
}, function (err) {
7373
console.error(err.stack);
7474
fail('should not have rejected');
@@ -79,7 +79,7 @@ describe('DS.create(resourceName, attrs[, options])', function () {
7979
$httpBackend.expectPOST('http://test.angular-cache.com/posts').respond(200, p2);
8080

8181
DS.create('post', { author: 'Sue', age: 70, id: 6 }, { upsert: false }).then(function (post) {
82-
assert.deepEqual(post, p2, 'post 6 should have been created');
82+
assert.deepEqual(angular.toJson(post), angular.toJson(p2), 'post 6 should have been created');
8383
}, function (err) {
8484
console.error(err.stack);
8585
fail('should not have rejected');
@@ -157,8 +157,8 @@ describe('DS.create(resourceName, attrs[, options])', function () {
157157
content: 'test',
158158
approvedBy: 4
159159
}).then(function (comment) {
160-
assert.deepEqual(comment, testComment);
161-
assert.deepEqual(comment, DS.get('comment', 5));
160+
assert.deepEqual(angular.toJson(comment), angular.toJson(testComment));
161+
assert.deepEqual(angular.toJson(comment), angular.toJson(DS.get('comment', 5)));
162162
}, function () {
163163
fail('Should not have failed!');
164164
});
@@ -174,8 +174,8 @@ describe('DS.create(resourceName, attrs[, options])', function () {
174174
approvedBy: 4
175175
}
176176
}).then(function (comment) {
177-
assert.deepEqual(comment, testComment2);
178-
assert.deepEqual(comment, DS.get('comment', 6));
177+
assert.deepEqual(angular.toJson(comment), angular.toJson(testComment2));
178+
assert.deepEqual(angular.toJson(comment), angular.toJson(DS.get('comment', 6)));
179179
}, function () {
180180
fail('Should not have failed!');
181181
});
@@ -192,7 +192,7 @@ describe('DS.create(resourceName, attrs[, options])', function () {
192192
approvedBy: false
193193
}
194194
}).then(function (comment) {
195-
assert.deepEqual(comment, testComment2);
195+
assert.deepEqual(angular.toJson(comment), angular.toJson(testComment2));
196196
assert.deepEqual(comment, DS.get('comment', 6));
197197
}, function () {
198198
fail('Should not have failed!');

test/integration/datastore/async_methods/find.test.js

+14-14
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ describe('DS.find(resourceName, id[, options]): ', function () {
3737
$httpBackend.expectGET('http://test.angular-cache.com/posts/5').respond(200, p1);
3838

3939
DS.find('post', 5).then(function (post) {
40-
assert.deepEqual(post, p1);
40+
assert.deepEqual(angular.toJson(post), angular.toJson(p1));
4141
}, function (err) {
4242
console.error(err.stack);
4343
fail('Should not have rejected!');
@@ -47,21 +47,21 @@ describe('DS.find(resourceName, id[, options]): ', function () {
4747

4848
// Should have no effect because there is already a pending query
4949
DS.find('post', 5).then(function (post) {
50-
assert.deepEqual(post, p1);
50+
assert.deepEqual(angular.toJson(post), angular.toJson(p1));
5151
}, function (err) {
5252
console.error(err.stack);
5353
fail('Should not have rejected!');
5454
});
5555

5656
$httpBackend.flush();
5757

58-
assert.deepEqual(DS.get('post', 5), p1, 'The post is now in the store');
58+
assert.deepEqual(angular.toJson(DS.get('post', 5)), angular.toJson(p1), 'The post is now in the store');
5959
assert.isNumber(DS.lastModified('post', 5));
6060
assert.isNumber(DS.lastSaved('post', 5));
6161

6262
// Should not make a request because the request was already completed
6363
DS.find('post', 5).then(function (post) {
64-
assert.deepEqual(post, p1);
64+
assert.deepEqual(angular.toJson(post), angular.toJson(p1));
6565
}, function (err) {
6666
console.error(err.stack);
6767
fail('Should not have rejected!');
@@ -71,7 +71,7 @@ describe('DS.find(resourceName, id[, options]): ', function () {
7171

7272
// Should make a request because bypassCache is set to true
7373
DS.find('post', 5, { bypassCache: true }).then(function (post) {
74-
assert.deepEqual(post, p1);
74+
assert.deepEqual(angular.toJson(post), angular.toJson(p1));
7575
}, function (err) {
7676
console.error(err.stack);
7777
fail('Should not have rejected!');
@@ -88,7 +88,7 @@ describe('DS.find(resourceName, id[, options]): ', function () {
8888
$httpBackend.expectGET('http://test.angular-cache.com/posts/5').respond(200, p1);
8989

9090
DS.find('post', 5, { cacheResponse: false }).then(function (post) {
91-
assert.deepEqual(post, p1);
91+
assert.deepEqual(angular.toJson(post), angular.toJson(p1));
9292
}, function (err) {
9393
console.error(err.stack);
9494
fail('Should not have rejected!');
@@ -126,8 +126,8 @@ describe('DS.find(resourceName, id[, options]): ', function () {
126126
approvedBy: 4
127127
}
128128
}).then(function (comment) {
129-
assert.deepEqual(comment, testComment);
130-
assert.deepEqual(comment, DS.get('comment', 5));
129+
assert.deepEqual(angular.toJson(comment), angular.toJson(testComment));
130+
assert.deepEqual(angular.toJson(comment), angular.toJson(DS.get('comment', 5)));
131131
}, function () {
132132
fail('Should not have failed!');
133133
});
@@ -139,8 +139,8 @@ describe('DS.find(resourceName, id[, options]): ', function () {
139139
DS.find('comment', 5, {
140140
bypassCache: true
141141
}).then(function (comment) {
142-
assert.deepEqual(comment, testComment);
143-
assert.deepEqual(comment, DS.get('comment', 5));
142+
assert.deepEqual(angular.toJson(comment), angular.toJson(testComment));
143+
assert.deepEqual(angular.toJson(comment), angular.toJson(DS.get('comment', 5)));
144144
}, function () {
145145
fail('Should not have failed!');
146146
});
@@ -155,8 +155,8 @@ describe('DS.find(resourceName, id[, options]): ', function () {
155155
approvedBy: false
156156
}
157157
}).then(function (comment) {
158-
assert.deepEqual(comment, testComment);
159-
assert.deepEqual(comment, DS.get('comment', 5));
158+
assert.deepEqual(angular.toJson(comment), angular.toJson(testComment));
159+
assert.deepEqual(angular.toJson(comment), angular.toJson(DS.get('comment', 5)));
160160
}, function () {
161161
fail('Should not have failed!');
162162
});
@@ -172,8 +172,8 @@ describe('DS.find(resourceName, id[, options]): ', function () {
172172
organizationId: 14
173173
}
174174
}).then(function (comment) {
175-
assert.deepEqual(comment, comment19);
176-
assert.deepEqual(comment, DS.get('comment', 19));
175+
assert.deepEqual(angular.toJson(comment), angular.toJson(comment19));
176+
assert.deepEqual(angular.toJson(comment), angular.toJson(DS.get('comment', 19)));
177177
}, function () {
178178
fail('Should not have failed!');
179179
});

0 commit comments

Comments
 (0)