loopback/test/memory.test.js

36 lines
862 B
JavaScript
Raw Normal View History

2014-11-21 02:35:36 +00:00
describe('Memory Connector', function() {
2013-07-16 20:39:03 +00:00
it('Create a model using the memory connector', function(done) {
// use the built in memory function
// to create a memory data source
var memory = loopback.memory();
// or create it using the standard
// data source creation api
2014-11-21 01:47:47 +00:00
memory = loopback.createDataSource({
connector: loopback.Memory,
2013-07-16 20:39:03 +00:00
});
2014-11-21 01:47:47 +00:00
2013-07-16 20:39:03 +00:00
// create a model using the
// memory data source
var properties = {
name: String,
price: Number,
2013-07-16 20:39:03 +00:00
};
2014-11-21 01:47:47 +00:00
2013-07-16 20:39:03 +00:00
var Product = memory.createModel('product', properties);
2014-11-21 01:47:47 +00:00
2013-07-16 20:39:03 +00:00
Product.create([
{ name: 'apple', price: 0.79 },
{ name: 'pear', price: 1.29 },
{ name: 'orange', price: 0.59 },
2013-07-16 20:39:03 +00:00
], count);
2014-11-21 01:47:47 +00:00
2013-07-16 20:39:03 +00:00
function count() {
2014-11-21 02:35:36 +00:00
Product.count(function(err, count) {
2013-07-16 20:39:03 +00:00
assert.equal(count, 3);
done();
});
}
});
2014-11-21 01:47:47 +00:00
});