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

feat($resource): deep-merge custom actions with default actions. #14821

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 3 additions & 2 deletions src/ngResource/resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.<Object>=} actions Hash with declaration of custom actions that should extend
* @param {Object.<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}:
*
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 = {};
Expand Down
12 changes: 12 additions & 0 deletions test/ngResource/resourceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down