bookshelf-modelbase
Advanced tools
Comparing version 2.2.0 to 2.2.1
@@ -14,5 +14,5 @@ var extend = require('xtend') | ||
// id might be number or string, for optimization | ||
id: Joi.any(), | ||
created_at: Joi.date().iso(), | ||
updated_at: Joi.date().iso() | ||
id: Joi.any().optional(), | ||
created_at: Joi.date().optional(), | ||
updated_at: Joi.date().optional() | ||
} | ||
@@ -87,5 +87,3 @@ | ||
.then(function (model) { | ||
if (model) { | ||
return model.save(data, options) | ||
} | ||
return model ? model.save(data, options) : undefined | ||
}) | ||
@@ -92,0 +90,0 @@ }, |
{ | ||
"name": "bookshelf-modelbase", | ||
"version": "2.2.0", | ||
"version": "2.2.1", | ||
"description": "Extensible ModelBase for bookshelf-based model layers", | ||
@@ -20,3 +20,2 @@ "main": "./lib", | ||
"dependencies": { | ||
"bluebird": "^2.3.11", | ||
"bookshelf": "^0.7.9", | ||
@@ -27,2 +26,3 @@ "joi": "^5.0.2", | ||
"devDependencies": { | ||
"bluebird": "^2.10.0", | ||
"chai": "^1.10.0", | ||
@@ -34,4 +34,4 @@ "istanbul": "^0.3.5", | ||
"sqlite3": "^3.0.4", | ||
"standard": "^5.2.1" | ||
"standard": "5.0.2" | ||
} | ||
} |
@@ -22,3 +22,3 @@ /* global describe, before, beforeEach, it */ | ||
validate: { | ||
name: Joi.string().valid('hello', 'goodbye') | ||
name: Joi.string().valid('hello', 'goodbye', 'yo') | ||
} | ||
@@ -49,2 +49,20 @@ }) | ||
describe('validateSave', function () { | ||
it('should allow extended Joi object', function () { | ||
SpecimenClass = ModelBase.extend({ | ||
tableName: 'test_table', | ||
validate: Joi.object().keys({ | ||
name: Joi.string().valid('hello', 'goodbye') | ||
}) | ||
}) | ||
specimen = new SpecimenClass({ | ||
name: 'hello' | ||
}) | ||
return specimen.save() | ||
.then(function (model) { | ||
expect(model).to.exist() | ||
}) | ||
}) | ||
it('should validate own attributes', function () { | ||
@@ -95,3 +113,3 @@ return expect(specimen.validateSave()).to.contain({ | ||
.then(function (model) { | ||
return expect(model.id).to.not.eql(specimen.id) | ||
expect(model.id).to.not.eql(specimen.id) | ||
}) | ||
@@ -103,18 +121,23 @@ }) | ||
it('should return a model', function () { | ||
return SpecimenClass.forge({ | ||
expect(specimen.get('name')).to.not.eql('goodbye') | ||
return SpecimenClass.update({ | ||
name: 'goodbye' | ||
}, { id: specimen.id }) | ||
.save() | ||
.bind({}) | ||
}, { | ||
id: specimen.get('id') | ||
}) | ||
.then(function (model) { | ||
this.modelId = model.id | ||
return SpecimenClass.update({ | ||
name: 'hello' | ||
}, { id: this.modelId }) | ||
expect(model.get('id')).to.eql(specimen.get('id')) | ||
expect(model.get('name')).to.eql('goodbye') | ||
}) | ||
.then(function () { | ||
return SpecimenClass.findOne({ id: this.modelId }) | ||
}) | ||
it('should return if require:false and not found', function () { | ||
return SpecimenClass.update({ | ||
name: 'goodbye' | ||
}, { | ||
id: -1, | ||
require: false | ||
}) | ||
.then(function (model) { | ||
return expect(model.get('name')).to.eql('hello') | ||
expect(model).to.eql(undefined) | ||
}) | ||
@@ -144,5 +167,5 @@ }) | ||
it('should find an existing model', function () { | ||
return SpecimenClass.findOrCreate() | ||
return SpecimenClass.findOrCreate({ id: specimen.id }) | ||
.then(function (model) { | ||
expect(model).to.be.instanceof(SpecimenClass) | ||
return expect(model.id).to.eql(specimen.id) | ||
}) | ||
@@ -153,3 +176,3 @@ }) | ||
return SpecimenClass.findOrCreate({ | ||
name: 'goodbye' | ||
name: 'yo' | ||
}) | ||
@@ -156,0 +179,0 @@ .then(function (model) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16287
3
289
8
- Removedbluebird@^2.3.11