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

Commit eb85343

Browse files
author
Jacob Wenger
committed
Merge pull request #391 from firebase/release_0.8.1_defaults
Fixes #385 - not accepting factory names for arrayFactory and objectFact...
2 parents 83b92cf + 787fedc commit eb85343

File tree

4 files changed

+71
-7
lines changed

4 files changed

+71
-7
lines changed

dist/angularfire.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,13 +1511,23 @@ if ( typeof Object.getPrototypeOf !== "function" ) {
15111511
'use strict';
15121512

15131513
angular.module('firebase')
1514-
.factory('$firebaseConfig', ["$FirebaseArray", "$FirebaseObject",
1515-
function($FirebaseArray, $FirebaseObject) {
1514+
.factory('$firebaseConfig', ["$FirebaseArray", "$FirebaseObject", "$injector",
1515+
function($FirebaseArray, $FirebaseObject, $injector) {
15161516
return function(configOpts) {
1517+
// make a copy we can modify
1518+
var opts = angular.extend({}, configOpts);
1519+
// look up factories if passed as string names
1520+
if( typeof opts.objectFactory === 'string' ) {
1521+
opts.objectFactory = $injector.get(opts.objectFactory);
1522+
}
1523+
if( typeof opts.arrayFactory === 'string' ) {
1524+
opts.arrayFactory = $injector.get(opts.arrayFactory);
1525+
}
1526+
// extend defaults and return
15171527
return angular.extend({
15181528
arrayFactory: $FirebaseArray,
15191529
objectFactory: $FirebaseObject
1520-
}, configOpts);
1530+
}, opts);
15211531
};
15221532
}
15231533
])

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/utils.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,23 @@
22
'use strict';
33

44
angular.module('firebase')
5-
.factory('$firebaseConfig', ["$FirebaseArray", "$FirebaseObject",
6-
function($FirebaseArray, $FirebaseObject) {
5+
.factory('$firebaseConfig', ["$FirebaseArray", "$FirebaseObject", "$injector",
6+
function($FirebaseArray, $FirebaseObject, $injector) {
77
return function(configOpts) {
8+
// make a copy we can modify
9+
var opts = angular.extend({}, configOpts);
10+
// look up factories if passed as string names
11+
if( typeof opts.objectFactory === 'string' ) {
12+
opts.objectFactory = $injector.get(opts.objectFactory);
13+
}
14+
if( typeof opts.arrayFactory === 'string' ) {
15+
opts.arrayFactory = $injector.get(opts.arrayFactory);
16+
}
17+
// extend defaults and return
818
return angular.extend({
919
arrayFactory: $FirebaseArray,
1020
objectFactory: $FirebaseObject
11-
}, configOpts);
21+
}, opts);
1222
};
1323
}
1424
])

tests/unit/firebase.spec.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@ describe('$firebase', function () {
77
module('firebase');
88
module('mock.firebase');
99
module('mock.utils');
10+
// have to create these before the first call to inject
11+
// or they will not be registered with the angular mock injector
12+
angular.module('firebase').provider('TestArrayFactory', {
13+
$get: function() {
14+
return function() {}
15+
}
16+
}).provider('TestObjectFactory', {
17+
$get: function() {
18+
return function() {};
19+
}
20+
});
1021
inject(function (_$firebase_, _$timeout_, _$rootScope_, $firebaseUtils) {
1122
$firebase = _$firebase_;
1223
$timeout = _$timeout_;
@@ -32,6 +43,39 @@ describe('$firebase', function () {
3243
$firebase('hello world');
3344
}).toThrowError(/valid Firebase reference/);
3445
});
46+
47+
it('should accept a factory name for arrayFactory', function() {
48+
var ref = new Firebase('Mock://');
49+
var app = angular.module('firebase');
50+
// if this does not throw an error we are fine
51+
expect($firebase(ref, {arrayFactory: 'TestArrayFactory'})).toBeAn('object');
52+
});
53+
54+
it('should accept a factory name for objectFactory', function() {
55+
var ref = new Firebase('Mock://');
56+
var app = angular.module('firebase');
57+
app.provider('TestObjectFactory', {
58+
$get: function() {
59+
return function() {}
60+
}
61+
});
62+
// if this does not throw an error we are fine
63+
expect($firebase(ref, {objectFactory: 'TestObjectFactory'})).toBeAn('object');
64+
});
65+
66+
it('should throw an error if factory name for arrayFactory does not exist', function() {
67+
var ref = new Firebase('Mock://');
68+
expect(function() {
69+
$firebase(ref, {arrayFactory: 'notarealarrayfactorymethod'})
70+
}).toThrowError();
71+
});
72+
73+
it('should throw an error if factory name for objectFactory does not exist', function() {
74+
var ref = new Firebase('Mock://');
75+
expect(function() {
76+
$firebase(ref, {objectFactory: 'notarealobjectfactorymethod'})
77+
}).toThrowError();
78+
});
3579
});
3680

3781
describe('$ref', function() {

0 commit comments

Comments
 (0)