diff options
| author | zeflasher | 2013-02-22 15:49:26 +1300 | 
|---|---|---|
| committer | Igor Minar | 2013-02-27 10:52:30 -0800 | 
| commit | 60f1f099fc7e5197808cd6acb7407cdc40f50a3f (patch) | |
| tree | 5bc062fb61ff416b6dcaec7844e6b18de1768d68 /test/ngResource | |
| parent | cf17c6af475eace31cf52944afd8e10d3afcf6c0 (diff) | |
| download | angular.js-60f1f099fc7e5197808cd6acb7407cdc40f50a3f.tar.bz2 | |
feat($resource): ability to override url in resource actions
Resources now can defined per action url override. The url is treated
as a template rather than a literal string, so fancy interpolations
are possible.
See attached tests for example usage.
Diffstat (limited to 'test/ngResource')
| -rw-r--r-- | test/ngResource/resourceSpec.js | 62 | 
1 files changed, 62 insertions, 0 deletions
diff --git a/test/ngResource/resourceSpec.js b/test/ngResource/resourceSpec.js index e5366f4f..11124739 100644 --- a/test/ngResource/resourceSpec.js +++ b/test/ngResource/resourceSpec.js @@ -703,4 +703,66 @@ describe("resource", function() {      $httpBackend.flush();      expect(person.id).toEqual(456);    }); + + +  describe('action-level url override', function() { + +    it('should support overriding url template with static url', function() { +      $httpBackend.expect('GET', '/override-url?type=Customer&typeId=123').respond({id: 'abc'}); +      var TypeItem = $resource('/:type/:typeId', {type: 'Order'}, { +          get: { +            method: 'GET', +            params: {type: 'Customer'}, +            url: '/override-url' +          } +      }); +      var item = TypeItem.get({typeId: 123}); +      $httpBackend.flush(); +      expect(item).toEqualData({id: 'abc'}); +    }); + + +    it('should support overriding url template with a new template ending in param', function() { +      //    url parameter in action, parameter ending the string +      $httpBackend.expect('GET', '/Customer/123').respond({id: 'abc'}); +      var TypeItem = $resource('/foo/:type', {type: 'Order'}, { +        get: { +          method: 'GET', +          params: {type: 'Customer'}, +          url: '/:type/:typeId' +        } +      }); +      var item = TypeItem.get({typeId: 123}); +      $httpBackend.flush(); +      expect(item).toEqualData({id: 'abc'}); + +      //    url parameter in action, parameter not ending the string +      $httpBackend.expect('GET', '/Customer/123/pay').respond({id: 'abc'}); +      var TypeItem = $resource('/foo/:type', {type: 'Order'}, { +        get: { +          method: 'GET', +          params: {type: 'Customer'}, +          url: '/:type/:typeId/pay' +        } +      }); +      var item = TypeItem.get({typeId: 123}); +      $httpBackend.flush(); +      expect(item).toEqualData({id: 'abc'}); +    }); + + +    it('should support overriding url template with a new template ending in string', function() { +      $httpBackend.expect('GET', '/Customer/123/pay').respond({id: 'abc'}); +      var TypeItem = $resource('/foo/:type', {type: 'Order'}, { +        get: { +          method: 'GET', +          params: {type: 'Customer'}, +          url: '/:type/:typeId/pay' +        } +      }); +      var item = TypeItem.get({typeId: 123}); +      $httpBackend.flush(); +      expect(item).toEqualData({id: 'abc'}); +    }); +  });  });  | 
