Navigation Menu

Skip to content

Commit

Permalink
Fix nohm.factory() loading with non-integer id. Fixes #50
Browse files Browse the repository at this point in the history
  • Loading branch information
maritz committed Mar 14, 2012
1 parent adb0972 commit b8c75e7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/nohm.js
Expand Up @@ -95,7 +95,7 @@ Nohm.factory = function factory(name, id, callback) {
return false;
}
var obj = new models[name]();
if(typeof(id) === 'number' && typeof(callback) === 'function') {
if(typeof(id) !== 'undefined' && typeof(callback) === 'function') {
obj.id = id;
obj.load(id, callback);
}
Expand Down
32 changes: 27 additions & 5 deletions test/featureTests.js
Expand Up @@ -20,11 +20,12 @@ exports.checkModules = function (t) {
var prefix = args.prefix;

// real tests start in 3.. 2.. 1.. NOW!
var redis = args.redis,
nohm = require(__dirname+'/../lib/nohm').Nohm,
helper = require(__dirname+'/../lib/helpers'),
async = require('async'),
UserMockup = nohm.model('UserMockup', {
var redis = args.redis;
var nohm = require(__dirname+'/../lib/nohm').Nohm;
var helper = require(__dirname+'/../lib/helpers');
var async = require('async');

var UserMockup = nohm.model('UserMockup', {
properties: {
name: {
type: 'string',
Expand Down Expand Up @@ -83,6 +84,12 @@ var redis = args.redis,
idGenerator: 'increment'
});

var NonIncrement = nohm.model('NonIncrement', {
properties: {
name: 'No name'
}
});


exports.prepare = {
redisClean: function(t) {
Expand Down Expand Up @@ -819,6 +826,21 @@ exports.factory = function (t) {
t.ok(user2, 'Using the factory with an id and callback returned false');
};

exports["factory with non-integer id"] = function (t) {
t.expect(3);
var name = 'NonIncrement';
var obj = nohm.factory(name);
obj.p('name', 'factory_non_integer_load');
obj.save(function (err) {
t.ok(!err, 'Unexpected saving error');
var obj2 = nohm.factory(name, obj.id, function (err) {
t.ok(!err, 'Unexpected factory loading error');
t.same(obj2.allProperties(), obj.allProperties(), 'The loaded object seems to have wrong properties');
t.done();
});
});
};

exports.purgeDB = function (t) {
var expected = 1;
var countKeys = function (prefix, callback) {
Expand Down

0 comments on commit b8c75e7

Please sign in to comment.