Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure .setup() runs on dynamic services. #110

Merged
merged 1 commit into from
Feb 13, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions lib/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ module.exports = {
},

service: function(location, service, options) {
location = stripSlashes(location);

if(!service) {
return this.services[stripSlashes(location)];
return this.services[location];
}

var protoService = Proto.extend(service);
var self = this;

location = stripSlashes(location);

// Add all the mixins
_.each(this.mixins, function (fn) {
fn.call(self, protoService);
Expand All @@ -46,8 +46,12 @@ module.exports = {
});

// If already _setup, just add this single service.
if (this._setup && this.addService) {
this.addService(protoService, stripSlashes(location));
if (this._setup) {
// If we're using a socket provider, register the service on it.
if (this.addService) {
this.addService(protoService, location);
}
protoService.setup(this, location);
}

this.services[location] = protoService;
Expand Down
16 changes: 14 additions & 2 deletions test/application.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,27 @@ describe('Feathers application', function () {
});
});

it('Registers a service, wraps it, and adds the event mixin.', function (done) {
it('Registers a service, wraps it, runs service.setup(), and adds the event mixin.', function (done) {
var dummyService = {
setup: function(app, path){
this.path = path;
},

create: function (data, params, callback) {
callback(null, data);
}
};

var dynamicService;

var app = feathers().use('/dummy', dummyService);
var server = app.listen(7887);
var server = app.listen(7887, function(){
app.use('/dumdum', dummyService);
dynamicService = app.service('dumdum');

assert.ok(wrappedService.path === 'dummy', 'Wrapped service setup method ran.');
assert.ok(dynamicService.path === 'dumdum', 'Dynamic service setup method ran.');
});
var wrappedService = app.service('dummy');

assert.ok(Proto.isPrototypeOf(wrappedService), 'Service got wrapped as Uberproto object');
Expand Down
7 changes: 6 additions & 1 deletion test/providers/primus.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -438,10 +438,15 @@ describe('Primus provider', function () {
socket.send('tasks::remove', 1, {}, function() {});
socket.send('tasks::remove', 23, {}, function() {});

var ready = false;

socket.on('tasks removed', function (data) {
service.removed = oldRemoved;
assert.equal(data.id, 23);
done();
if (ready) {
done();
}
ready = true;
});
});
});
Expand Down
7 changes: 6 additions & 1 deletion test/providers/socketio.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,10 +437,15 @@ describe('SocketIO provider', function () {
socket.emit('tasks::remove', 1, {}, function() {});
socket.emit('tasks::remove', 23, {}, function() {});

var ready = false;

socket.on('tasks removed', function (data) {
service.removed = oldRemoved;
assert.equal(data.id, 23);
done();
if (ready) {
done();
}
ready = true;
});
});
});
Expand Down