Fix formatting
This commit is contained in:
parent
724fd7d99c
commit
2df5b726b1
|
@ -17,7 +17,9 @@ module.exports = RemoteConnector;
|
|||
*/
|
||||
|
||||
function RemoteConnector(settings) {
|
||||
assert(typeof settings === 'object', 'cannot initiaze RemoteConnector without a settings object');
|
||||
assert(typeof settings ===
|
||||
'object',
|
||||
'cannot initiaze RemoteConnector without a settings object');
|
||||
this.client = settings.client;
|
||||
this.adapter = settings.adapter || 'rest';
|
||||
this.protocol = settings.protocol || 'http'
|
||||
|
@ -36,7 +38,8 @@ function RemoteConnector(settings) {
|
|||
}
|
||||
|
||||
// handle mixins in the define() method
|
||||
var DAO = this.DataAccessObject = function() {};
|
||||
var DAO = this.DataAccessObject = function() {
|
||||
};
|
||||
}
|
||||
|
||||
RemoteConnector.prototype.connect = function() {
|
||||
|
@ -44,7 +47,8 @@ RemoteConnector.prototype.connect = function() {
|
|||
}
|
||||
|
||||
RemoteConnector.initialize = function(dataSource, callback) {
|
||||
var connector = dataSource.connector = new RemoteConnector(dataSource.settings);
|
||||
var connector = dataSource.connector =
|
||||
new RemoteConnector(dataSource.settings);
|
||||
connector.connect();
|
||||
callback();
|
||||
}
|
||||
|
@ -54,18 +58,19 @@ RemoteConnector.prototype.define = function(definition) {
|
|||
var remotes = this.remotes;
|
||||
var SharedClass;
|
||||
|
||||
assert(Model.sharedClass, 'cannot attach ' + Model.modelName
|
||||
+ ' to a remote connector without a Model.sharedClass');
|
||||
assert(Model.sharedClass,
|
||||
'cannot attach ' +
|
||||
Model.modelName +
|
||||
' to a remote connector without a Model.sharedClass');
|
||||
|
||||
remotes.addClass(Model.sharedClass);
|
||||
|
||||
Model
|
||||
.sharedClass
|
||||
.methods()
|
||||
.forEach(function(remoteMethod) {
|
||||
Model.sharedClass.methods().forEach(function(remoteMethod) {
|
||||
// TODO(ritch) more elegant way of ignoring a nested shared class
|
||||
if(remoteMethod.name !== 'Change'
|
||||
&& remoteMethod.name !== 'Checkpoint') {
|
||||
if (remoteMethod.name !==
|
||||
'Change' &&
|
||||
remoteMethod.name !==
|
||||
'Checkpoint') {
|
||||
createProxyMethod(Model, remotes, remoteMethod);
|
||||
}
|
||||
});
|
||||
|
@ -87,4 +92,5 @@ function createProxyMethod(Model, remotes, remoteMethod) {
|
|||
}
|
||||
}
|
||||
|
||||
function noop() {}
|
||||
function noop() {
|
||||
}
|
||||
|
|
|
@ -33,7 +33,8 @@ describe('RemoteConnector', function() {
|
|||
var test = this;
|
||||
remoteApp = this.remoteApp = loopback();
|
||||
remoteApp.use(loopback.rest());
|
||||
var ServerModel = this.ServerModel = loopback.PersistedModel.extend('TestModel');
|
||||
var ServerModel = this.ServerModel =
|
||||
loopback.PersistedModel.extend('TestModel');
|
||||
|
||||
remoteApp.model(ServerModel);
|
||||
|
||||
|
|
|
@ -22,7 +22,8 @@ describe('Model Tests', function() {
|
|||
var test = this;
|
||||
|
||||
// setup a model / datasource
|
||||
dataSource = this.dataSource || loopback.createDataSource(options.dataSource);
|
||||
dataSource =
|
||||
this.dataSource || loopback.createDataSource(options.dataSource);
|
||||
|
||||
var extend = PersistedModel.extend;
|
||||
|
||||
|
@ -55,7 +56,8 @@ describe('Model Tests', function() {
|
|||
});
|
||||
|
||||
describe('Model.validatesPresenceOf(properties...)', function() {
|
||||
it("Require a model to include a property to be considered valid", function() {
|
||||
it("Require a model to include a property to be considered valid",
|
||||
function() {
|
||||
User.validatesPresenceOf('first', 'last', 'age');
|
||||
var joe = new User({first: 'joe'});
|
||||
assert(joe.isValid() === false, 'model should not validate');
|
||||
|
@ -65,8 +67,10 @@ describe('Model Tests', function() {
|
|||
});
|
||||
|
||||
describe('Model.validatesLengthOf(property, options)', function() {
|
||||
it("Require a property length to be within a specified range", function() {
|
||||
User.validatesLengthOf('password', {min: 5, message: {min: 'Password is too short'}});
|
||||
it("Require a property length to be within a specified range",
|
||||
function() {
|
||||
User.validatesLengthOf('password',
|
||||
{min: 5, message: {min: 'Password is too short'}});
|
||||
var joe = new User({password: '1234'});
|
||||
assert(joe.isValid() === false, 'model should not be valid');
|
||||
assert(joe.errors.password, 'should have password error');
|
||||
|
@ -74,7 +78,8 @@ describe('Model Tests', function() {
|
|||
});
|
||||
|
||||
describe('Model.validatesInclusionOf(property, options)', function() {
|
||||
it("Require a value for `property` to be in the specified array", function() {
|
||||
it("Require a value for `property` to be in the specified array",
|
||||
function() {
|
||||
User.validatesInclusionOf('gender', {in: ['male', 'female']});
|
||||
var foo = new User({gender: 'bar'});
|
||||
assert(foo.isValid() === false, 'model should not be valid');
|
||||
|
@ -83,8 +88,10 @@ describe('Model Tests', function() {
|
|||
});
|
||||
|
||||
describe('Model.validatesExclusionOf(property, options)', function() {
|
||||
it("Require a value for `property` to not exist in the specified array", function() {
|
||||
User.validatesExclusionOf('domain', {in: ['www', 'billing', 'admin']});
|
||||
it("Require a value for `property` to not exist in the specified array",
|
||||
function() {
|
||||
User.validatesExclusionOf('domain',
|
||||
{in: ['www', 'billing', 'admin']});
|
||||
var foo = new User({domain: 'www'});
|
||||
var bar = new User({domain: 'billing'});
|
||||
var bat = new User({domain: 'admin'});
|
||||
|
@ -98,7 +105,8 @@ describe('Model Tests', function() {
|
|||
});
|
||||
|
||||
describe('Model.validatesNumericalityOf(property, options)', function() {
|
||||
it("Require a value for `property` to be a specific type of `Number`", function() {
|
||||
it("Require a value for `property` to be a specific type of `Number`",
|
||||
function() {
|
||||
User.validatesNumericalityOf('age', {int: true});
|
||||
var joe = new User({age: 10.2});
|
||||
assert(joe.isValid() === false);
|
||||
|
@ -129,7 +137,8 @@ describe('Model Tests', function() {
|
|||
});
|
||||
|
||||
describe('Model.create([data], [callback])', function() {
|
||||
it("Create an instance of Model with given data and save to the attached data source", function(done) {
|
||||
it("Create an instance of Model with given data and save to the attached data source",
|
||||
function(done) {
|
||||
User.create({first: 'Joe', last: 'Bob'}, function(err, user) {
|
||||
assert(user instanceof User);
|
||||
done();
|
||||
|
@ -138,7 +147,8 @@ describe('Model Tests', function() {
|
|||
});
|
||||
|
||||
describe('model.save([options], [callback])', function() {
|
||||
it("Save an instance of a Model to the attached data source", function(done) {
|
||||
it("Save an instance of a Model to the attached data source",
|
||||
function(done) {
|
||||
var joe = new User({first: 'Joe', last: 'Bob'});
|
||||
joe.save(function(err, user) {
|
||||
assert(user.id);
|
||||
|
@ -150,7 +160,8 @@ describe('Model Tests', function() {
|
|||
});
|
||||
|
||||
describe('model.updateAttributes(data, [callback])', function() {
|
||||
it("Save specified attributes to the attached data source", function(done) {
|
||||
it("Save specified attributes to the attached data source",
|
||||
function(done) {
|
||||
User.create({first: 'joe', age: 100}, function(err, user) {
|
||||
assert(!err);
|
||||
assert.equal(user.first, 'joe');
|
||||
|
@ -170,7 +181,8 @@ describe('Model Tests', function() {
|
|||
});
|
||||
|
||||
describe('Model.upsert(data, callback)', function() {
|
||||
it("Update when record with id=data.id found, insert otherwise", function(done) {
|
||||
it("Update when record with id=data.id found, insert otherwise",
|
||||
function(done) {
|
||||
User.upsert({first: 'joe', id: 7}, function(err, user) {
|
||||
assert(!err);
|
||||
assert.equal(user.first, 'joe');
|
||||
|
@ -201,7 +213,8 @@ describe('Model Tests', function() {
|
|||
});
|
||||
|
||||
describe('Model.deleteById(id, [callback])', function() {
|
||||
it("Delete a model instance from the attached data source", function (done) {
|
||||
it("Delete a model instance from the attached data source",
|
||||
function(done) {
|
||||
User.create({first: 'joe', last: 'bob'}, function(err, user) {
|
||||
User.deleteById(user.id, function(err) {
|
||||
User.findById(user.id, function(err, notFound) {
|
||||
|
@ -228,13 +241,15 @@ describe('Model Tests', function() {
|
|||
|
||||
describe('Model.count([query], callback)', function() {
|
||||
it("Query count of Model instances in data source", function(done) {
|
||||
(new TaskEmitter())
|
||||
.task(User, 'create', {first: 'jill', age: 100})
|
||||
.task(User, 'create', {first: 'bob', age: 200})
|
||||
.task(User, 'create', {first: 'jan'})
|
||||
.task(User, 'create', {first: 'sam'})
|
||||
.task(User, 'create', {first: 'suzy'})
|
||||
.on('done', function () {
|
||||
(new TaskEmitter()).task(User,
|
||||
'create',
|
||||
{first: 'jill', age: 100}).task(User,
|
||||
'create',
|
||||
{first: 'bob', age: 200}).task(User,
|
||||
'create',
|
||||
{first: 'jan'}).task(User, 'create', {first: 'sam'}).task(User,
|
||||
'create',
|
||||
{first: 'suzy'}).on('done', function() {
|
||||
User.count({age: {gt: 99}}, function(err, count) {
|
||||
assert.equal(count, 2);
|
||||
done();
|
||||
|
|
Loading…
Reference in New Issue