Permalink
Browse files

Fix for the new redis.keys() return format. (when no keys were found …

…[] instead of null)
  • Loading branch information...
1 parent b3fc154 commit 264fcbac64dc1985a0a23f5e4ca76f3f3ac3550a @maritz committed Jan 19, 2011
Showing with 23 additions and 17 deletions.
  1. +15 −11 lib/nohm.js
  2. +3 −2 test/features.js
  3. +4 −3 test/relations.js
  4. +1 −1 test/tests.js
View
26 lib/nohm.js
@@ -11,13 +11,19 @@ numToAlpha = helpers.numToAlpha,
getCallback = helpers.getCallback,
checkEqual = helpers.checkEqual;
-var prefix = 'nohm';
+var prefix = null;
process.argv.forEach(function (val, index) {
- if (val === '--nohm-prefix') {
- prefix = process.argv[index + 1];
- }
-});
+ if (val.indexOf('test/tests.js') !== -1)
+ prefix = 'tests';
+ if ( ! prefix && val === '--nohm-prefix') {
+ prefix = process.argv[index + 1];
+ }
+ });
+
+if ( ! prefix)
+ prefix = 'nohm';
+
var urlRegexp = /^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([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|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i,
indexNumberTypes = ['integer', 'float', 'timestamp'],
@@ -54,12 +60,10 @@ var ModelClass = {
* Main constructor. Initializes the object.
*/
constructor: function constuctor(id) {
- if (this.modelName === 'Model') {
- throw 'modelName has to be set to your models name!';
- }
- if (client === null) {
+ if ( ! this.modelName || this.modelName === 'Model')
+ throw new Error('modelName has to be set to your models name!');
+ if (client === null)
throw 'redis client not set. use nohm.connect(port, host)';
- }
this.p = this.prop = this.property; // create short calls
@@ -483,7 +487,7 @@ var ModelClass = {
self.logError(err);
}
- if (keys) {
+ if (keys && Array.isArray(keys) && keys.length > 0) {
keys = keys.toString().split(',');
inConductCallback = function (key, callback) {
relationActions.push(function (multi) {
View
5 test/features.js
@@ -20,7 +20,7 @@ exports.checkModules = function (t) {
t.done();
};
-var prefix = 'nohm';
+var prefix = 'tests';
process.argv.forEach(function (val, index) {
if (val === '--nohm-prefix') {
@@ -76,7 +76,8 @@ var UserMockup = nohm.Model.extend({
exports.redisClean = function (t) {
t.expect(1);
redis.keys(prefix + ':*:*Mockup:*', function (err, value) {
- t.ok(value === null, 'The redis database seems to contain fragments from previous nohm testruns. Use the redis command "KEYS nohm:*:*Mockup:*" to see what keys could be the cause.');
+ var check = (Array.isArray(value) && value.length === 0) || value === null;
+ t.ok(check, 'The redis database seems to contain fragments from previous nohm testruns. Use the redis command "KEYS '+prefix+':*:*Mockup:*" to see what keys could be the cause.');
t.done();
});
};
View
7 test/relations.js
@@ -1,7 +1,7 @@
"use strict";
var util = require('util');
-var prefix = 'nohm';
+var prefix = 'tests';
process.argv.forEach(function (val, index) {
if (val === '--nohm-prefix') {
@@ -168,9 +168,10 @@ exports.unlink = function (t) {
if (!err) {
t.ok(unlinkCallbackCalled, 'The provided callback for unlinking was not called.');
t.ok(unlinkCallbackCalled2, 'The provided callback for the second(!) unlinking was not called.');
- redis.keys(relationsprefix + '*', function (err, values) {
+ redis.keys(relationsprefix + '*', function (err, value) {
if (!err) {
- t.equals(values, null, 'Unlinking an object did not delete keys.');
+ var check = (Array.isArray(value) && value.length === 0) || value === null;
+ t.ok(check, 'Unlinking an object did not delete keys.');
}
t.done();
});
View
2 test/tests.js
@@ -54,7 +54,7 @@ run = function(files){
};
-var prefix = 'nohm';
+var prefix = 'tests';
process.argv.forEach(function (val, index) {
if (val === '--nohm-prefix') {

0 comments on commit 264fcba

Please sign in to comment.