2013-04-06 10:57:12 +00:00
|
|
|
// This test written in mocha+should.js
|
|
|
|
var should = require('./init.js');
|
|
|
|
|
2013-03-24 22:29:13 +00:00
|
|
|
var Schema = require('../').Schema;
|
2013-03-19 10:05:38 +00:00
|
|
|
|
|
|
|
describe('JSON property', function() {
|
2013-07-23 18:16:43 +00:00
|
|
|
var dataSource, Model;
|
2013-03-19 10:05:38 +00:00
|
|
|
|
2013-03-24 21:29:07 +00:00
|
|
|
it('should be defined', function() {
|
2013-07-23 18:16:43 +00:00
|
|
|
dataSource = getSchema();
|
|
|
|
Model = dataSource.define('Model', {propertyName: Schema.JSON});
|
2013-03-19 10:05:38 +00:00
|
|
|
var m = new Model;
|
2013-03-24 13:37:13 +00:00
|
|
|
(new Boolean('propertyName' in m)).should.eql(true);
|
2013-03-19 10:05:38 +00:00
|
|
|
should.not.exist(m.propertyName);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should accept JSON in constructor and return object', function() {
|
|
|
|
var m = new Model({
|
|
|
|
propertyName: '{"foo": "bar"}'
|
|
|
|
});
|
|
|
|
m.propertyName.should.be.an.Object;
|
|
|
|
m.propertyName.foo.should.equal('bar');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should accept object in setter and return object', function() {
|
|
|
|
var m = new Model;
|
|
|
|
m.propertyName = {"foo": "bar"};
|
|
|
|
m.propertyName.should.be.an.Object;
|
|
|
|
m.propertyName.foo.should.equal('bar');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should accept string in setter and return string', function() {
|
|
|
|
var m = new Model;
|
|
|
|
m.propertyName = '{"foo": "bar"}';
|
|
|
|
m.propertyName.should.be.a.String;
|
|
|
|
m.propertyName.should.equal('{"foo": "bar"}');
|
|
|
|
});
|
|
|
|
});
|