Simplify the test case

This commit is contained in:
Raymond Feng 2014-02-12 22:49:54 -08:00
parent 061b274055
commit 0d3ce00f35
1 changed files with 5 additions and 27 deletions

View File

@ -5,25 +5,6 @@ var db, Model;
describe('datatypes', function () { describe('datatypes', function () {
// Used to emulate a custom id type
function DummyType(value) {
if (!(this instanceof DummyType) &&
( typeof value === 'string' || typeof value === 'object')) {
return new DummyType(value);
}
if (typeof value === 'string') {
this.value = value;
return;
} else if (typeof value === 'object') {
this.value = value.value;
return;
}
return value;
};
before(function (done) { before(function (done) {
db = getSchema(); db = getSchema();
Model = db.define('Model', { Model = db.define('Model', {
@ -31,8 +12,7 @@ describe('datatypes', function () {
date: Date, date: Date,
num: Number, num: Number,
bool: Boolean, bool: Boolean,
dummy: DummyType, list: {type: [String]},
list: {type: []},
}); });
db.automigrate(function () { db.automigrate(function () {
Model.destroyAll(done); Model.destroyAll(done);
@ -87,8 +67,7 @@ describe('datatypes', function () {
var d = new Date, id; var d = new Date, id;
Model.create({ Model.create({
str: 'hello', date: d, num: '3', bool: 1, dummy: new DummyType('dummy') str: 'hello', date: d, num: '3', bool: 1}, function(err, m) {
}, function(err, m) {
should.not.exist(err); should.not.exist(err);
should.exist(m && m.id); should.exist(m && m.id);
@ -96,7 +75,6 @@ describe('datatypes', function () {
m.str.should.be.a('string'); m.str.should.be.a('string');
m.num.should.be.a('number'); m.num.should.be.a('number');
m.bool.should.be.a('boolean'); m.bool.should.be.a('boolean');
m.dummy.should.be.an.instanceOf(DummyType);
id = m.id; id = m.id;
testDataInDB(function () { testDataInDB(function () {
testUpdate(function() { testUpdate(function() {
@ -111,10 +89,10 @@ describe('datatypes', function () {
// update using updateAttributes // update using updateAttributes
m.updateAttributes({ m.updateAttributes({
id: id, dummy: 'NotADummy' id: id, num: '10'
}, function (err, m) { }, function (err, m) {
should.not.exist(err); should.not.exist(err);
m.dummy.should.be.an.instanceOf(DummyType); m.num.should.be.a('number');
done(); done();
}); });
}); });
@ -125,7 +103,7 @@ describe('datatypes', function () {
// verify that the value stored in the db is still an object // verify that the value stored in the db is still an object
db.connector.find(Model.modelName, id, function (err, data) { db.connector.find(Model.modelName, id, function (err, data) {
should.exist(data); should.exist(data);
data.dummy.should.be.a('object'); data.num.should.be.a('number');
done(); done();
}); });
} }