diff options
| author | Igor Minar | 2010-09-23 05:37:17 +0800 |
|---|---|---|
| committer | Misko Hevery | 2010-09-23 17:23:52 +0800 |
| commit | acbcfbaf30f73f25df1c45da41132091e7022240 (patch) | |
| tree | cbf6fea04061974197a5f6c9b9c983ce18b054ff /test/servicesSpec.js | |
| parent | a8931c9021fa15190927b913a66fb34deedf9e20 (diff) | |
| download | angular.js-acbcfbaf30f73f25df1c45da41132091e7022240.tar.bz2 | |
$cookies service refactoring
- remove obsolete code in tests
- add warning logs when maximum cookie limits (as specified via RFC 2965) were reached
- non-string values will now get dropped
- after each update $cookies hash will reflect the actual state of browser cookies
this means that if browser drops some cookies due to cookie overflow, $cookies will reflect that
- $sessionStore got renamed to $cookieStore to avoid name conflicts with html5's sessionStore
Diffstat (limited to 'test/servicesSpec.js')
| -rw-r--r-- | test/servicesSpec.js | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/test/servicesSpec.js b/test/servicesSpec.js index 28bde598..3416f0ea 100644 --- a/test/servicesSpec.js +++ b/test/servicesSpec.js @@ -373,13 +373,22 @@ describe("service", function(){ describe('$cookies', function() { - it('should provide access to existing cookies via object properties', function(){ + it('should provide access to existing cookies via object properties and keep them in sync', + function(){ expect(scope.$cookies).toEqual({}); scope.$browser.cookies('brandNew', 'cookie'); scope.$browser.poll(); expect(scope.$cookies).toEqual({'brandNew':'cookie'}); + + scope.$browser.cookies('brandNew', 'cookie2'); + scope.$browser.poll(); + expect(scope.$cookies).toEqual({'brandNew':'cookie2'}); + + scope.$browser.cookies('brandNew', undefined); + scope.$browser.poll(); + expect(scope.$cookies).toEqual({}); }); @@ -396,10 +405,11 @@ describe("service", function(){ }); - it('should turn non-string into String when creating a cookie', function() { + it('should ignore non-string values when asked to create a cookie', function() { scope.$cookies.nonString = [1, 2, 3]; scope.$eval(); - expect(scope.$browser.cookies()).toEqual({'nonString':'1,2,3'}); + expect(scope.$browser.cookies()).toEqual({}); + expect(scope.$cookies).toEqual({}); }); @@ -425,10 +435,10 @@ describe("service", function(){ }); - describe('$sessionStore', function() { + describe('$cookieStore', function() { it('should serialize objects to json', function() { - scope.$sessionStore.put('objectCookie', {id: 123, name: 'blah'}); + scope.$cookieStore.put('objectCookie', {id: 123, name: 'blah'}); scope.$eval(); //force eval in test expect(scope.$browser.cookies()).toEqual({'objectCookie': '{"id":123,"name":"blah"}'}); }); @@ -437,12 +447,12 @@ describe("service", function(){ it('should deserialize json to object', function() { scope.$browser.cookies('objectCookie', '{"id":123,"name":"blah"}'); scope.$browser.poll(); - expect(scope.$sessionStore.get('objectCookie')).toEqual({id: 123, name: 'blah'}); + expect(scope.$cookieStore.get('objectCookie')).toEqual({id: 123, name: 'blah'}); }); it('should delete objects from the store when remove is called', function() { - scope.$sessionStore.put('gonner', { "I'll":"Be Back"}); + scope.$cookieStore.put('gonner', { "I'll":"Be Back"}); scope.$eval(); //force eval in test expect(scope.$browser.cookies()).toEqual({'gonner': '{"I\'ll":"Be Back"}'}); }); |
