Skip to content

Commit

Permalink
Jslinize if blocks, not strict equal for ids on uniqueness checking
Browse files Browse the repository at this point in the history
  • Loading branch information
1602 committed Apr 18, 2012
1 parent 221c3d4 commit 1b83266
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 13 deletions.
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ try {
exports.version = require('../package').version;
}
} catch (e) {}

27 changes: 20 additions & 7 deletions lib/adapters/mongoose.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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);
});
Expand All @@ -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);
}
});
};

Expand Down
2 changes: 1 addition & 1 deletion lib/adapters/postgres.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 5 additions & 2 deletions lib/hookable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
};

Expand Down
2 changes: 1 addition & 1 deletion lib/validatable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions test/common_test.js
Original file line number Diff line number Diff line change
@@ -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: {
Expand Down
4 changes: 4 additions & 0 deletions test/spec_helper.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
var semicov = require('semicov');
semicov.init('lib');
process.on('exit', semicov.report);

try {
global.sinon = require('sinon');
} catch (e) {
Expand Down

0 comments on commit 1b83266

Please sign in to comment.