Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' into meta

Conflicts:
	test/featureTests.js
  • Loading branch information...
commit a4ee319e9ee0ceb12740a441e6854c55d445d70c 2 parents bc216ed + fbc826a
@maritz authored
View
3  lib/store.js
@@ -185,7 +185,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
2  package.json
@@ -2,7 +2,7 @@
"name": "nohm",
"version": "0.9.0",
"engines": {
- "node" : "0.6"
+ "node" : ">=0.6"
},
"author": "Moritz Peters",
"repository" : {
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');
@@ -975,3 +976,29 @@ exports["temporary model definitions"] = function (t) {
t.notDeepEqual(user.allProperties(), new_user.allProperties(), 'HURASDASF');
t.done();
};
+
+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();
+ });
+ });
+ });
+ });
+ });
+};
Please sign in to comment.
Something went wrong with that request. Please try again.