Skip to content

Commit a428555

Browse files
committed
Merge pull request Urigo#438 from mxab/cfs-file-insert-fix
Cfs file insert fix
2 parents c16f862 + 638f2ba commit a428555

File tree

3 files changed

+48
-4
lines changed

3 files changed

+48
-4
lines changed

modules/angular-meteor-meteorCollection.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ angularMeteorCollections.factory('AngularMeteorCollection', ['$q', '$meteorSubsc
3030
var deferred = $q.defer();
3131

3232
// delete $$hashkey
33-
if (!(item instanceof File))
34-
item = $meteorUtils.stripDollarPrefixedKeys(item);
33+
item = $meteorUtils.stripDollarPrefixedKeys(item);
3534

3635
if (item._id) { // Performs an update if the _id property is set.
3736
var item_id = item._id; // Store the _id in temporary variable

modules/angular-meteor-utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ angularMeteorUtils.service('$meteorUtils', [ '$timeout',
2525
};
2626
// Borrowed from angularFire - https://github.com/firebase/angularfire/blob/master/src/utils.js#L445-L454
2727
this.stripDollarPrefixedKeys = function (data) {
28-
if( !angular.isObject(data) || data instanceof File || data instanceof Date) { return data; }
28+
if( !angular.isObject(data) || data instanceof File || (typeof FS === 'object' && data instanceof FS.File) || data instanceof Date) { return data; }
2929
var out = angular.isArray(data)? [] : {};
3030
angular.forEach(data, function(v,k) {
3131
if(typeof k !== 'string' || k.charAt(0) !== '$') {
3232
out[k] = self.stripDollarPrefixedKeys(v);
3333
}
3434
});
3535
return out;
36-
}
36+
};
3737
}]);
3838

3939
angularMeteorUtils.run(['$rootScope', '$meteorUtils',

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,49 @@ describe('$meteorUtils service', function () {
7070
expect(handle.stop).toHaveBeenCalled();
7171
});
7272
});
73+
describe('stripDollarPrefixedKeys', function () {
74+
75+
it('should remove keys with $ prefix', function(){
76+
77+
var result = $meteorUtils.stripDollarPrefixedKeys({'$foo': 1, '$$baz': 3, bar : 2});
78+
expect(result.hasOwnProperty('$foo')).toBe(false);
79+
expect(result.hasOwnProperty('$$baz')).toBe(false);
80+
expect(result.bar).toEqual(2);
81+
82+
});
83+
it('should ignore FS.File instances', function(){
84+
85+
var cfsExits = typeof window.FS === 'object';
86+
if(!cfsExits){
87+
window.FS = {
88+
File : function(){}
89+
};
90+
}
91+
92+
var fsFile = new FS.File();
93+
var result = $meteorUtils.stripDollarPrefixedKeys(fsFile);
94+
95+
if(!cfsExits){ // clean up
96+
delete window.FS;
97+
}
98+
expect(result).toBe(fsFile);
99+
100+
});
101+
it('should ignore Date instances', function(){
102+
103+
var input = new Date();
104+
var result = $meteorUtils.stripDollarPrefixedKeys(input);
105+
106+
expect(result).toBe(input);
107+
108+
});
109+
it('should ignore File instances', function(){
110+
111+
var input = new File([], "myfile.jpg");
112+
var result = $meteorUtils.stripDollarPrefixedKeys(input);
113+
114+
expect(result).toBe(input);
115+
116+
});
117+
});
73118
});

0 commit comments

Comments
 (0)