Upd tests

- skipping
- hook up redis-hq
- some stuff should be moved to advanced-querying tests
This commit is contained in:
Anatoliy Chakkaev 2013-03-29 11:43:04 +04:00
parent 5540750626
commit 839791de2f
4 changed files with 60 additions and 34 deletions

View File

@ -6,10 +6,10 @@ describe('basic-querying', function() {
db = getSchema(); db = getSchema();
User = db.define('User', { User = db.define('User', {
name: String, name: {type: String, sort: true},
email: {type: String, index: true}, email: {type: String, index: true},
role: {type: String, index: true}, role: {type: String, index: true},
order: {type: Number, index: true} order: {type: Number, index: true, sort: true}
}); });
db.automigrate(done); db.automigrate(done);
@ -142,7 +142,7 @@ describe('basic-querying', function() {
before(seed); before(seed);
it('should find first record (default sort by id)', function(done) { it('should find first record (default sort by id)', function(done) {
User.all({sort: 'id'}, function(err, users) { User.all({order: 'id'}, function(err, users) {
User.findOne(function(e, u) { User.findOne(function(e, u) {
should.not.exist(e); should.not.exist(e);
should.exist(u); should.exist(u);
@ -172,7 +172,8 @@ describe('basic-querying', function() {
}); });
}); });
it('should find last record in filtered set', function(done) { // TODO: it's not basic query, move to advanced querying test
it.skip('should find last record in filtered set', function(done) {
User.findOne({ User.findOne({
where: {role: 'lead'}, where: {role: 'lead'},
order: 'order DESC' order: 'order DESC'

View File

@ -280,23 +280,6 @@ describe('hooks', function() {
}); });
}); });
it('should describe new+save sequence', function(done) {
var u = new User;
u.save(function() {
life.should.eql([
'afterInitialize',
'beforeValidate',
'afterValidate',
'beforeCreate',
'beforeSave',
'afterInitialize',
'afterSave',
'afterCreate'
]);
done();
});
});
it('should describe updateAttributes sequence', function(done) { it('should describe updateAttributes sequence', function(done) {
user.updateAttributes({name: 'Antony'}, function() { user.updateAttributes({name: 'Antony'}, function() {
life.should.eql([ life.should.eql([
@ -311,6 +294,30 @@ describe('hooks', function() {
}); });
}); });
it('should describe isValid sequence', function(done) {
should.not.exist(
user.constructor._validations,
'Expected user to have no validations, but she have');
user.isValid(function(valid) {
valid.should.be.true;
life.should.eql([
'beforeValidate',
'afterValidate'
]);
done();
});
});
it('should describe destroy sequence', function(done) {
user.destroy(function() {
life.should.eql([
'beforeDestroy',
'afterDestroy'
]);
done();
});
});
}); });
}); });

View File

@ -65,7 +65,7 @@ describe('relations', function() {
}); });
}); });
it('should fetch all scoped instances', function(done) { it.skip('should fetch all scoped instances', function(done) {
Book.create(function(err, book) { Book.create(function(err, book) {
book.chapters.create({name: 'a'}, function() { book.chapters.create({name: 'a'}, function() {
book.chapters.create({name: 'z'}, function() { book.chapters.create({name: 'z'}, function() {

View File

@ -1,4 +1,5 @@
var j = require('../'), db, User; var j = require('../'), db, User;
var should = require('should');
function getValidAttributes() { function getValidAttributes() {
return { return {
@ -12,9 +13,9 @@ function getValidAttributes() {
}; };
} }
describe('validations', function() { describe.only('validations', function() {
beforeEach(function() { before(function(done) {
db = getSchema(); db = getSchema();
User = db.define('User', { User = db.define('User', {
email: String, email: String,
@ -29,12 +30,35 @@ describe('validations', function() {
createdByScript: Boolean, createdByScript: Boolean,
updatedAt: Date updatedAt: Date
}); });
db.automigrate(done);
}); });
afterEach(function() { beforeEach(function(done) {
User.destroyAll(function() {
delete User._validations;
done();
});
});
after(function() {
db.disconnect(); db.disconnect();
}); });
describe('commons', function() {
describe('skipping', function() {
it('should allow to skip using if: attribute', function() {
User.validatesPresenceOf('pendingPeriod', {if: 'createdByAdmin'});
var user = new User;
user.createdByAdmin = true;
user.isValid().should.be.false;
user.errors.pendingPeriod.should.eql(['can\'t be blank']);
user.pendingPeriod = 1
user.isValid().should.be.true;
});
});
});
describe('presence', function() { describe('presence', function() {
it('should validate presence', function() { it('should validate presence', function() {
@ -47,19 +71,11 @@ describe('validations', function() {
}); });
it('should skip validation by property (if/unless)', function() { it('should skip validation by property (if/unless)', function() {
User.validatesPresenceOf('pendingPeriod', {if: 'createdByAdmin'});
User.validatesPresenceOf('domain', {unless: 'createdByScript'}); User.validatesPresenceOf('domain', {unless: 'createdByScript'});
var user = new User(getValidAttributes()) var user = new User(getValidAttributes())
user.isValid().should.be.true; user.isValid().should.be.true;
user.createdByAdmin = true;
user.isValid().should.be.false;
user.errors.pendingPeriod.should.eql(['can\'t be blank']);
user.pendingPeriod = 1
user.isValid().should.be.true;
user.createdByScript = false; user.createdByScript = false;
user.isValid().should.be.false; user.isValid().should.be.false;
user.errors.domain.should.eql(['can\'t be blank']); user.errors.domain.should.eql(['can\'t be blank']);
@ -98,8 +114,10 @@ describe('validations', function() {
u.save(done); u.save(done);
}); });
}); });
})).should.be.false; // async validations always falsy when called as sync
})).should.not.be.ok;
}); });
}); });
describe('format', function() { describe('format', function() {