Skip to content
This repository has been archived by the owner on May 4, 2019. It is now read-only.

[RFR] Fix issue in resource model chaining #9

Merged
merged 2 commits into from
Mar 12, 2015
Merged
Changes from 1 commit
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
Next Next commit
Fix issue in resource model chaining
Fixes #7
RobinBressan committed Mar 11, 2015

Verified

This commit was signed with the committer’s verified signature.
TimoGlastra Timo Glastra
commit b643711bc8839e3026ad29a71b2c9ce7df48a05d
4 changes: 2 additions & 2 deletions dist/restful.min.js

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions src/model/resource.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
export default function resource(refEndpoint) {
var model = {
model = function() {
return refEndpoint;
}

var model = Object.assign(model, {
addRequestInterceptor(interceptor) {
refEndpoint.requestInterceptors().push(interceptor);

@@ -29,9 +33,7 @@ export default function resource(refEndpoint) {
headers() {
return refEndpoint.headers();
},
};
});

return Object.assign(function() {
return refEndpoint;
}, model);
return model;
}
19 changes: 19 additions & 0 deletions test/src/restful-spec.js
Original file line number Diff line number Diff line change
@@ -823,5 +823,24 @@
expect(transformedData.title).toBe('Intercepted');
});
});

it('should correctly chain callback in restful object', function() {
expect(resource.header('foo', 'bar')).toBe(resource);
expect(resource.header('foo', 'bar').prefixUrl('v1')).toBe(resource);

var articlesCollection = resource.header('foo', 'bar').prefixUrl('v1').all('articles');

expect(articlesCollection.header('foo1', 'bar1')).toBe(articlesCollection);

expect(articlesCollection.header('foo2', 'bar2')
.addResponseInterceptor(jasmine.createSpy('interceptor'))).toBe(articlesCollection);

var commentsMember = resource.one('articles', 2).one('comments', 1);

expect(commentsMember.header('foo3', 'bar3')).toBe(commentsMember);

expect(commentsMember.header('foo4', 'bar4')
.addResponseInterceptor(jasmine.createSpy('interceptor'))).toBe(commentsMember);
});
});
})();