Correctly handle remoting of scope methods

This commit is contained in:
Fabien Franzen 2014-07-30 17:30:21 +02:00
parent af0ca5b108
commit 090c738bb5
2 changed files with 13 additions and 3 deletions

View File

@ -64,11 +64,18 @@ function extendScopeMethods(definition, scopeMethods, ext) {
customMethods = ext.call(definition, scopeMethods, relationClass);
} else if (typeof ext === 'object') {
for (var key in ext) {
scopeMethods[key] = function () {
var relationMethod = ext[key];
var method = scopeMethods[key] = function () {
var relation = new relationClass(definition, this);
return ext[key].apply(relation, arguments);
return relationMethod.apply(relation, arguments);
};
if (ext[key].shared === true) scopeMethods[key].shared = true;
if (relationMethod.shared) {
method.shared = true;
method.accepts = relationMethod.accepts;
method.returns = relationMethod.returns;
method.http = relationMethod.http;
method.description = relationMethod.description;
}
customMethods.push(key);
}
}

View File

@ -1861,12 +1861,15 @@ describe('relations', function () {
};
reverse.shared = true; // remoting
reverse.http = { verb: 'put', path: '/products/reverse' };
Category.referencesMany(Product, { scopeMethods: {
reverse: reverse
} });
Category.prototype['__reverse__products'].should.be.a.function;
should.exist(Category.prototype['__reverse__products'].shared);
Category.prototype['__reverse__products'].http.should.eql(reverse.http);
db.automigrate(done);
});