describe('Registry tests', function() { var sandbox; var TestModel = BaseModel.extend({ type: 'video', sync: Db.sync.bind(TestDB), db: TestDB, afterSave: function() { var res = TestModel.__super__.afterSave.apply(this, arguments); if (this.options.registry) { this.options.registry.set(this); } return res; } }); beforeEach(function() { sandbox = sinon.sandbox.create(); }); afterEach(function() { sandbox.restore(); }); it('should set value to Registry', function() { var model = new TestModel({ test: 'foo' }); var registry = new serverbone.Registry(); registry.set(model); var cachedModel = registry.get(model.type, model.id); should.exist(cachedModel); }); it('should cache model when saving', function() { var registry = new serverbone.Registry(); var set = sandbox.spy(registry, 'set'); var model = new TestModel({ title: 'bar' }, { registry: registry }); model.isValid().should.equal(true); return model .save() .then(function() { should.exist(model.id, 'Model id was missing'); set.called.should.equal(true); var cachedModel = registry.get(model.type, model.id); should.exist(cachedModel, 'cached model did not exist'); cachedModel.should.be.an.instanceOf(TestModel); cachedModel.get('title').should.equal('bar'); }); }); });
var redisTestDb = require('../config/redis'); var Db = require('backbone-db-local'); var database = new Db('test_database'); var IndexingTestDb = serverbone.db.IndexingTestDb; var indexingDatabase = new IndexingTestDb('index_database'); var BaseModel = serverbone.models.BaseModel; var BaseCollection = serverbone.collections.BaseCollection; var ACLModel = serverbone.models.ACLModel; var FlatModel = serverbone.models.FlatModel; var acl = serverbone.acl; var EmptyModel = exports.EmptyModel = BaseModel.extend({ type: 'barfoo', db: database, sync: Db.sync.bind(database), schema: {id: 'barfoo'} }); var testSchema = { owner: 'user_id', properties: { id: { type: 'integer' }, title: { required: true, type: 'string' }, test: { type: 'string'