diff --git a/lib/index.js b/lib/index.js index bd82b95..0d68d08 100644 --- a/lib/index.js +++ b/lib/index.js @@ -34,11 +34,18 @@ var epilogue = { this.updateMethod = method; } + + this.defaultOptions = { + resource: {} + }; + if (options.resource) { + this.defaultOptions.resource = options.resource; + } }, resource: function(options) { options = options || {}; - _.defaults(options, { + _.defaults(options, this.defaultOptions.resource, { include: [], associations: false }); diff --git a/tests/epilogue.test.js b/tests/epilogue.test.js index 6c69cea..3d2c2a0 100644 --- a/tests/epilogue.test.js +++ b/tests/epilogue.test.js @@ -34,6 +34,22 @@ describe('Epilogue', function() { done(); }); + it('should extend .resource options if they are provided on initialize', function() { + var resourceOptions = { pagination: false }; + + epilogue.initialize({ + app: {}, + sequelize: new Sequelize('main', null, null, { + dialect: 'sqlite', + storage: ':memory:', + logging: (process.env.SEQ_LOG ? console.log : false) + }), + resource: resourceOptions + }); + + expect(epilogue.defaultOptions.resource).to.be.equal(resourceOptions); + }); + it('should allow the user to pass in a sequelize instance rather than prototype', function() { var db = new Sequelize('main', null, null, { dialect: 'sqlite', diff --git a/tests/resource/resource.test.js b/tests/resource/resource.test.js index c27b980..b5e48eb 100644 --- a/tests/resource/resource.test.js +++ b/tests/resource/resource.test.js @@ -78,7 +78,7 @@ describe('Resource(basic)', function() { // TESTS describe('construction', function() { it('should throw an exception if called with an invalid model', function(done) { - expect(rest.resource).to.throw('please specify a valid model'); + expect(rest.resource.bind(rest)).to.throw('please specify a valid model'); done(); }); @@ -89,7 +89,16 @@ describe('Resource(basic)', function() { expect(exception).to.eql(new Error('resource needs a model')); done(); } + }); + + it('should extend default options', function() { + rest.defaultOptions.resource = { pagination: false }; + + var resource = rest.resource({ + model: test.models.Person + }); + expect( resource.pagination ).to.be.equal( false ); }); it('should auto generate endpoints if none were provided', function() {