2013-04-04 22:12:34 +00:00
|
|
|
var db = getSchema(), slave = getSchema(), Model, SlaveModel;
|
|
|
|
var should = require('should');
|
|
|
|
|
2013-04-04 22:13:14 +00:00
|
|
|
<<<<<<< HEAD
|
2013-04-04 22:12:34 +00:00
|
|
|
describe.skip('schema', function() {
|
2013-04-04 22:13:14 +00:00
|
|
|
=======
|
2013-04-01 13:49:12 +00:00
|
|
|
describe.only('schema', function() {
|
2013-04-04 22:13:14 +00:00
|
|
|
>>>>>>> feature-transactions
|
2013-04-04 22:12:34 +00:00
|
|
|
|
|
|
|
it('should define Model', function() {
|
|
|
|
Model = db.define('Model');
|
|
|
|
Model.schema.should.eql(db);
|
|
|
|
var m = new Model;
|
|
|
|
m.schema.should.eql(db);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should clone existing model', function() {
|
|
|
|
SlaveModel = slave.copyModel(Model);
|
|
|
|
SlaveModel.schema.should.eql(slave);
|
|
|
|
slave.should.not.eql(db);
|
|
|
|
var sm = new SlaveModel;
|
|
|
|
sm.should.be.instanceOf(Model);
|
|
|
|
sm.schema.should.not.eql(db);
|
|
|
|
sm.schema.should.eql(slave);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should automigrate', function(done) {
|
|
|
|
db.automigrate(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should create transaction', function(done) {
|
|
|
|
var tr = db.transaction();
|
|
|
|
tr.connected.should.be.false;
|
|
|
|
tr.connecting.should.be.false;
|
|
|
|
var called = false;
|
|
|
|
tr.models.Model.create(Array(3), function () {
|
|
|
|
called = true;
|
|
|
|
});
|
|
|
|
tr.connected.should.be.false;
|
|
|
|
tr.connecting.should.be.true;
|
|
|
|
|
|
|
|
db.models.Model.count(function(err, c) {
|
|
|
|
should.not.exist(err);
|
|
|
|
should.exist(c);
|
|
|
|
c.should.equal(0);
|
|
|
|
called.should.be.false;
|
|
|
|
tr.exec(function () {
|
|
|
|
setTimeout(function() {
|
|
|
|
called.should.be.true;
|
|
|
|
db.models.Model.count(function(err, c) {
|
|
|
|
c.should.equal(3);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
}, 100);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|