This repository has been archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat($resource): allow dynamic default parameters
Default resource params can now be calculated at runtime if defined via a function.
- Loading branch information
Showing
2 changed files
with
36 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -356,6 +356,35 @@ describe("resource", function() { | |
}); | ||
|
||
|
||
it('should support dynamic default parameters (global)', function() { | ||
var currentGroup = 'students', | ||
Person = $resource('/Person/:group/:id', { group: function() { return currentGroup; }}); | ||
|
||
|
||
$httpBackend.expect('GET', '/Person/students/fedor').respond({id: 'fedor', email: '[email protected]'}); | ||
|
||
var fedor = Person.get({id: 'fedor'}); | ||
$httpBackend.flush(); | ||
|
||
expect(fedor).toEqualData({id: 'fedor', email: '[email protected]'}); | ||
}); | ||
|
||
|
||
it('should support dynamic default parameters (action specific)', function() { | ||
var currentGroup = 'students', | ||
Person = $resource('/Person/:group/:id', {}, { | ||
fetch: {method: 'GET', params: {group: function() { return currentGroup; }}} | ||
}); | ||
|
||
$httpBackend.expect('GET', '/Person/students/fedor').respond({id: 'fedor', email: '[email protected]'}); | ||
|
||
var fedor = Person.fetch({id: 'fedor'}); | ||
$httpBackend.flush(); | ||
|
||
expect(fedor).toEqualData({id: 'fedor', email: '[email protected]'}); | ||
}); | ||
|
||
|
||
it('should exercise full stack', function() { | ||
var Person = $resource('/Person/:id'); | ||
|
||
|