Permalink
Browse files

Jslinize if blocks, not strict equal for ids on uniqueness checking

  • Loading branch information...
1602 committed Apr 18, 2012
1 parent 221c3d4 commit 1b83266fd6d24cdb253f39c20609e9e07b626615
Showing with 34 additions and 13 deletions.
  1. +1 −0 index.js
  2. +20 −7 lib/adapters/mongoose.js
  3. +1 −1 lib/adapters/postgres.js
  4. +5 −2 lib/hookable.js
  5. +1 −1 lib/validatable.js
  6. +2 −2 test/common_test.js
  7. +4 −0 test/spec_helper.js
View
@@ -18,3 +18,4 @@ try {
exports.version = require('../package').version;
}
} catch (e) {}
+
View
@@ -67,7 +67,9 @@ MongooseAdapter.prototype.getCached = function (model, id, cb) {
cb(null, this.cache[model][id]);
} else {
this._models[model].findById(id, function (err, instance) {
- if (err) return cb(err);
+ if (err) {
+ return cb(err);
+ }
this.cache[model][id] = instance;
cb(null, instance);
}.bind(this));
@@ -83,7 +85,9 @@ MongooseAdapter.prototype.create = function (model, data, callback) {
MongooseAdapter.prototype.save = function (model, data, callback) {
this.getCached(model, data.id, function (err, inst) {
- if (err) return callback(err);
+ if (err) {
+ return callback(err);
+ }
merge(inst, data);
inst.save(callback);
});
@@ -92,24 +96,33 @@ MongooseAdapter.prototype.save = function (model, data, callback) {
MongooseAdapter.prototype.exists = function (model, id, callback) {
delete this.cache[model][id];
this.getCached(model, id, function (err, data) {
- if (err) return callback(err);
+ if (err) {
+ return callback(err);
+ }
callback(err, !!data);
});
};
MongooseAdapter.prototype.find = function find(model, id, callback) {
delete this.cache[model][id];
this.getCached(model, id, function (err, data) {
- if (err) return callback(err);
+ if (err) {
+ return callback(err);
+ }
callback(err, data ? data.toObject() : null);
});
};
MongooseAdapter.prototype.destroy = function destroy(model, id, callback) {
this.getCached(model, id, function (err, data) {
- if (err) return callback(err);
- if (data) data.remove(callback);
- else callback(null);
+ if (err) {
+ return callback(err);
+ }
+ if (data) {
+ data.remove(callback);
+ } else {
+ callback(null);
+ }
});
};
View
@@ -196,7 +196,7 @@ PG.prototype.fromDatabase = function (model, data) {
};
PG.prototype.escapeName = function (name) {
- return '"' + name + '"';
+ return '"' + name.replace(/\./g, '"."') + '"';
};
PG.prototype.all = function all(model, filter, callback) {
View
@@ -38,8 +38,11 @@ Hookable.prototype.trigger = function trigger(actionName, work, data) {
}
function next(done) {
- if (afterHook) afterHook.call(inst, done);
- else if (done) done.call(this);
+ if (afterHook) {
+ afterHook.call(inst, done);
+ } else if (done) {
+ done.call(this);
+ }
}
};
View
@@ -257,7 +257,7 @@ function validateUniqueness(attr, conf, err, done) {
this.constructor.all(cond, function (error, found) {
if (found.length > 1) {
err();
- } else if (found.length === 1 && found[0].id !== this.id) {
+ } else if (found.length === 1 && found[0].id != this.id) {
err();
}
done();
View
@@ -1,8 +1,8 @@
+require('./spec_helper').init(exports);
+
var Schema = require('../index').Schema;
var Text = Schema.Text;
-require('./spec_helper').init(exports);
-
var schemas = {
// riak: {},
mysql: {
View
@@ -1,3 +1,7 @@
+var semicov = require('semicov');
+semicov.init('lib');
+process.on('exit', semicov.report);
+
try {
global.sinon = require('sinon');
} catch (e) {

0 comments on commit 1b83266

Please sign in to comment.