Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix uniques not freeing up locks being case-sensitive

Fix pubsub tests to use subscription_set instead of subscriptions
  • Loading branch information...
commit fbc826a4a7bb65eff1003d21f37721acc7a0800e 1 parent f2115e6
@maritz authored
View
3  lib/store.js
@@ -184,7 +184,8 @@ var __update = function __update(all, options, callback) {
// free old uniques
if (props[p].unique === true && props[p].__updated) {
if (self.__inDB) {
- multi.del(Nohm.prefix.unique + self.modelName + ':' + p + ':' + props[p].__oldValue, Nohm.logError);
+ var propLower = props[p].type === 'string' ? props[p].__oldValue.toLowerCase() : props[p].__oldValue;
+ multi.del(Nohm.prefix.unique + self.modelName + ':' + p + ':' + propLower, Nohm.logError);
}
}
if (props[p].index === true && (!self.__inDB || props[p].__updated)) {
View
3  lib/validation.js
@@ -100,6 +100,9 @@ exports.__checkUniques = function __checkUniques(setDirectly, saveCallback, p) {
}
async.map(Object.keys(tmp), uniqueLocker, function (err, arr) {
+ if (err) {
+ Nohm.logError('Database error while checking uniques.', err);
+ }
if (Array.isArray(arr) && arr.length > 0) {
arr.forEach(function(val) {
if (val && ! val.unique) {
View
79 test/featureTests.js
@@ -601,6 +601,32 @@ exports.uniqueEmpty = function (t) {
});
};
+exports["integer uniques"] = function (t) {
+ t.expect(5);
+ var obj = nohm.factory('UniqueInteger');
+ var obj2 = nohm.factory('UniqueInteger');
+ obj.p('unique', 123);
+ obj2.p('unique', 123);
+
+ obj.save(function (err) {
+ t.ok(!err, 'Unexpected saving error');
+ t.same(obj.allProperties(), {
+ unique: 123,
+ id: obj.id
+ }, 'Properties not correct');
+ obj2.save(function (err) {
+ t.same(err, 'invalid', 'Unique integer conflict did not result in error.');
+ obj.remove(function (err) {
+ t.ok(!err, 'Unexpected removing error');
+ obj2.save(function () {
+ t.ok(!err, 'Unexpected saving error');
+ t.done();
+ });
+ });
+ });
+ });
+};
+
exports.indexes = function (t) {
var user = new UserMockup();
t.expect(7);
@@ -644,6 +670,7 @@ exports.__updated = function (t) {
user.p('email', '__updatedTest@test.de');
user.save(function (err) {
if (err) {
+ console.log(err);
t.ok(false, 'Error while saving user in test for __updated.');
}
user.p('name', 'hurgelwurz');
@@ -889,32 +916,6 @@ exports.purgeDB = function (t) {
});
};
-exports["integer uniques"] = function (t) {
- t.expect(5);
- var obj = nohm.factory('UniqueInteger');
- var obj2 = nohm.factory('UniqueInteger');
- obj.p('unique', 123);
- obj2.p('unique', 123);
-
- obj.save(function (err) {
- t.ok(!err, 'Unexpected saving error');
- t.same(obj.allProperties(), {
- unique: 123,
- id: obj.id
- }, 'Properties not correct');
- obj2.save(function (err) {
- t.same(err, 'invalid', 'Unique integer conflict did not result in error.');
- obj.remove(function (err) {
- t.ok(!err, 'Unexpected removing error');
- obj2.save(function () {
- t.ok(!err, 'Unexpected saving error');
- t.done();
- });
- });
- });
- });
-};
-
exports["no key left behind"] = function (t) {
var user = nohm.factory('UserMockup');
var user2 = nohm.factory('UserMockup');
@@ -956,3 +957,29 @@ exports["no key left behind"] = function (t) {
}
);
};
+
+exports["changing unique frees old unique with uppercase values"] = function (t) {
+ t.expect(3);
+ var obj = nohm.factory('UserMockup');
+ var obj2 = nohm.factory('UserMockup');
+ var obj3 = nohm.factory('UserMockup');
+ var old = "Changing Unique Property Frees The Value";
+ obj.p('name', old);
+
+ obj.save(function (err) {
+ t.ok(!err, 'Unexpected saving error');
+ obj2.load(obj.id, function () {
+ obj2.p('name', "changing unique property frees the value to something else")
+ obj2.save(function (err) {
+ t.ok(!err, 'Unexpected saving error');
+ obj3.load(obj.id, function () {
+ obj2.p('name', old);
+ obj2.save(function (err) {
+ t.ok(!err, 'Unexpected saving error. (May be because old uniques are not freed properly on chnage.');
+ t.done();
+ });
+ });
+ });
+ });
+ });
+};
View
4 test/pubsub/child.js
@@ -3,7 +3,9 @@ var nohm = require(__dirname+'/../../lib/nohm').Nohm;
var args = require(__dirname+'/../testArgs.js');
nohm.setPrefix(args.prefix);
-nohm.setClient(args.redis);
+args.redis.on('ready', function () {
+ nohm.setClient(args.redis);
+});
require(__dirname+'/Model.js');
process.on('message', function (msg) {
View
2  test/pubsubTests.js
@@ -44,7 +44,7 @@ module.exports = {
nohm.setPubSubClient(secondaryClient, function (err) {
t.ok(!err, 'There was an error while subscribing');
t.same(nohm.getPubSubClient(), secondaryClient, 'Second redis client wasn\'t set properly');
- t.ok(nohm.getPubSubClient().subscriptions, 'Second redis client isn\'t subscribed to anything');
+ t.ok(nohm.getPubSubClient().subscription_set, 'Second redis client isn\'t subscribed to anything');
t.done();
});
},
Please sign in to comment.
Something went wrong with that request. Please try again.