Skip to content
This repository was archived by the owner on Mar 17, 2025. It is now read-only.

Commit 787fedc

Browse files
author
jacobawenger
committed
Merged with release_0.8.1
2 parents b37d659 + 83b92cf commit 787fedc

File tree

5 files changed

+24
-11
lines changed

5 files changed

+24
-11
lines changed

dist/angularfire.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@
610610
}
611611
};
612612

613-
self.$id = $firebase.$ref().name();
613+
self.$id = $firebase.$ref().ref().name();
614614
self.$priority = null;
615615
}
616616

@@ -768,7 +768,6 @@
768768
$$updated: function (snap) {
769769
// applies new data to this object
770770
var changed = $firebaseUtils.updateRec(this, snap);
771-
this.$id = snap.name();
772771
if( changed ) {
773772
// notifies $watch listeners and
774773
// updates $scope if bound to a variable

dist/angularfire.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/FirebaseObject.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
}
6565
};
6666

67-
self.$id = $firebase.$ref().name();
67+
self.$id = $firebase.$ref().ref().name();
6868
self.$priority = null;
6969
}
7070

@@ -222,7 +222,6 @@
222222
$$updated: function (snap) {
223223
// applies new data to this object
224224
var changed = $firebaseUtils.updateRec(this, snap);
225-
this.$id = snap.name();
226225
if( changed ) {
227226
// notifies $watch listeners and
228227
// updates $scope if bound to a variable

tests/unit/FirebaseArray.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,7 @@ describe('$FirebaseArray', function () {
671671
}
672672
})();
673673

674+
//todo abstract into testutils
674675
function stubFb() {
675676
var ref = testutils.ref();
676677
var fb = {};

tests/unit/FirebaseObject.spec.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,19 @@ describe('$FirebaseObject', function() {
2828
});
2929
});
3030

31+
describe('constructor', function() {
32+
it('should set the record id', function() {
33+
expect(obj.$id).toEqual($fb.$ref().name());
34+
});
35+
36+
it('should accept a query', function() {
37+
var obj = makeObject(FIXTURE_DATA, $fb.$ref().limit(1).startAt(null));
38+
obj.$$updated(testutils.snap({foo: 'bar'}));
39+
flushAll();
40+
expect(obj).toEqual(jasmine.objectContaining({foo: 'bar'}));
41+
});
42+
});
43+
3144
describe('$save', function () {
3245
it('should call $firebase.$set', function () {
3346
obj.foo = 'bar';
@@ -417,9 +430,9 @@ describe('$FirebaseObject', function() {
417430
});
418431

419432
it('should preserve the id', function() {
420-
var oldId = obj.$id;
433+
obj.$id = 'change_id_for_test';
421434
obj.$$updated(fakeSnap(true));
422-
expect(obj.$id).toBe(oldId);
435+
expect(obj.$id).toBe('change_id_for_test');
423436
});
424437

425438
it('should set the priority', function() {
@@ -463,8 +476,9 @@ describe('$FirebaseObject', function() {
463476
return testutils.refSnap(testutils.ref('data/a'), data, pri);
464477
}
465478

466-
function stubFb() {
467-
var ref = testutils.ref('data/a');
479+
//todo abstract into testutils
480+
function stubFb(ref) {
481+
if( !ref ) { ref = testutils.ref('data/a'); }
468482
var fb = {};
469483
[
470484
'$set', '$update', '$remove', '$transaction', '$asArray', '$asObject', '$ref', '$push'
@@ -497,10 +511,10 @@ describe('$FirebaseObject', function() {
497511

498512
function noop() {}
499513

500-
function makeObject(initialData) {
514+
function makeObject(initialData, ref) {
501515
var readyFuture = $utils.defer();
502516
var destroyFn = jasmine.createSpy('destroyFn');
503-
var fb = stubFb();
517+
var fb = stubFb(ref);
504518
var obj = new $FirebaseObject(fb, destroyFn, readyFuture.promise);
505519
obj.$$$readyFuture = readyFuture;
506520
obj.$$$destroyFn = destroyFn;

0 commit comments

Comments
 (0)