Skip to content

Commit

Permalink
Test and fix for allowing services with only a setup method (#285)
Browse files Browse the repository at this point in the history
  • Loading branch information
daffl committed Apr 23, 2016
1 parent 7196c03 commit 73d8ce2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ export default {

// Run the provider functions to register the service
this.providers.forEach(provider =>
provider.call(this, location, protoService, options));
provider.call(this, location, protoService, options)
);

// If we ran setup already, set this service up explicitly
if (this._isSetup && typeof protoService.setup === 'function') {
Expand Down Expand Up @@ -75,10 +76,11 @@ export default {
});

const hasMethod = methods => methods.some(name =>
(service && typeof service[name] === 'function'));
(service && typeof service[name] === 'function')
);

// Check for service (any object with at least one service method)
if(hasMethod(['handle', 'set']) || !hasMethod(this.methods)) {
if(hasMethod(['handle', 'set']) || !hasMethod(this.methods.concat('setup'))) {
return this._super.apply(this, arguments);
}

Expand Down
14 changes: 14 additions & 0 deletions test/application.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,20 @@ describe('Feathers application', () => {
assert.equal(otherApp.mixins.length, 4);
});

it('initializes a service with only a setup method (#285)', done => {
const app = feathers();

app.use('/setup-only', {
setup(_app, path) {
assert.equal(_app, app);
assert.equal(path, 'setup-only');
done();
}
});

app.setup();
});

it('Event punching happens after normalization (#150)', done => {
const todoService = {
create(data) {
Expand Down

0 comments on commit 73d8ce2

Please sign in to comment.