mgonto/restangular — pull request #638 by idpaterson (2014-03-18 20:15:02+00:00)
Title: Pull requests/fix request extension by interceptors

As @nerezo alluded to in #608, `_.defaults` was causing inconsistent behavior when using request interceptors. Previously, the first value returned for either `element`, `headers`, `params`, or `httpConfig` by any interceptor was the value that was used in the request. This made it impossible to chain interceptors because each was receiving a copy of the original data and was only sometimes given the chance to modify that data.

The existing tests passed because a single reference to the resource was being modified. The addition of `angular.copy(element)` quickly shows that the return value is not actually being used as expected.

The code was changed to use `_.extend` rather than `_.defaults` since it eliminates the first-in-wins behavior. Additionally, the data passed to the interceptors is taken from the `request` accumulator rather than from the initial input. `config.defaultInterceptor` is now used to provide the defaults for `request` based on the initial data. This behavior is what I would expect, but it differs from what happened in the past (`config.defaultInterceptor` was executed last to add any missing keys to the `request`). People overriding `defaultInterceptor` could have issues with this change, but that is neither something that was documented nor something that seems sensible to do.