Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix nohm.factory() loading with non-integer id. Fixes #50

  • Loading branch information...
commit b8c75e7f486ce23dc0e81eba8cfef2c988f49913 1 parent adb0972
@maritz authored
Showing with 28 additions and 6 deletions.
  1. +1 −1  lib/nohm.js
  2. +27 −5 test/featureTests.js
View
2  lib/nohm.js
@@ -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);
}
View
32 test/featureTests.js
@@ -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',
@@ -83,6 +84,12 @@ var redis = args.redis,
idGenerator: 'increment'
});
+var NonIncrement = nohm.model('NonIncrement', {
+ properties: {
+ name: 'No name'
+ }
+});
+
exports.prepare = {
redisClean: function(t) {
@@ -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) {
Please sign in to comment.
Something went wrong with that request. Please try again.