diff options
Diffstat (limited to 'test/ngResource')
| -rw-r--r-- | test/ngResource/resourceSpec.js | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/test/ngResource/resourceSpec.js b/test/ngResource/resourceSpec.js index d13156b3..5b75c8cf 100644 --- a/test/ngResource/resourceSpec.js +++ b/test/ngResource/resourceSpec.js @@ -31,6 +31,48 @@ describe("resource", function() { $httpBackend.verifyNoOutstandingExpectation(); }); + describe('isValidDottedPath', function() { + it('should support arbitrary dotted names', function() { + expect(isValidDottedPath('')).toBe(false); + expect(isValidDottedPath('1')).toBe(false); + expect(isValidDottedPath('1abc')).toBe(false); + expect(isValidDottedPath('.')).toBe(false); + expect(isValidDottedPath('$')).toBe(true); + expect(isValidDottedPath('a')).toBe(true); + expect(isValidDottedPath('A')).toBe(true); + expect(isValidDottedPath('a1')).toBe(true); + expect(isValidDottedPath('$a')).toBe(true); + expect(isValidDottedPath('$1')).toBe(true); + expect(isValidDottedPath('$$')).toBe(true); + expect(isValidDottedPath('$.$')).toBe(true); + expect(isValidDottedPath('.$')).toBe(false); + expect(isValidDottedPath('$.')).toBe(false); + }); + }); + + describe('lookupDottedPath', function() { + var data = {a: {b: 'foo', c: null}}; + + it('should throw for invalid path', function() { + expect(function() { + lookupDottedPath(data, '.ckck') + }).toThrowMinErr('$resource', 'badmember', + 'Dotted member path "@.ckck" is invalid.'); + }); + + it('should get dotted paths', function() { + expect(lookupDottedPath(data, 'a')).toEqual({b: 'foo', c: null}); + expect(lookupDottedPath(data, 'a.b')).toBe('foo'); + expect(lookupDottedPath(data, 'a.c')).toBeNull(); + }); + + it('should skip over null/undefined members', function() { + expect(lookupDottedPath(data, 'a.b.c')).toBe(undefined); + expect(lookupDottedPath(data, 'a.c.c')).toBe(undefined); + expect(lookupDottedPath(data, 'a.b.c.d')).toBe(undefined); + expect(lookupDottedPath(data, 'NOT_EXIST')).toBe(undefined); + }); + }); it('should not include a request body when calling $delete', function() { $httpBackend.expect('DELETE', '/fooresource', null).respond({}); @@ -189,6 +231,19 @@ describe("resource", function() { }); + it('should support @_property lookups with underscores', function() { + $httpBackend.expect('GET', '/Order/123').respond({_id: {_key:'123'}, count: 0}); + var LineItem = $resource('/Order/:_id', {_id: '@_id._key'}); + var item = LineItem.get({_id: 123}); + $httpBackend.flush(); + expect(item).toEqualData({_id: {_key: '123'}, count: 0}); + $httpBackend.expect('POST', '/Order/123').respond({_id: {_key:'123'}, count: 1}); + item.$save(); + $httpBackend.flush(); + expect(item).toEqualData({_id: {_key: '123'}, count: 1}); + }); + + it('should not pass default params between actions', function() { var R = $resource('/Path', {}, {get: {method: 'GET', params: {objId: '1'}}, perform: {method: 'GET'}}); |
