diff --git a/src/ngResource/resource.js b/src/ngResource/resource.js index 31a594421e50..5629166f6023 100644 --- a/src/ngResource/resource.js +++ b/src/ngResource/resource.js @@ -132,7 +132,7 @@ function shallowClearAndCopy(src, dst) { * Note that the parameter will be ignored, when calling a "GET" action method (i.e. an action * method that does not accept a request body) * - * @param {Object.=} actions Hash with declaration of custom actions that should extend + * @param {Object.=} actions Hash with declaration of custom actions that should be merged with * the default set of resource actions. The declaration should be created in the format of {@link * ng.$http#usage $http.config}: * @@ -516,6 +516,7 @@ angular.module('ngResource', ['ng']). var noop = angular.noop, forEach = angular.forEach, extend = angular.extend, + merge = angular.merge, copy = angular.copy, isFunction = angular.isFunction, encodeUriQuery = angular.$$encodeUriQuery, @@ -603,7 +604,7 @@ angular.module('ngResource', ['ng']). function resourceFactory(url, paramDefaults, actions, options) { var route = new Route(url, options); - actions = extend({}, provider.defaults.actions, actions); + actions = merge({}, provider.defaults.actions, actions); function extractParams(data, actionParams) { var ids = {}; diff --git a/test/ngResource/resourceSpec.js b/test/ngResource/resourceSpec.js index a848f06d1244..a5b33888744d 100644 --- a/test/ngResource/resourceSpec.js +++ b/test/ngResource/resourceSpec.js @@ -491,6 +491,18 @@ describe("basic usage", function() { }); + it('should deep-merge custom actions with default actions', function() { + $httpBackend.when('GET', '/foo').respond({invokedMethod: 'get'}); + $httpBackend.when('POST', '/foo').respond({invokedMethod: 'post'}); + + var Resource = $resource('/foo', {}, {save: {timeout: 10000}}); + var response = Resource.save(); + + $httpBackend.flush(); + expect(response.invokedMethod).toEqual('post'); + }); + + it("should read partial resource", function() { $httpBackend.expect('GET', '/CreditCard').respond([{id:{key:123}}]); var ccs = CreditCard.query();