Skip to content

Commit 94c57b0

Browse files
committed
Fixes #66.
1 parent e83f887 commit 94c57b0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+309
-212
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
- #59, #62 - Make queryTransform() consistent with the rest of the API
66

77
###### Backwards compatible API changes
8-
- #30, #48 - DSCacheFactory integration
8+
- #30, #48, #66 - DSCacheFactory integration
99
- #49 - DS.bindOne($scope, prop, resourceName, id)
1010
- #50 - DS.bindAll($scope, prop, resourceName, query)
1111
- #51 - Allow baseUrl to be overridable at the method level

Gruntfile.js

+28-8
Original file line numberDiff line numberDiff line change
@@ -97,24 +97,44 @@ module.exports = function (grunt) {
9797
dev: {
9898
browsers: ['Chrome'],
9999
autoWatch: true,
100-
singleRun: false
100+
singleRun: false,
101+
exclude: [
102+
'test/integration/datastore/cacheFactory.test.js'
103+
]
101104
},
102105
min: {
103-
browsers: ['Chrome'],
104-
autoWatch: false,
105-
singleRun: true,
106+
browsers: ['Firefox', 'PhantomJS'],
106107
options: {
107108
files: [
108109
'bower_components/angular/angular.js',
109110
'bower_components/angular-mocks/angular-mocks.js',
111+
'bower_components/angular-cache/dist/angular-cache.js',
110112
'dist/angular-data.min.js',
111-
'test/integration/**/*.js',
112-
'karma.start.js'
113+
'karma.start.js',
114+
'test/integration/**/*.js'
115+
]
116+
},
117+
exclude: [
118+
'test/integration/datastore/cacheFactory.test.js'
119+
]
120+
},
121+
cacheFactory: {
122+
browsers: ['Firefox', 'PhantomJS'],
123+
options: {
124+
files: [
125+
'bower_components/angular/angular.js',
126+
'bower_components/angular-mocks/angular-mocks.js',
127+
'dist/angular-data.js',
128+
'karma.start.js',
129+
'test/integration/datastore/cacheFactory.test.js'
113130
]
114131
}
115132
},
116133
ci: {
117-
browsers: ['Firefox', 'PhantomJS']
134+
browsers: ['Firefox', 'PhantomJS'],
135+
exclude: [
136+
'test/integration/datastore/cacheFactory.test.js'
137+
]
118138
}
119139
},
120140
coveralls: {
@@ -375,5 +395,5 @@ module.exports = function (grunt) {
375395
grunt.registerTask('default', ['build']);
376396

377397
// Used by TravisCI
378-
grunt.registerTask('ci', ['build', 'karma:ci', 'coveralls', 'doc']);
398+
grunt.registerTask('ci', ['build', 'karma:ci', 'karma:cacheFactory', 'karma:min', 'coveralls', 'doc']);
379399
};

README.md

+4-6
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,18 @@
22

33
__Data store for Angular.js.__
44

5-
__Current version:__ 0.9.0
5+
__Latest Release:__ [0.8.1](http://angular-data.codetrain.io/)
6+
__master:__ [0.9.0](http://angular-data-next.codetrain.io/)
67

78
Angular-data is in a pre-1.0.0 development stage; the API is fluctuating, not a lot of tests yet, etc.
89

9-
Not for production use (yet). If you still want to develop with Angular-data, be prepared to keep a close eye on the changelog, as the API is very liable to change (a lot).
10+
Not for production use (yet). If you still want to develop with Angular-data, be prepared to keep a close eye on the changelog, as the API is still liable to change before 1.0.0.
1011

11-
Pending:
12-
- A Solid Roadmap
12+
Roadmap:
1313
- Relations/Associations
1414
- Various Adapters
1515
- Schema Definition/Validation
1616
- Nested Resources
17-
- Website / documentation
18-
- 100% tested (whatever _that_ means)
1917
- See [issues](https://github.com/jmdobry/angular-data/issues?milestone=7&page=1&state=open) for what's in development
2018
- See [Design Doc](https://docs.google.com/document/d/1o069KLuBH4jpwm1FCLZFwKMgM73Xi8_1JyjhSxVpidM/edit?usp=sharing) for other juicy reading material
2119

dist/angular-data.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3346,8 +3346,8 @@ function DSProvider() {
33463346
var defaults = this.defaults = new BaseConfig();
33473347

33483348
this.$get = [
3349-
'$rootScope', '$log', '$q', 'DSHttpAdapter', 'DSLocalStorageAdapter', 'DSUtils', 'DSErrors', 'DSCacheFactory',
3350-
function ($rootScope, $log, $q, DSHttpAdapter, DSLocalStorageAdapter, DSUtils, DSErrors, DSCacheFactory) {
3349+
'$rootScope', '$log', '$q', 'DSHttpAdapter', 'DSLocalStorageAdapter', 'DSUtils', 'DSErrors',
3350+
function ($rootScope, $log, $q, DSHttpAdapter, DSLocalStorageAdapter, DSUtils, DSErrors) {
33513351

33523352
var syncMethods = require('./sync_methods'),
33533353
asyncMethods = require('./async_methods'),

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.

karma.conf.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ module.exports = function (config) {
1212
'karma-chrome-launcher',
1313
'karma-phantomjs-launcher',
1414
'karma-firefox-launcher',
15-
'karma-coverage'
15+
'karma-coverage',
16+
'karma-spec-reporter'
1617
],
1718
autoWatch: false,
1819
browsers: ['Chrome'],
@@ -23,11 +24,11 @@ module.exports = function (config) {
2324
'bower_components/angular-mocks/angular-mocks.js',
2425
'bower_components/angular-cache/dist/angular-cache.js',
2526
'dist/angular-data.js',
26-
'test/integration/**/*.js',
27-
'karma.start.js'
27+
'karma.start.js',
28+
'test/integration/**/*.js'
2829
],
2930

30-
reporters: ['progress', 'coverage'],
31+
reporters: ['spec', 'coverage'],
3132

3233
preprocessors: {
3334
'dist/angular-data.js': ['coverage']

karma.start.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ var fail = function (msg) {
2727
}],
2828
TYPES_EXCEPT_FUNCTION = ['string', 123, 123.123, null, undefined, {}, [], true, false];
2929

30-
angular.module('app', ['ng', 'angular-data.DS', 'angular-data.DSCacheFactory']);
30+
angular.module('app', ['ng', 'angular-data.DS']);
3131

3232
// Setup before each test
33-
beforeEach(function (done) {
33+
beforeEach(function () {
3434
lifecycle.beforeValidate = function (resourceName, attrs, cb) {
3535
lifecycle.beforeValidate.callCount += 1;
3636
cb(null, attrs);
@@ -103,10 +103,13 @@ beforeEach(function (done) {
103103
DSProvider.defaults.deserialize = lifecycle.deserialize;
104104
DSHttpAdapterProvider = _DSHttpAdapterProvider_;
105105
DSHttpAdapterProvider.defaults.queryTransform = lifecycle.queryTransform;
106-
107106
});
107+
});
108+
109+
function startInjector() {
108110
inject(function (_$rootScope_, _$q_, _$httpBackend_, _DS_, _$log_, _DSUtils_, _DSHttpAdapter_, _DSLocalStorageAdapter_) {
109111
// Setup global mocks
112+
110113
localStorage.clear();
111114
$q = _$q_;
112115
$rootScope = _$rootScope_;
@@ -141,10 +144,8 @@ beforeEach(function (done) {
141144
p3 = { author: 'Mike', age: 32, id: 7 };
142145
p4 = { author: 'Adam', age: 33, id: 8 };
143146
p5 = { author: 'Adam', age: 33, id: 9 };
144-
145-
done();
146147
});
147-
});
148+
}
148149

149150
// Clean up after each test
150151
afterEach(function () {

package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
}
2020
],
2121
"devDependencies": {
22-
"grunt": "0.4.4",
22+
"grunt": "0.4.5",
2323
"grunt-cli": "0.1.13",
2424
"grunt-contrib-clean": "0.5.0",
2525
"load-grunt-tasks": "0.4.0",
@@ -35,15 +35,16 @@
3535
"karma": "~0.12.16",
3636
"grunt-karma": "~0.8.3",
3737
"karma-chai": "0.1.0",
38-
"mocha": "~1.18.2",
38+
"mocha": "~1.19.0",
3939
"karma-coverage": "~0.2.1",
4040
"grunt-contrib-watch": "~0.6.1",
4141
"grunt-karma-coveralls": "~2.5.0",
4242
"karma-mocha": "~0.1.3",
4343
"karma-sinon": "~1.0.3",
4444
"time-grunt": "~0.3.1",
4545
"browserify": "4.1.3",
46-
"grunt-browserify": "2.1.0"
46+
"grunt-browserify": "2.1.0",
47+
"karma-spec-reporter": "0.0.13"
4748
},
4849
"scripts": {
4950
"test": "node node_modules/grunt-cli/bin/grunt test"

src/datastore/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -461,8 +461,8 @@ function DSProvider() {
461461
var defaults = this.defaults = new BaseConfig();
462462

463463
this.$get = [
464-
'$rootScope', '$log', '$q', 'DSHttpAdapter', 'DSLocalStorageAdapter', 'DSUtils', 'DSErrors', 'DSCacheFactory',
465-
function ($rootScope, $log, $q, DSHttpAdapter, DSLocalStorageAdapter, DSUtils, DSErrors, DSCacheFactory) {
464+
'$rootScope', '$log', '$q', 'DSHttpAdapter', 'DSLocalStorageAdapter', 'DSUtils', 'DSErrors',
465+
function ($rootScope, $log, $q, DSHttpAdapter, DSLocalStorageAdapter, DSUtils, DSErrors) {
466466

467467
var syncMethods = require('./sync_methods'),
468468
asyncMethods = require('./async_methods'),

test/integration/adapters/http/create.test.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
describe('DSHttpAdapter.create(resourceConfig, attrs, options)', function () {
2+
3+
beforeEach(startInjector);
4+
25
it('should make a POST request', function () {
36
$httpBackend.expectPOST('api/posts', {
47
author: 'John',

test/integration/adapters/http/destroy.test.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
describe('DSHttpAdapter.destroy(resourceConfig, id, options)', function () {
2+
3+
beforeEach(startInjector);
4+
25
it('should make a DELETE request', function () {
36
$httpBackend.expectDELETE('api/posts/1').respond(200, 1);
47

test/integration/adapters/http/destroyAll.test.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
describe('DSHttpAdapter.destroyAll(resourceConfig, params, options)', function () {
2+
3+
beforeEach(startInjector);
4+
25
it('should make a DELETE request', function () {
36
$httpBackend.expectDELETE('api/posts').respond(204);
47

test/integration/adapters/http/find.test.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
describe('DSHttpAdapter.find(resourceConfig, id, options)', function () {
2+
3+
beforeEach(startInjector);
4+
25
it('should make a GET request', function () {
36
$httpBackend.expectGET('api/posts/1').respond(200, p1);
47

test/integration/adapters/http/findAll.test.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
describe('DSHttpAdapter.findAll(resourceConfig, params, options)', function () {
2+
3+
beforeEach(startInjector);
4+
25
it('should make a GET request', function () {
36
$httpBackend.expectGET('api/posts').respond(200, [p1]);
47

test/integration/adapters/http/update.test.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
describe('DSHttpAdapter.update(resourceConfig, id, attrs, options)', function () {
2+
3+
beforeEach(startInjector);
4+
25
it('should make a PUT request', function () {
36
$httpBackend.expectPUT('api/posts/1', {
47
author: 'John',

test/integration/adapters/http/updateAll.test.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
describe('DSHttpAdapter.updateAll(resourceConfig, attrs, params, options)', function () {
2+
3+
beforeEach(startInjector);
4+
25
it('should make a PUT request', function () {
36
$httpBackend.expectPUT('api/posts').respond(200, [p1]);
47

test/integration/adapters/localStorage/destroy.test.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
describe('DSLocalStorageAdapter.destroy(resourceConfig, id, options)', function () {
2+
3+
beforeEach(startInjector);
4+
25
it('should destroy an item from localStorage', function (done) {
36
var path = DSUtils.makePath('api', 'posts', 1);
47

test/integration/adapters/localStorage/find.test.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
describe('DSLocalStorageAdapter.find(resourceConfig, id, options)', function () {
2+
3+
beforeEach(startInjector);
4+
25
it('should retrieve an item from localStorage', function (done) {
36
var path = DSUtils.makePath('api', 'posts', 1);
47

test/integration/adapters/localStorage/update.test.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
describe('DSLocalStorageAdapter.update(resourceConfig, id, attrs, options)', function () {
2+
3+
beforeEach(startInjector);
4+
25
it('should make a PUT request', function (done) {
36
var path = DSUtils.makePath('api', 'posts', 1);
47

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
describe('DSCacheFactory integration', function () {
2+
3+
beforeEach(function () {
4+
module('angular-data.DSCacheFactory');
5+
});
6+
7+
beforeEach(startInjector);
8+
9+
it('should get an item from the server and delete when using DSCacheFactory in passive mode', function (done) {
10+
DS.defineResource({
11+
name: 'comment',
12+
endpoint: '/comments',
13+
deleteOnExpire: 'passive',
14+
maxAge: 20
15+
});
16+
17+
$httpBackend.expectGET('http://test.angular-cache.com/comments/5').respond(200, {
18+
id: 5,
19+
text: 'test'
20+
});
21+
22+
DS.find('comment', 5).then(function (comment) {
23+
assert.deepEqual(comment, {
24+
id: 5,
25+
text: 'test'
26+
});
27+
}, function (err) {
28+
console.error(err.stack);
29+
fail('Should not have rejected!');
30+
});
31+
32+
$httpBackend.flush();
33+
34+
assert.deepEqual(DS.get('comment', 5), {
35+
id: 5,
36+
text: 'test'
37+
}, 'The comment is now in the store');
38+
assert.isNumber(DS.lastModified('comment', 5));
39+
assert.isNumber(DS.lastSaved('comment', 5));
40+
41+
setTimeout(function () {
42+
assert.isUndefined(DS.get('comment', 5));
43+
44+
assert.equal(lifecycle.beforeInject.callCount, 1, 'beforeInject should have been called');
45+
assert.equal(lifecycle.afterInject.callCount, 1, 'afterInject should have been called');
46+
assert.equal(lifecycle.serialize.callCount, 0, 'serialize should have been called');
47+
assert.equal(lifecycle.deserialize.callCount, 1, 'deserialize should have been called');
48+
49+
done();
50+
}, 100);
51+
});
52+
it('should get an item from the server and delete when using DSCacheFactory in aggressive mode', function (done) {
53+
DS.defineResource({
54+
name: 'comment',
55+
endpoint: '/comments',
56+
deleteOnExpire: 'aggressive',
57+
recycleFreq: 10,
58+
maxAge: 20
59+
});
60+
61+
$httpBackend.expectGET('http://test.angular-cache.com/comments/5').respond(200, {
62+
id: 5,
63+
text: 'test'
64+
});
65+
66+
DS.find('comment', 5).then(function (comment) {
67+
assert.deepEqual(comment, {
68+
id: 5,
69+
text: 'test'
70+
});
71+
}, function (err) {
72+
console.error(err.stack);
73+
fail('Should not have rejected!');
74+
});
75+
76+
$httpBackend.flush();
77+
78+
assert.deepEqual(DS.get('comment', 5), {
79+
id: 5,
80+
text: 'test'
81+
}, 'The comment is now in the store');
82+
assert.isNumber(DS.lastModified('comment', 5));
83+
assert.isNumber(DS.lastSaved('comment', 5));
84+
85+
setTimeout(function () {
86+
assert.isUndefined(DS.get('comment', 5));
87+
88+
assert.equal(lifecycle.beforeInject.callCount, 1, 'beforeInject should have been called');
89+
assert.equal(lifecycle.afterInject.callCount, 1, 'afterInject should have been called');
90+
assert.equal(lifecycle.serialize.callCount, 0, 'serialize should have been called');
91+
assert.equal(lifecycle.deserialize.callCount, 1, 'deserialize should have been called');
92+
93+
done();
94+
}, 100);
95+
});
96+
});

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

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
describe('DS.create(resourceName, attrs[, options])', function () {
22
var errorPrefix = 'DS.create(resourceName, attrs[, options]): ';
33

4+
beforeEach(startInjector);
5+
46
it('should throw an error when method pre-conditions are not met', function () {
57
DS.create('does not exist', 5).then(function () {
68
fail('should have rejected');

0 commit comments

Comments
 (0)