Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 6eb4ffc

Browse files
committed
fix($resource): pass options when binding default params
`Resource.bind()`, which creates an new Resource class with the same propertiesexcept for the additional bound default parameters, was not passing the original Resource class' `options`, resulting in different behavior. This commit fixes it by passing the `options` when creating the new Resource class.
1 parent b59bc0b commit 6eb4ffc

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/ngResource/resource.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,8 @@ angular.module('ngResource', ['ng']).
825825
});
826826

827827
Resource.bind = function(additionalParamDefaults) {
828-
return resourceFactory(url, extend({}, paramDefaults, additionalParamDefaults), actions);
828+
var extendedParamDefaults = extend({}, paramDefaults, additionalParamDefaults);
829+
return resourceFactory(url, extendedParamDefaults, actions, options);
829830
};
830831

831832
return Resource;

test/ngResource/resourceSpec.js

+18-3
Original file line numberDiff line numberDiff line change
@@ -636,10 +636,25 @@ describe('basic usage', function() {
636636

637637
it('should bind default parameters', function() {
638638
$httpBackend.expect('GET', '/CreditCard/123.visa?minimum=0.05').respond({id: 123});
639-
var Visa = CreditCard.bind({verb:'.visa', minimum:0.05});
640-
var visa = Visa.get({id:123});
639+
var Visa = CreditCard.bind({verb: '.visa', minimum: 0.05});
640+
var visa = Visa.get({id: 123});
641641
$httpBackend.flush();
642-
expect(visa).toEqualData({id:123});
642+
expect(visa).toEqualData({id: 123});
643+
});
644+
645+
646+
it('should pass all original arguments when binding default params', function() {
647+
$httpBackend.expect('GET', '/CancellableCreditCard/123.visa').respond({id: 123});
648+
649+
var CancellableCreditCard = $resource('/CancellableCreditCard/:id:verb', {},
650+
{charge: {method: 'POST'}}, {cancellable: true});
651+
var CancellableVisa = CancellableCreditCard.bind({verb: '.visa'});
652+
var visa = CancellableVisa.get({id: 123});
653+
654+
$httpBackend.flush();
655+
656+
expect(visa.$charge).toEqual(jasmine.any(Function));
657+
expect(visa.$cancelRequest).toEqual(jasmine.any(Function));
643658
});
644659

645660

0 commit comments

Comments
 (0)