commit
3ba7a5d1e8
|
@ -83,9 +83,10 @@ describe('manipulation', function() {
|
||||||
it('should create instance', function(done) {
|
it('should create instance', function(done) {
|
||||||
Person.create({name: 'Anatoliy'}, function(err, p) {
|
Person.create({name: 'Anatoliy'}, function(err, p) {
|
||||||
p.name.should.equal('Anatoliy');
|
p.name.should.equal('Anatoliy');
|
||||||
should.not.exist(err);
|
if (err) return done(err);
|
||||||
should.exist(p);
|
should.exist(p);
|
||||||
Person.findById(p.id, function(err, person) {
|
Person.findById(p.id, function(err, person) {
|
||||||
|
if (err) return done(err);
|
||||||
person.id.should.eql(p.id);
|
person.id.should.eql(p.id);
|
||||||
person.name.should.equal('Anatoliy');
|
person.name.should.equal('Anatoliy');
|
||||||
done();
|
done();
|
||||||
|
@ -113,7 +114,7 @@ describe('manipulation', function() {
|
||||||
p.name.should.equal('Anatoliy');
|
p.name.should.equal('Anatoliy');
|
||||||
p.isNewRecord().should.be.true;
|
p.isNewRecord().should.be.true;
|
||||||
p.save(function(err, inst) {
|
p.save(function(err, inst) {
|
||||||
should.not.exist(err);
|
if (err) return done(err);
|
||||||
inst.isNewRecord().should.be.false;
|
inst.isNewRecord().should.be.false;
|
||||||
inst.should.equal(p);
|
inst.should.equal(p);
|
||||||
done();
|
done();
|
||||||
|
@ -136,6 +137,7 @@ describe('manipulation', function() {
|
||||||
|
|
||||||
it('should not return instance of object', function(done) {
|
it('should not return instance of object', function(done) {
|
||||||
var person = Person.create(function(err, p) {
|
var person = Person.create(function(err, p) {
|
||||||
|
if (err) return done(err);
|
||||||
should.exist(p.id);
|
should.exist(p.id);
|
||||||
if (person) person.should.not.be.an.instanceOf(Person);
|
if (person) person.should.not.be.an.instanceOf(Person);
|
||||||
done();
|
done();
|
||||||
|
@ -209,10 +211,11 @@ describe('manipulation', function() {
|
||||||
|
|
||||||
it('should create instance with blank data', function(done) {
|
it('should create instance with blank data', function(done) {
|
||||||
Person.create(function(err, p) {
|
Person.create(function(err, p) {
|
||||||
should.not.exist(err);
|
if (err) return done(err);
|
||||||
should.exist(p);
|
should.exist(p);
|
||||||
should.not.exists(p.name);
|
should.not.exists(p.name);
|
||||||
Person.findById(p.id, function(err, person) {
|
Person.findById(p.id, function(err, person) {
|
||||||
|
if (err) return done(err);
|
||||||
person.id.should.eql(p.id);
|
person.id.should.eql(p.id);
|
||||||
should.not.exists(person.name);
|
should.not.exists(person.name);
|
||||||
done();
|
done();
|
||||||
|
@ -350,7 +353,7 @@ describe('manipulation', function() {
|
||||||
it('should save new object', function(done) {
|
it('should save new object', function(done) {
|
||||||
var p = new Person;
|
var p = new Person;
|
||||||
p.save(function(err) {
|
p.save(function(err) {
|
||||||
should.not.exist(err);
|
if (err) return done(err);
|
||||||
should.exist(p.id);
|
should.exist(p.id);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
@ -368,13 +371,13 @@ describe('manipulation', function() {
|
||||||
|
|
||||||
it('should save existing object', function(done) {
|
it('should save existing object', function(done) {
|
||||||
Person.findOne(function(err, p) {
|
Person.findOne(function(err, p) {
|
||||||
should.not.exist(err);
|
if (err) return done(err);
|
||||||
p.name = 'Hans';
|
p.name = 'Hans';
|
||||||
p.save(function(err) {
|
p.save(function(err) {
|
||||||
should.not.exist(err);
|
if (err) return done(err);
|
||||||
p.name.should.equal('Hans');
|
p.name.should.equal('Hans');
|
||||||
Person.findOne(function(err, p) {
|
Person.findOne(function(err, p) {
|
||||||
should.not.exist(err);
|
if (err) return done(err);
|
||||||
p.name.should.equal('Hans');
|
p.name.should.equal('Hans');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
@ -400,7 +403,7 @@ describe('manipulation', function() {
|
||||||
|
|
||||||
it('should save invalid object (skipping validation)', function(done) {
|
it('should save invalid object (skipping validation)', function(done) {
|
||||||
Person.findOne(function(err, p) {
|
Person.findOne(function(err, p) {
|
||||||
should.not.exist(err);
|
if (err) return done(err);
|
||||||
p.isValid = function(done) {
|
p.isValid = function(done) {
|
||||||
process.nextTick(done);
|
process.nextTick(done);
|
||||||
return false;
|
return false;
|
||||||
|
@ -409,7 +412,7 @@ describe('manipulation', function() {
|
||||||
p.save(function(err) {
|
p.save(function(err) {
|
||||||
should.exist(err);
|
should.exist(err);
|
||||||
p.save({validate: false}, function(err) {
|
p.save({validate: false}, function(err) {
|
||||||
should.not.exist(err);
|
if (err) return done(err);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -441,7 +444,7 @@ describe('manipulation', function() {
|
||||||
|
|
||||||
it('should save throw error on validation', function() {
|
it('should save throw error on validation', function() {
|
||||||
Person.findOne(function(err, p) {
|
Person.findOne(function(err, p) {
|
||||||
should.not.exist(err);
|
if (err) return done(err);
|
||||||
p.isValid = function(cb) {
|
p.isValid = function(cb) {
|
||||||
cb(false);
|
cb(false);
|
||||||
return false;
|
return false;
|
||||||
|
@ -548,6 +551,7 @@ describe('manipulation', function() {
|
||||||
function(done) {
|
function(done) {
|
||||||
Person.definition.settings.strict = true;
|
Person.definition.settings.strict = true;
|
||||||
Person.findById(person.id, function(err, p) {
|
Person.findById(person.id, function(err, p) {
|
||||||
|
if (err) return done(err);
|
||||||
p.updateAttributes({name: 'John', unknownVar: undefined},
|
p.updateAttributes({name: 'John', unknownVar: undefined},
|
||||||
function(err, p) {
|
function(err, p) {
|
||||||
// if uknownVar was defined, it would return validationError
|
// if uknownVar was defined, it would return validationError
|
||||||
|
@ -566,6 +570,7 @@ describe('manipulation', function() {
|
||||||
function(done) {
|
function(done) {
|
||||||
Person.definition.settings.strict = false;
|
Person.definition.settings.strict = false;
|
||||||
Person.findById(person.id, function(err, p) {
|
Person.findById(person.id, function(err, p) {
|
||||||
|
if (err) return done(err);
|
||||||
p.updateAttributes({name: 'John', foo: 'bar'},
|
p.updateAttributes({name: 'John', foo: 'bar'},
|
||||||
function(err, p) {
|
function(err, p) {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
|
@ -584,6 +589,7 @@ describe('manipulation', function() {
|
||||||
// changes to '{}' and breaks other tests
|
// changes to '{}' and breaks other tests
|
||||||
Person.definition.settings.strict = true;
|
Person.definition.settings.strict = true;
|
||||||
Person.findById(person.id, function(err, p) {
|
Person.findById(person.id, function(err, p) {
|
||||||
|
if (err) return done(err);
|
||||||
p.updateAttributes({name: 'John', foo: 'bar'},
|
p.updateAttributes({name: 'John', foo: 'bar'},
|
||||||
function(err, p) {
|
function(err, p) {
|
||||||
should.exist(err);
|
should.exist(err);
|
||||||
|
@ -604,6 +610,7 @@ describe('manipulation', function() {
|
||||||
it('should fallback to strict:true when using strict: throw', function(done) {
|
it('should fallback to strict:true when using strict: throw', function(done) {
|
||||||
Person.definition.settings.strict = 'throw';
|
Person.definition.settings.strict = 'throw';
|
||||||
Person.findById(person.id, function(err, p) {
|
Person.findById(person.id, function(err, p) {
|
||||||
|
if (err) return done(err);
|
||||||
p.updateAttributes({foo: 'bar'},
|
p.updateAttributes({foo: 'bar'},
|
||||||
function(err, p) {
|
function(err, p) {
|
||||||
should.exist(err);
|
should.exist(err);
|
||||||
|
@ -623,6 +630,7 @@ describe('manipulation', function() {
|
||||||
it('should fallback to strict:true when using strict:validate', function(done) {
|
it('should fallback to strict:true when using strict:validate', function(done) {
|
||||||
Person.definition.settings.strict = 'validate';
|
Person.definition.settings.strict = 'validate';
|
||||||
Person.findById(person.id, function(err, p) {
|
Person.findById(person.id, function(err, p) {
|
||||||
|
if (err) return done(err);
|
||||||
p.updateAttributes({foo: 'bar'},
|
p.updateAttributes({foo: 'bar'},
|
||||||
function(err, p) {
|
function(err, p) {
|
||||||
should.exist(err);
|
should.exist(err);
|
||||||
|
@ -1356,9 +1364,11 @@ describe('manipulation', function() {
|
||||||
|
|
||||||
it('should destroy record', function(done) {
|
it('should destroy record', function(done) {
|
||||||
Person.create(function(err, p) {
|
Person.create(function(err, p) {
|
||||||
|
if (err) return done(err);
|
||||||
p.destroy(function(err) {
|
p.destroy(function(err) {
|
||||||
should.not.exist(err);
|
if (err) return done(err);
|
||||||
Person.exists(p.id, function(err, ex) {
|
Person.exists(p.id, function(err, ex) {
|
||||||
|
if (err) return done(err);
|
||||||
ex.should.not.be.ok;
|
ex.should.not.be.ok;
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
@ -1383,10 +1393,12 @@ describe('manipulation', function() {
|
||||||
|
|
||||||
it('should destroy all records', function(done) {
|
it('should destroy all records', function(done) {
|
||||||
Person.destroyAll(function(err) {
|
Person.destroyAll(function(err) {
|
||||||
should.not.exist(err);
|
if (err) return done(err);
|
||||||
Person.all(function(err, posts) {
|
Person.all(function(err, posts) {
|
||||||
|
if (err) return done(err);
|
||||||
posts.should.have.lengthOf(0);
|
posts.should.have.lengthOf(0);
|
||||||
Person.count(function(err, count) {
|
Person.count(function(err, count) {
|
||||||
|
if (err) return done(err);
|
||||||
count.should.eql(0);
|
count.should.eql(0);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
@ -1525,6 +1537,7 @@ describe('manipulation', function() {
|
||||||
|
|
||||||
it('should allow delete(id) - success', function(done) {
|
it('should allow delete(id) - success', function(done) {
|
||||||
Person.findOne(function(e, p) {
|
Person.findOne(function(e, p) {
|
||||||
|
if (e) return done(e);
|
||||||
p.delete(function(err, info) {
|
p.delete(function(err, info) {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
info.should.have.property('count', 1);
|
info.should.have.property('count', 1);
|
||||||
|
@ -1536,6 +1549,7 @@ describe('manipulation', function() {
|
||||||
it('should allow delete(id) - fail', function(done) {
|
it('should allow delete(id) - fail', function(done) {
|
||||||
Person.settings.strictDelete = false;
|
Person.settings.strictDelete = false;
|
||||||
Person.findOne(function(e, p) {
|
Person.findOne(function(e, p) {
|
||||||
|
if (e) return done(e);
|
||||||
p.delete(function(err, info) {
|
p.delete(function(err, info) {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
info.should.have.property('count', 1);
|
info.should.have.property('count', 1);
|
||||||
|
@ -1550,7 +1564,8 @@ describe('manipulation', function() {
|
||||||
|
|
||||||
it('should allow delete(id) - fail with error', function(done) {
|
it('should allow delete(id) - fail with error', function(done) {
|
||||||
Person.settings.strictDelete = true;
|
Person.settings.strictDelete = true;
|
||||||
Person.findOne(function(e, u) {
|
Person.findOne(function(err, u) {
|
||||||
|
if (err) return done(err);
|
||||||
u.delete(function(err, info) {
|
u.delete(function(err, info) {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
info.should.have.property('count', 1);
|
info.should.have.property('count', 1);
|
||||||
|
@ -1592,10 +1607,10 @@ describe('manipulation', function() {
|
||||||
function(done) {
|
function(done) {
|
||||||
var now = Date.now();
|
var now = Date.now();
|
||||||
|
|
||||||
var myCustomModel = CustomModel.create(function(err, m) {
|
CustomModel.create(function(err, model) {
|
||||||
should.not.exists(err);
|
should.not.exists(err);
|
||||||
m.createdAt.should.be.instanceOf(Date);
|
model.createdAt.should.be.instanceOf(Date);
|
||||||
(m.createdAt >= now).should.be.true;
|
(model.createdAt >= now).should.be.true;
|
||||||
});
|
});
|
||||||
|
|
||||||
done();
|
done();
|
||||||
|
@ -1614,10 +1629,10 @@ describe('manipulation', function() {
|
||||||
|
|
||||||
it('should report \'$now\' as default value for string property',
|
it('should report \'$now\' as default value for string property',
|
||||||
function(done) {
|
function(done) {
|
||||||
var myCustomModel = CustomModel.create(function(err, m) {
|
CustomModel.create(function(err, model) {
|
||||||
should.not.exists(err);
|
if (err) return done(err);
|
||||||
m.now.should.be.instanceOf(String);
|
model.now.should.be.instanceOf(String);
|
||||||
m.now.should.equal('$now');
|
model.now.should.equal('$now');
|
||||||
});
|
});
|
||||||
|
|
||||||
done();
|
done();
|
||||||
|
@ -1637,10 +1652,10 @@ describe('manipulation', function() {
|
||||||
it('should generate current time when "defaultFn" is "now"',
|
it('should generate current time when "defaultFn" is "now"',
|
||||||
function(done) {
|
function(done) {
|
||||||
var now = Date.now();
|
var now = Date.now();
|
||||||
var inst = CustomModel.create(function(err, m) {
|
CustomModel.create(function(err, model) {
|
||||||
should.not.exists(err);
|
if (err) return done(err);
|
||||||
m.now.should.be.instanceOf(Date);
|
model.now.should.be.instanceOf(Date);
|
||||||
m.now.should.be.within(now, now + 200);
|
model.now.should.be.within(now, now + 200);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1657,9 +1672,9 @@ describe('manipulation', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should generate a new id when "defaultFn" is "guid"', function(done) {
|
it('should generate a new id when "defaultFn" is "guid"', function(done) {
|
||||||
var inst = CustomModel.create(function(err, m) {
|
CustomModel.create(function(err, model) {
|
||||||
should.not.exists(err);
|
if (err) return done(err);
|
||||||
m.guid.should.match(UUID_REGEXP);
|
model.guid.should.match(UUID_REGEXP);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1676,9 +1691,9 @@ describe('manipulation', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should generate a new id when "defaultfn" is "uuid"', function(done) {
|
it('should generate a new id when "defaultfn" is "uuid"', function(done) {
|
||||||
var inst = CustomModel.create(function(err, m) {
|
CustomModel.create(function(err, model) {
|
||||||
should.not.exists(err);
|
if (err) return done(err);
|
||||||
m.guid.should.match(UUID_REGEXP);
|
model.guid.should.match(UUID_REGEXP);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1695,9 +1710,9 @@ describe('manipulation', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should generate a new id when "defaultfn" is "uuidv4"', function(done) {
|
it('should generate a new id when "defaultfn" is "uuidv4"', function(done) {
|
||||||
var inst = CustomModel.create(function(err, m) {
|
CustomModel.create(function(err, model) {
|
||||||
should.not.exists(err);
|
should.not.exists(err);
|
||||||
m.guid.should.match(UUID_REGEXP);
|
model.guid.should.match(UUID_REGEXP);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -48,7 +48,7 @@ describe('scope', function() {
|
||||||
Station.scope('active', {where: {isActive: true}});
|
Station.scope('active', {where: {isActive: true}});
|
||||||
Station.scopes.should.have.property('active');
|
Station.scopes.should.have.property('active');
|
||||||
Station.active.create(function(err, station) {
|
Station.active.create(function(err, station) {
|
||||||
should.not.exist(err);
|
if (err) return done(err);
|
||||||
should.exist(station);
|
should.exist(station);
|
||||||
should.exist(station.isActive);
|
should.exist(station.isActive);
|
||||||
station.isActive.should.be.true;
|
station.isActive.should.be.true;
|
||||||
|
@ -60,7 +60,7 @@ describe('scope', function() {
|
||||||
Station.scope('active', {where: {isActive: true}});
|
Station.scope('active', {where: {isActive: true}});
|
||||||
Station.scope('subway', {where: {isUndeground: true}});
|
Station.scope('subway', {where: {isUndeground: true}});
|
||||||
Station.active.subway.create(function(err, station) {
|
Station.active.subway.create(function(err, station) {
|
||||||
should.not.exist(err);
|
if (err) return done(err);
|
||||||
should.exist(station);
|
should.exist(station);
|
||||||
station.isActive.should.be.true;
|
station.isActive.should.be.true;
|
||||||
station.isUndeground.should.be.true;
|
station.isUndeground.should.be.true;
|
||||||
|
@ -75,6 +75,7 @@ describe('scope', function() {
|
||||||
Station.active.ground.create(function() {
|
Station.active.ground.create(function() {
|
||||||
Station.inactive.ground.create(function() {
|
Station.inactive.ground.create(function() {
|
||||||
Station.ground.inactive(function(err, ss) {
|
Station.ground.inactive(function(err, ss) {
|
||||||
|
if (err) return done(err);
|
||||||
ss.should.have.lengthOf(1);
|
ss.should.have.lengthOf(1);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
@ -135,6 +136,7 @@ describe('scope - order', function() {
|
||||||
|
|
||||||
it('should define scope with default order', function(done) {
|
it('should define scope with default order', function(done) {
|
||||||
Station.reverse(function(err, stations) {
|
Station.reverse(function(err, stations) {
|
||||||
|
if (err) return done(err);
|
||||||
stations[0].name.should.equal('c');
|
stations[0].name.should.equal('c');
|
||||||
stations[0].order.should.equal(3);
|
stations[0].order.should.equal(3);
|
||||||
stations[1].name.should.equal('b');
|
stations[1].name.should.equal('b');
|
||||||
|
@ -147,6 +149,7 @@ describe('scope - order', function() {
|
||||||
|
|
||||||
it('should override default scope order', function(done) {
|
it('should override default scope order', function(done) {
|
||||||
Station.reverse({order: 'order ASC'}, function(err, stations) {
|
Station.reverse({order: 'order ASC'}, function(err, stations) {
|
||||||
|
if (err) return done(err);
|
||||||
stations[0].name.should.equal('a');
|
stations[0].name.should.equal('a');
|
||||||
stations[0].order.should.equal(1);
|
stations[0].order.should.equal(1);
|
||||||
stations[1].name.should.equal('b');
|
stations[1].name.should.equal('b');
|
||||||
|
@ -187,6 +190,7 @@ describe('scope - filtered count, updateAll and destroyAll', function() {
|
||||||
|
|
||||||
beforeEach(function(done) {
|
beforeEach(function(done) {
|
||||||
Station.create({name: 'a', order: 1}, function(err, inst) {
|
Station.create({name: 'a', order: 1}, function(err, inst) {
|
||||||
|
if (err) return done(err);
|
||||||
stationA = inst;
|
stationA = inst;
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
@ -202,7 +206,7 @@ describe('scope - filtered count, updateAll and destroyAll', function() {
|
||||||
|
|
||||||
it('should find all - verify', function(done) {
|
it('should find all - verify', function(done) {
|
||||||
Station.ordered(function(err, stations) {
|
Station.ordered(function(err, stations) {
|
||||||
should.not.exist(err);
|
if (err) return done(err);
|
||||||
stations.should.have.length(4);
|
stations.should.have.length(4);
|
||||||
stations[0].name.should.equal('a');
|
stations[0].name.should.equal('a');
|
||||||
stations[1].name.should.equal('b');
|
stations[1].name.should.equal('b');
|
||||||
|
@ -214,7 +218,7 @@ describe('scope - filtered count, updateAll and destroyAll', function() {
|
||||||
|
|
||||||
it('should find one', function(done) {
|
it('should find one', function(done) {
|
||||||
Station.active.findOne(function(err, station) {
|
Station.active.findOne(function(err, station) {
|
||||||
should.not.exist(err);
|
if (err) return done(err);
|
||||||
station.name.should.equal('a');
|
station.name.should.equal('a');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
@ -222,7 +226,7 @@ describe('scope - filtered count, updateAll and destroyAll', function() {
|
||||||
|
|
||||||
it('should find one - with filter', function(done) {
|
it('should find one - with filter', function(done) {
|
||||||
Station.active.findOne({where: {name: 'c'}}, function(err, station) {
|
Station.active.findOne({where: {name: 'c'}}, function(err, station) {
|
||||||
should.not.exist(err);
|
if (err) return done(err);
|
||||||
station.name.should.equal('c');
|
station.name.should.equal('c');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
@ -230,7 +234,7 @@ describe('scope - filtered count, updateAll and destroyAll', function() {
|
||||||
|
|
||||||
it('should find by id - match', function(done) {
|
it('should find by id - match', function(done) {
|
||||||
Station.active.findById(stationA.id, function(err, station) {
|
Station.active.findById(stationA.id, function(err, station) {
|
||||||
should.not.exist(err);
|
if (err) return done(err);
|
||||||
station.name.should.equal('a');
|
station.name.should.equal('a');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
@ -238,7 +242,7 @@ describe('scope - filtered count, updateAll and destroyAll', function() {
|
||||||
|
|
||||||
it('should find by id - no match', function(done) {
|
it('should find by id - no match', function(done) {
|
||||||
Station.inactive.findById(stationA.id, function(err, station) {
|
Station.inactive.findById(stationA.id, function(err, station) {
|
||||||
should.not.exist(err);
|
if (err) return done(err);
|
||||||
should.not.exist(station);
|
should.not.exist(station);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
@ -246,7 +250,7 @@ describe('scope - filtered count, updateAll and destroyAll', function() {
|
||||||
|
|
||||||
it('should count all in scope - active', function(done) {
|
it('should count all in scope - active', function(done) {
|
||||||
Station.active.count(function(err, count) {
|
Station.active.count(function(err, count) {
|
||||||
should.not.exist(err);
|
if (err) return done(err);
|
||||||
count.should.equal(2);
|
count.should.equal(2);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
@ -254,7 +258,7 @@ describe('scope - filtered count, updateAll and destroyAll', function() {
|
||||||
|
|
||||||
it('should count all in scope - inactive', function(done) {
|
it('should count all in scope - inactive', function(done) {
|
||||||
Station.inactive.count(function(err, count) {
|
Station.inactive.count(function(err, count) {
|
||||||
should.not.exist(err);
|
if (err) return done(err);
|
||||||
count.should.equal(2);
|
count.should.equal(2);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
@ -262,7 +266,7 @@ describe('scope - filtered count, updateAll and destroyAll', function() {
|
||||||
|
|
||||||
it('should count filtered - active', function(done) {
|
it('should count filtered - active', function(done) {
|
||||||
Station.active.count({order: {gt: 1}}, function(err, count) {
|
Station.active.count({order: {gt: 1}}, function(err, count) {
|
||||||
should.not.exist(err);
|
if (err) return done(err);
|
||||||
count.should.equal(1);
|
count.should.equal(1);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
@ -270,7 +274,7 @@ describe('scope - filtered count, updateAll and destroyAll', function() {
|
||||||
|
|
||||||
it('should count filtered - inactive', function(done) {
|
it('should count filtered - inactive', function(done) {
|
||||||
Station.inactive.count({order: 2}, function(err, count) {
|
Station.inactive.count({order: 2}, function(err, count) {
|
||||||
should.not.exist(err);
|
if (err) return done(err);
|
||||||
count.should.equal(1);
|
count.should.equal(1);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
@ -278,14 +282,14 @@ describe('scope - filtered count, updateAll and destroyAll', function() {
|
||||||
|
|
||||||
it('should allow updateAll', function(done) {
|
it('should allow updateAll', function(done) {
|
||||||
Station.inactive.updateAll({flagged: true}, function(err, result) {
|
Station.inactive.updateAll({flagged: true}, function(err, result) {
|
||||||
should.not.exist(err);
|
if (err) return done(err);
|
||||||
result.count.should.equal(2);
|
result.count.should.equal(2);
|
||||||
verify();
|
verify();
|
||||||
});
|
});
|
||||||
|
|
||||||
var verify = function() {
|
var verify = function() {
|
||||||
Station.flagged.count(function(err, count) {
|
Station.flagged.count(function(err, count) {
|
||||||
should.not.exist(err);
|
if (err) return done(err);
|
||||||
count.should.equal(2);
|
count.should.equal(2);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
@ -294,14 +298,14 @@ describe('scope - filtered count, updateAll and destroyAll', function() {
|
||||||
|
|
||||||
it('should allow filtered updateAll', function(done) {
|
it('should allow filtered updateAll', function(done) {
|
||||||
Station.ordered.updateAll({active: true}, {flagged: true}, function(err, result) {
|
Station.ordered.updateAll({active: true}, {flagged: true}, function(err, result) {
|
||||||
should.not.exist(err);
|
if (err) return done(err);
|
||||||
result.count.should.equal(2);
|
result.count.should.equal(2);
|
||||||
verify();
|
verify();
|
||||||
});
|
});
|
||||||
|
|
||||||
var verify = function() {
|
var verify = function() {
|
||||||
Station.flagged.count(function(err, count) {
|
Station.flagged.count(function(err, count) {
|
||||||
should.not.exist(err);
|
if (err) return done(err);
|
||||||
count.should.equal(2);
|
count.should.equal(2);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
@ -310,16 +314,16 @@ describe('scope - filtered count, updateAll and destroyAll', function() {
|
||||||
|
|
||||||
it('should allow filtered destroyAll', function(done) {
|
it('should allow filtered destroyAll', function(done) {
|
||||||
Station.ordered.destroyAll({active: false}, function(err) {
|
Station.ordered.destroyAll({active: false}, function(err) {
|
||||||
should.not.exist(err);
|
if (err) return done(err);
|
||||||
verify();
|
verify();
|
||||||
});
|
});
|
||||||
|
|
||||||
var verify = function() {
|
var verify = function() {
|
||||||
Station.ordered.count(function(err, count) {
|
Station.ordered.count(function(err, count) {
|
||||||
should.not.exist(err);
|
if (err) return done(err);
|
||||||
count.should.equal(2);
|
count.should.equal(2);
|
||||||
Station.inactive.count(function(err, count) {
|
Station.inactive.count(function(err, count) {
|
||||||
should.not.exist(err);
|
if (err) return done(err);
|
||||||
count.should.equal(0);
|
count.should.equal(0);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
@ -330,7 +334,7 @@ describe('scope - filtered count, updateAll and destroyAll', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('scope - dynamic target class', function() {
|
describe('scope - dynamic target class', function() {
|
||||||
var Collection, Media, Image, Video;
|
var Collection, Image, Video;
|
||||||
|
|
||||||
before(function() {
|
before(function() {
|
||||||
db = getSchema();
|
db = getSchema();
|
||||||
|
@ -375,10 +379,10 @@ describe('scope - dynamic target class', function() {
|
||||||
|
|
||||||
it('should deduce modelTo at runtime - Image', function(done) {
|
it('should deduce modelTo at runtime - Image', function(done) {
|
||||||
Collection.findOne({where: {modelName: 'Image'}}, function(err, coll) {
|
Collection.findOne({where: {modelName: 'Image'}}, function(err, coll) {
|
||||||
should.not.exist(err);
|
if (err) return done(err);
|
||||||
coll.name.should.equal('Images');
|
coll.name.should.equal('Images');
|
||||||
coll.items(function(err, items) {
|
coll.items(function(err, items) {
|
||||||
should.not.exist(err);
|
if (err) return done(err);
|
||||||
items.length.should.equal(1);
|
items.length.should.equal(1);
|
||||||
items[0].name.should.equal('Image A');
|
items[0].name.should.equal('Image A');
|
||||||
items[0].should.be.instanceof(Image);
|
items[0].should.be.instanceof(Image);
|
||||||
|
@ -389,10 +393,10 @@ describe('scope - dynamic target class', function() {
|
||||||
|
|
||||||
it('should deduce modelTo at runtime - Video', function(done) {
|
it('should deduce modelTo at runtime - Video', function(done) {
|
||||||
Collection.findOne({where: {modelName: 'Video'}}, function(err, coll) {
|
Collection.findOne({where: {modelName: 'Video'}}, function(err, coll) {
|
||||||
should.not.exist(err);
|
if (err) return done(err);
|
||||||
coll.name.should.equal('Videos');
|
coll.name.should.equal('Videos');
|
||||||
coll.items(function(err, items) {
|
coll.items(function(err, items) {
|
||||||
should.not.exist(err);
|
if (err) return done(err);
|
||||||
items.length.should.equal(1);
|
items.length.should.equal(1);
|
||||||
items[0].name.should.equal('Video A');
|
items[0].name.should.equal('Video A');
|
||||||
items[0].should.be.instanceof(Video);
|
items[0].should.be.instanceof(Video);
|
||||||
|
@ -403,7 +407,7 @@ describe('scope - dynamic target class', function() {
|
||||||
|
|
||||||
it('should throw if modelTo is invalid', function(done) {
|
it('should throw if modelTo is invalid', function(done) {
|
||||||
Collection.findOne({where: {name: 'Things'}}, function(err, coll) {
|
Collection.findOne({where: {name: 'Things'}}, function(err, coll) {
|
||||||
should.not.exist(err);
|
if (err) return done(err);
|
||||||
coll.modelName.should.equal('Unknown');
|
coll.modelName.should.equal('Unknown');
|
||||||
(function() {
|
(function() {
|
||||||
coll.items(function(err, items) {});
|
coll.items(function(err, items) {});
|
||||||
|
@ -435,10 +439,10 @@ describe('scope - dynamic function', function() {
|
||||||
|
|
||||||
it('should deduce item by runtime creator', function(done) {
|
it('should deduce item by runtime creator', function(done) {
|
||||||
Item.dynamicQuery.findOne(function(err, firstQuery) {
|
Item.dynamicQuery.findOne(function(err, firstQuery) {
|
||||||
should.not.exist(err);
|
if (err) return done(err);
|
||||||
firstQuery.title.should.equal(1);
|
firstQuery.title.should.equal(1);
|
||||||
Item.dynamicQuery.findOne(function(err, secondQuery) {
|
Item.dynamicQuery.findOne(function(err, secondQuery) {
|
||||||
should.not.exist(err);
|
if (err) return done(err);
|
||||||
secondQuery.title.should.equal(2);
|
secondQuery.title.should.equal(2);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue