Skip to content

Commit 229bc33

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 898e09c + 51c8f7d commit 229bc33

File tree

4 files changed

+91
-1
lines changed

4 files changed

+91
-1
lines changed

.docs/angular-meteor/client/views/steps/tutorial.step_19.tpl

+2
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ Package.onUse(function(api) {
127127
api.use('DEPENDENCY_NAME', where); // Dependencies
128128
129129
api.addFiles('FILE_NAME', where); // Files in use
130+
});
130131
```
131132

132133
Now, just fill the information inside the file, according to the package information, the `bower.json` could be helpful to fill missing information you can't find.
@@ -157,6 +158,7 @@ Package.onUse(function(api) {
157158
api.use('stevezhu:[email protected]', where); // Surprised?! Read the bower.json file!
158159
159160
api.addFiles('src/angularjs-dropdown-multiselect.js', where); // Files in use
161+
});
160162
```
161163

162164
**Important Notes:**

package.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ Package.onTest(function(api) {
7171
'tests/integration/angular-meteor-session-spec.js',
7272
'tests/integration/angular-meteor-diff-array-spec.js',
7373
'tests/integration/angular-meteor-collection-spec.js',
74-
'tests/integration/angular-meteor-utils-spec.js'
74+
'tests/integration/angular-meteor-utils-spec.js',
75+
'tests/integration/test_collections.js'
7576
], 'client');
77+
78+
api.addFiles([
79+
'tests/integration/test_collections.js'
80+
], 'server');
7681
});

tests/integration/angular-meteor-collection-spec.js

+74
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,78 @@ describe('$meteorCollection service', function() {
115115
expect(meteorArray).toEqualCollection(MyCollection);
116116
});
117117
});
118+
119+
describe('observe server changes', function() {
120+
121+
beforeEach(function() {
122+
// Cleaning up after each test.
123+
bigCollection.find({}).forEach(function(doc) {
124+
bigCollection.remove(doc._id);
125+
});
126+
127+
for (var i = 0; i < 100; i++) {
128+
bigCollection.insert({count: i});
129+
}
130+
});
131+
132+
it('$apply executed twice', function() {
133+
134+
var $ngCol = $meteorCollection(bigCollection);
135+
136+
expect($rootScope.$apply).toHaveBeenCalled();
137+
138+
expect($ngCol).toEqualCollection(bigCollection);
139+
140+
// No matter how much elements MyCollection contains
141+
// $rootScope.$apply should be called twice.
142+
expect($rootScope.$apply.calls.count()).toEqual(2);
143+
144+
});
145+
146+
it('push updates from client handled correctly', function() {
147+
148+
$rootScope.limit = 10;
149+
var $ngCol = $meteorCollection(function() {
150+
return bigCollection.find({}, {
151+
limit: $rootScope.getReactively('limit')
152+
});
153+
});
154+
spyOn($ngCol, 'save');
155+
156+
// Adds docs on the client.
157+
for (var i = 100; i < 106; i++) {
158+
$ngCol.push({count: i});
159+
}
160+
161+
$timeout.flush();
162+
163+
expect($ngCol.length).toEqual(10);
164+
expect($ngCol.save).toHaveBeenCalled();
165+
expect($ngCol.save.calls.count()).toEqual(6);
166+
});
167+
168+
it('remove updates from client handled correctly', function() {
169+
170+
$rootScope.limit = 10;
171+
var $ngCol = $meteorCollection(function() {
172+
return bigCollection.find({}, {
173+
limit: $rootScope.getReactively('limit')
174+
});
175+
});
176+
spyOn($ngCol, 'remove').and.callThrough();
177+
178+
// Removes last two docs on the client.
179+
$ngCol.pop();
180+
$ngCol.pop();
181+
182+
$timeout.flush();
183+
184+
// Size should stay at 10 after removing because
185+
// limit is set.
186+
expect($ngCol.length).toEqual(10);
187+
expect($ngCol.remove).toHaveBeenCalled();
188+
expect($ngCol.remove.calls.count()).toEqual(2);
189+
});
190+
191+
});
118192
});

tests/integration/test_collections.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
bigCollection = new Meteor.Collection('bigCollection');
2+
bigCollection.allow({
3+
remove: function() {
4+
return true;
5+
},
6+
insert: function() {
7+
return true;
8+
}
9+
});

0 commit comments

Comments
 (0)