Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
Moritz Peters authored
3  lib/store.js
@@ -184,7 +184,8 @@ var __update = function __update(all, options, callback) {
184 184 // free old uniques
185 185 if (props[p].unique === true && props[p].__updated) {
186 186 if (self.__inDB) {
187   - multi.del(Nohm.prefix.unique + self.modelName + ':' + p + ':' + props[p].__oldValue, Nohm.logError);
  187 + var propLower = props[p].type === 'string' ? props[p].__oldValue.toLowerCase() : props[p].__oldValue;
  188 + multi.del(Nohm.prefix.unique + self.modelName + ':' + p + ':' + propLower, Nohm.logError);
188 189 }
189 190 }
190 191 if (props[p].index === true && (!self.__inDB || props[p].__updated)) {
3  lib/validation.js
@@ -100,6 +100,9 @@ exports.__checkUniques = function __checkUniques(setDirectly, saveCallback, p) {
100 100 }
101 101
102 102 async.map(Object.keys(tmp), uniqueLocker, function (err, arr) {
  103 + if (err) {
  104 + Nohm.logError('Database error while checking uniques.', err);
  105 + }
103 106 if (Array.isArray(arr) && arr.length > 0) {
104 107 arr.forEach(function(val) {
105 108 if (val && ! val.unique) {
79 test/featureTests.js
@@ -601,6 +601,32 @@ exports.uniqueEmpty = function (t) {
601 601 });
602 602 };
603 603
  604 +exports["integer uniques"] = function (t) {
  605 + t.expect(5);
  606 + var obj = nohm.factory('UniqueInteger');
  607 + var obj2 = nohm.factory('UniqueInteger');
  608 + obj.p('unique', 123);
  609 + obj2.p('unique', 123);
  610 +
  611 + obj.save(function (err) {
  612 + t.ok(!err, 'Unexpected saving error');
  613 + t.same(obj.allProperties(), {
  614 + unique: 123,
  615 + id: obj.id
  616 + }, 'Properties not correct');
  617 + obj2.save(function (err) {
  618 + t.same(err, 'invalid', 'Unique integer conflict did not result in error.');
  619 + obj.remove(function (err) {
  620 + t.ok(!err, 'Unexpected removing error');
  621 + obj2.save(function () {
  622 + t.ok(!err, 'Unexpected saving error');
  623 + t.done();
  624 + });
  625 + });
  626 + });
  627 + });
  628 +};
  629 +
604 630 exports.indexes = function (t) {
605 631 var user = new UserMockup();
606 632 t.expect(7);
@@ -644,6 +670,7 @@ exports.__updated = function (t) {
644 670 user.p('email', '__updatedTest@test.de');
645 671 user.save(function (err) {
646 672 if (err) {
  673 + console.log(err);
647 674 t.ok(false, 'Error while saving user in test for __updated.');
648 675 }
649 676 user.p('name', 'hurgelwurz');
@@ -889,32 +916,6 @@ exports.purgeDB = function (t) {
889 916 });
890 917 };
891 918
892   -exports["integer uniques"] = function (t) {
893   - t.expect(5);
894   - var obj = nohm.factory('UniqueInteger');
895   - var obj2 = nohm.factory('UniqueInteger');
896   - obj.p('unique', 123);
897   - obj2.p('unique', 123);
898   -
899   - obj.save(function (err) {
900   - t.ok(!err, 'Unexpected saving error');
901   - t.same(obj.allProperties(), {
902   - unique: 123,
903   - id: obj.id
904   - }, 'Properties not correct');
905   - obj2.save(function (err) {
906   - t.same(err, 'invalid', 'Unique integer conflict did not result in error.');
907   - obj.remove(function (err) {
908   - t.ok(!err, 'Unexpected removing error');
909   - obj2.save(function () {
910   - t.ok(!err, 'Unexpected saving error');
911   - t.done();
912   - });
913   - });
914   - });
915   - });
916   -};
917   -
918 919 exports["no key left behind"] = function (t) {
919 920 var user = nohm.factory('UserMockup');
920 921 var user2 = nohm.factory('UserMockup');
@@ -956,3 +957,29 @@ exports["no key left behind"] = function (t) {
956 957 }
957 958 );
958 959 };
  960 +
  961 +exports["changing unique frees old unique with uppercase values"] = function (t) {
  962 + t.expect(3);
  963 + var obj = nohm.factory('UserMockup');
  964 + var obj2 = nohm.factory('UserMockup');
  965 + var obj3 = nohm.factory('UserMockup');
  966 + var old = "Changing Unique Property Frees The Value";
  967 + obj.p('name', old);
  968 +
  969 + obj.save(function (err) {
  970 + t.ok(!err, 'Unexpected saving error');
  971 + obj2.load(obj.id, function () {
  972 + obj2.p('name', "changing unique property frees the value to something else")
  973 + obj2.save(function (err) {
  974 + t.ok(!err, 'Unexpected saving error');
  975 + obj3.load(obj.id, function () {
  976 + obj2.p('name', old);
  977 + obj2.save(function (err) {
  978 + t.ok(!err, 'Unexpected saving error. (May be because old uniques are not freed properly on chnage.');
  979 + t.done();
  980 + });
  981 + });
  982 + });
  983 + });
  984 + });
  985 +};
4 test/pubsub/child.js
@@ -3,7 +3,9 @@ var nohm = require(__dirname+'/../../lib/nohm').Nohm;
3 3 var args = require(__dirname+'/../testArgs.js');
4 4
5 5 nohm.setPrefix(args.prefix);
6   -nohm.setClient(args.redis);
  6 +args.redis.on('ready', function () {
  7 + nohm.setClient(args.redis);
  8 +});
7 9 require(__dirname+'/Model.js');
8 10
9 11 process.on('message', function (msg) {
2  test/pubsubTests.js
@@ -44,7 +44,7 @@ module.exports = {
44 44 nohm.setPubSubClient(secondaryClient, function (err) {
45 45 t.ok(!err, 'There was an error while subscribing');
46 46 t.same(nohm.getPubSubClient(), secondaryClient, 'Second redis client wasn\'t set properly');
47   - t.ok(nohm.getPubSubClient().subscriptions, 'Second redis client isn\'t subscribed to anything');
  47 + t.ok(nohm.getPubSubClient().subscription_set, 'Second redis client isn\'t subscribed to anything');
48 48 t.done();
49 49 });
50 50 },

0 comments on commit fbc826a

Please sign in to comment.
Something went wrong with that request. Please try again.