Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix for empty promises + test

  • Loading branch information...
commit 4081eefb14ff9afa889b654b2ec8f8923a047ae2 1 parent 0d2da29
@rauchg rauchg authored
Showing with 14 additions and 6 deletions.
  1. +1 −1  lib/model.js
  2. +5 −5 lib/query.js
  3. +8 −0 tests/unit/spec.lib.query.js
View
2  lib/model.js
@@ -235,7 +235,7 @@ _define = function(proto, key, value){
var p = (path ? path + '.' : '') + i;
if (/^_/.test(i) && !(i in cast)) cast[p] = ObjectID;
(function(props, getters, setters, p, i){
- if (props[i] == null || props[i] instanceof Array){
+ if (props[i] === null || props[i] instanceof Array){
prototype.__defineGetter__(i, function(){
return getters[i] ? getters[i].apply(this, [this._get(p)]) : this._get(p);
});
View
10 lib/query.js
@@ -72,23 +72,23 @@ Promise = this.Promise = Class({
},
_one: function(callback, data){
- callback.apply(this, [data[0] || null]);
+ if(callback) callback.apply(this, [data[0] || null]);
},
_first: function(callback, data){
- callback.apply(this, [data[0] || null]);
+ if(callback) callback.apply(this, [data[0] || null]);
},
_last: function(callback, data){
- callback.apply(this, [data[data.length - 1] || null]);
+ if(callback) callback.apply(this, [data[data.length - 1] || null]);
},
_get: function(callback, data){
- callback.apply(this, [data]);
+ if(callback) callback.apply(this, [data]);
},
_all: function(callback, data){
- callback.apply(this, [data]);
+ if(callback) callback.apply(this, [data]);
}
});
View
8 tests/unit/spec.lib.query.js
@@ -127,6 +127,14 @@ describe 'Query'
promise._queues.length.should.be 2
end
+ it 'should allow empty promises'
+ promise = new Promise();
+ promise.get()
+ promise.one()
+
+ -{ promise.complete([]) }.should.not.throw_error
+ end
+
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.