Browse files

orpheus 0.2.1 - Fixed a bug where number fields with 0 as the value w…

…ould get discarded when getting the model
  • Loading branch information...
1 parent 632c394 commit 542c14de6f21c768a115026029d8fd5ad19e8174 @Radagaisus committed Nov 13, 2012
Showing with 33 additions and 8 deletions.
  1. +1 −1 dist/commands.js
  2. +4 −3 dist/orpheus.js
  3. +1 −0 history.md
  4. +5 −4 lib/orpheus.coffee
  5. +22 −0 test/orpheus.spec.coffee
View
2 dist/commands.js
@@ -16,7 +16,7 @@
zincrby: true,
hmset: true
},
- getters: ['lrange', 'smembers', 'scard', 'zrange', 'zrangebyscore', 'zrevrange', 'zrevrangebyscore', 'zscore', 'zrank', 'zrevrank', 'zcount', 'hget', 'hgetall', 'hmget'],
+ getters: ['lrange', 'smembers', 'scard', 'zrange', 'zrangebyscore', 'zrevrange', 'zrevrangebyscore', 'zscore', 'zrank', 'zrevrank', 'zcount', 'zcard', 'hget', 'hgetall', 'hmget'],
str: ['hdel', 'hexists', 'hget', 'hsetnx', 'hset'],
num: ['hdel', 'hexists', 'hget', 'hsetnx', 'hset', 'hincrby', 'hincrbyfloat'],
list: ['blpop', 'brpop', 'brpoplpush', 'lindex', 'linsert', 'llen', 'lpop', 'lpush', 'lpushx', 'lrange', 'lrem', 'lset', 'ltrim', 'rpop', 'rpoplpush', 'rpush', 'rpushx'],
View
7 dist/orpheus.js
@@ -37,7 +37,7 @@
return Orpheus.__super__.constructor.apply(this, arguments);
}
- Orpheus.version = "0.2.0";
+ Orpheus.version = "0.2.1";
Orpheus.config = {
prefix: 'orpheus'
@@ -531,7 +531,7 @@
};
OrpheusAPI.prototype._create_getter_object = function(res) {
- var i, index, member, new_res, s, _i, _j, _len, _len1, _ref, _ref1, _step;
+ var field, i, index, member, new_res, s, _i, _j, _len, _len1, _ref, _ref1, _step;
new_res = {};
_ref = this._res_schema;
for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {
@@ -548,7 +548,8 @@
} else {
new_res[s.name] = res[i];
}
- if (!new_res[s.name] || (_.isObject(new_res[s.name]) && _.isEmpty(new_res[s.name]))) {
+ field = new_res[s.name];
+ if (_.isNull(field) || _.isUndefined(field) || (_.isObject(field) && _.isEmpty(field))) {
if (_.isUndefined(this.model[s.name].options["default"])) {
delete new_res[s.name];
} else {
View
1 history.md
@@ -3,6 +3,7 @@
# 0.2.1
- added `zcard` to the getters
+- Fixed a bug where number fields with 0 as the value would get discarded when getting the model
# 0.2.0
View
9 lib/orpheus.coffee
@@ -503,10 +503,11 @@ class OrpheusAPI
else
new_res[s.name] = res[i]
- # Use the field's defaults or delete the field if
- # it's empty (undefined, null, {}, [])
- if not new_res[s.name] or (_.isObject(new_res[s.name]) and _.isEmpty(new_res[s.name]))
-
+ # If the field is empty - undefined, null, {}, []
+ # then user the field's default or delete the field
+ # if there's no default.
+ field = new_res[s.name]
+ if _.isNull(field) or _.isUndefined(field) or (_.isObject(field) and _.isEmpty(field))
if _.isUndefined @model[s.name].options.default
then delete new_res[s.name]
else new_res[s.name] = @model[s.name].options.default
View
22 test/orpheus.spec.coffee
@@ -1033,3 +1033,25 @@ describe 'Defaults', ->
expect(res.troll).toBe 'trololol'
expect(res.sup).toBeUndefined() # No default
done()
+
+describe 'Regressions', ->
+ it 'Returns an object with a number field with 0 as the value', (done) ->
+ class User extends Orpheus
+ constructor: ->
+ @num 'points'
+
+ user = User.create()
+ user('zero')
+ .points.set(0)
+ .exec ->
+ user('zero')
+ .points.get()
+ .exec (err, res) ->
+ expect(res.points).toBe(0)
+
+ # User with no points set whatsoever
+ user('hi')
+ .points.get()
+ .exec (err, res) ->
+ expect(res.points).toBe(0)
+ done()

0 comments on commit 542c14d

Please sign in to comment.