diff --git a/lib/models/model.js b/lib/models/model.js index e4414505..b8a4e1c1 100644 --- a/lib/models/model.js +++ b/lib/models/model.js @@ -507,9 +507,11 @@ Model.scopeRemoting = function(scopeName, scope, define) { define('__count__' + scopeName, { isStatic: isStatic, http: {verb: 'get', path: '/' + pathName + '/count'}, + accepts: {arg: 'where', type: 'object', description: 'Criteria to match model instances'}, description: 'Counts ' + scopeName + ' of ' + this.modelName + '.', - returns: {arg: 'count', type: 'number', root: true} + returns: {arg: 'count', type: 'number'} }); + }; Model.nestRemoting = function(relationName, options, cb) { diff --git a/test/relations.integration.js b/test/relations.integration.js index c0e2d28c..ccf3f27b 100644 --- a/test/relations.integration.js +++ b/test/relations.integration.js @@ -113,6 +113,48 @@ describe('relations - integration', function () { }); }); }); + + describe('/store/:id/widgets/count', function () { + beforeEach(function() { + this.url = '/api/stores/' + this.store.id + '/widgets/count'; + }); + lt.describe.whenCalledRemotely('GET', '/api/stores/:id/widgets/count', function() { + it('should succeed with statusCode 200', function() { + assert.equal(this.res.statusCode, 200); + }); + it('should return the count', function() { + assert.equal(this.res.body.count, 1); + }); + }); + }); + + describe('/store/:id/widgets/count - filtered (matches)', function () { + beforeEach(function() { + this.url = '/api/stores/' + this.store.id + '/widgets/count?where[name]=foo'; + }); + lt.describe.whenCalledRemotely('GET', '/api/stores/:id/widgets/count?where[name]=foo', function() { + it('should succeed with statusCode 200', function() { + assert.equal(this.res.statusCode, 200); + }); + it('should return the count', function() { + assert.equal(this.res.body.count, 1); + }); + }); + }); + + describe('/store/:id/widgets/count - filtered (no matches)', function () { + beforeEach(function() { + this.url = '/api/stores/' + this.store.id + '/widgets/count?where[name]=bar'; + }); + lt.describe.whenCalledRemotely('GET', '/api/stores/:id/widgets/count?where[name]=bar', function() { + it('should succeed with statusCode 200', function() { + assert.equal(this.res.statusCode, 200); + }); + it('should return the count', function() { + assert.equal(this.res.body.count, 0); + }); + }); + }); describe('/widgets/:id/store', function () { beforeEach(function (done) {