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

Commit 5303950

Browse files
gkalpakpetebacondarwin
authored andcommitted
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 9ea1e44 commit 5303950

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
@@ -843,7 +843,8 @@ angular.module('ngResource', ['ng']).
843843
});
844844

845845
Resource.bind = function(additionalParamDefaults) {
846-
return resourceFactory(url, extend({}, paramDefaults, additionalParamDefaults), actions);
846+
var extendedParamDefaults = extend({}, paramDefaults, additionalParamDefaults);
847+
return resourceFactory(url, extendedParamDefaults, actions, options);
847848
};
848849

849850
return Resource;

test/ngResource/resourceSpec.js

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

616616
it('should bind default parameters', function() {
617617
$httpBackend.expect('GET', '/CreditCard/123.visa?minimum=0.05').respond({id: 123});
618-
var Visa = CreditCard.bind({verb:'.visa', minimum:0.05});
619-
var visa = Visa.get({id:123});
618+
var Visa = CreditCard.bind({verb: '.visa', minimum: 0.05});
619+
var visa = Visa.get({id: 123});
620620
$httpBackend.flush();
621-
expect(visa).toEqualData({id:123});
621+
expect(visa).toEqualData({id: 123});
622+
});
623+
624+
625+
it('should pass all original arguments when binding default params', function() {
626+
$httpBackend.expect('GET', '/CancellableCreditCard/123.visa').respond({id: 123});
627+
628+
var CancellableCreditCard = $resource('/CancellableCreditCard/:id:verb', {},
629+
{charge: {method: 'POST'}}, {cancellable: true});
630+
var CancellableVisa = CancellableCreditCard.bind({verb: '.visa'});
631+
var visa = CancellableVisa.get({id: 123});
632+
633+
$httpBackend.flush();
634+
635+
expect(visa.$charge).toEqual(jasmine.any(Function));
636+
expect(visa.$cancelRequest).toEqual(jasmine.any(Function));
622637
});
623638

624639

0 commit comments

Comments
 (0)