Skip to content

Commit 87bca6a

Browse files
committed
Merge pull request FirebaseExtended#288 from twilson63/master
Fix for issue FirebaseExtended#286 (make sure child is object before adding $priority)
2 parents 2baec65 + bd4dfa8 commit 87bca6a

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

angularfire.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@
5959
for (var i = 0; i < index.length; i++) {
6060
var val = input[index[i]];
6161
if (val) {
62-
val.$id = index[i];
62+
if (angular.isObject(val)) {
63+
val.$id = index[i];
64+
}
6365
sorted.push(val);
6466
}
6567
}

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"karma": "~0.10.4",
3131
"karma-chrome-launcher": "~0.1.0",
3232
"protractor": "~0.12.1",
33-
"lodash": "~2.4.1"
33+
"lodash": "~2.4.1",
34+
"karma-safari-launcher": "~0.1.1"
3435
}
3536
}

tests/automatic_karma.conf.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ module.exports = function(config) {
1616

1717
autoWatch: true,
1818
//Recommend starting Chrome manually with experimental javascript flag enabled, and open localhost:9876.
19-
browsers: ['Chrome']
19+
browsers: ['Chrome', 'Safari']
2020
});
2121
};

tests/unit/orderbypriority.spec.js

+20
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,24 @@ describe('OrderByPriority Filter', function () {
4040
});
4141
expect(res).toEqual(originalData);
4242
});
43+
44+
it('should return an array from a $firebase instance array', function () {
45+
var loaded = false;
46+
// autoFlush makes all Firebase methods trigger immediately
47+
var fb = new Firebase('Mock//sort',
48+
{data: {'0': 'foo', '1': 'bar'}}
49+
).child('data').autoFlush();
50+
var ref = $firebase(fb);
51+
// $timeout is a mock, so we have to tell the mock when to trigger it
52+
// and fire all the angularFire events
53+
$timeout.flush();
54+
// now we can actually trigger our filter and pass in the $firebase ref
55+
var res = $filter('orderByPriority')(ref);
56+
// and finally test the results against the original data in Firebase instance
57+
var originalData = _.map(fb.getData(), function(v, k) {
58+
return _.isObject(v)? _.assign({'$id': k}, v) : v;
59+
});
60+
expect(res).toEqual(originalData);
61+
});
62+
4363
});

0 commit comments

Comments
 (0)