summaryrefslogtreecommitdiffstats
path: root/common/src/main/webapp/usageguide/appserver/node_modules/node-restful/test/model.chainable.js
diff options
context:
space:
mode:
Diffstat (limited to 'common/src/main/webapp/usageguide/appserver/node_modules/node-restful/test/model.chainable.js')
-rw-r--r--common/src/main/webapp/usageguide/appserver/node_modules/node-restful/test/model.chainable.js48
1 files changed, 48 insertions, 0 deletions
diff --git a/common/src/main/webapp/usageguide/appserver/node_modules/node-restful/test/model.chainable.js b/common/src/main/webapp/usageguide/appserver/node_modules/node-restful/test/model.chainable.js
new file mode 100644
index 0000000..89b083f
--- /dev/null
+++ b/common/src/main/webapp/usageguide/appserver/node_modules/node-restful/test/model.chainable.js
@@ -0,0 +1,48 @@
+var should = require('should'),
+ request = require('supertest'),
+ restful = require('../'),
+ mongoose = require('mongoose'),
+ sinon = require('sinon');
+
+describe('Model', function() {
+
+ before(function() {
+ restful.model('posts', mongoose.Schema({ title: 'string' }));
+ });
+ it('should return a mongoose model', function() {
+ var posts = restful.model('posts');
+
+ posts.should.have.property('methods');
+ posts.should.have.property('update');
+ posts.should.have.property('remove');
+ posts.should.have.property('updateOptions');
+ posts.should.have.property('removeOptions');
+ });
+ it('should add methods in a chainable way', function() {
+ var posts = restful.model('posts');
+ posts.allowed_methods.should.have.property('get');
+ posts.methods(['get', 'post', 'put'])
+ .updateOptions({})
+ .removeOptions({})
+ .template('/idk/where/this/goes/');
+ posts.allowed_methods.should.containEql('get');
+ posts.allowed_methods.should.containEql('post');
+ posts.allowed_methods.should.containEql('put');
+ posts.update_options.should.be.an.instanceOf(Object);
+ posts.remove_options.should.be.an.instanceOf(Object);
+ posts.templateRoot.should.eql('/idk/where/this/goes');
+
+ });
+ it('should be updateable', function(done) {
+ var Posts = restful.model('posts');
+ Posts.create({
+ title: "First post"
+ }, function(err, post) {
+ post.title.should.equal('First post');
+ Posts.update({_id: post._id}, { title: "Second post"}, function(err, count, resp) {
+ count.n.should.equal(1);
+ done()
+ });
+ })
+ });
+});