Fix Model.exists() to work with remote connector
This commit is contained in:
parent
ae3fff9e7b
commit
e8d115bdc2
|
@ -724,7 +724,8 @@ module.exports = function(registry) {
|
||||||
description: 'Check whether a model instance exists in the data source.',
|
description: 'Check whether a model instance exists in the data source.',
|
||||||
accessType: 'READ',
|
accessType: 'READ',
|
||||||
accepts: [
|
accepts: [
|
||||||
{arg: 'id', type: 'any', description: 'Model id', required: true},
|
{arg: 'id', type: 'any', description: 'Model id', required: true,
|
||||||
|
http: {source: 'path'}},
|
||||||
{arg: 'options', type: 'object', http: 'optionsFromRequest'},
|
{arg: 'options', type: 'object', http: 'optionsFromRequest'},
|
||||||
],
|
],
|
||||||
returns: {arg: 'exists', type: 'boolean'},
|
returns: {arg: 'exists', type: 'boolean'},
|
||||||
|
|
|
@ -235,6 +235,27 @@ module.exports = function defineModelTestsWithDataSource(options) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Model.exists(id, [callback])', function() {
|
||||||
|
it('returns true when the model with the given id exists', function(done) {
|
||||||
|
User.create({first: 'max'}, function(err, user) {
|
||||||
|
if (err) return done(err);
|
||||||
|
User.exists(user.id, function(err, exist) {
|
||||||
|
if (err) return done(err);
|
||||||
|
assert.equal(exist, true);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns false when there is no model with the given id', function(done) {
|
||||||
|
User.exists('user-id-does-not-exist', function(err, exist) {
|
||||||
|
if (err) return done(err);
|
||||||
|
assert.equal(exist, false);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('Model.findById(id, callback)', function() {
|
describe('Model.findById(id, callback)', function() {
|
||||||
it('Find an instance by id', function(done) {
|
it('Find an instance by id', function(done) {
|
||||||
User.create({first: 'michael', last: 'jordan', id: 23}, function() {
|
User.create({first: 'michael', last: 'jordan', id: 23}, function() {
|
||||||
|
|
Loading…
Reference in New Issue