diff options
| author | Igor Minar | 2010-09-25 15:29:48 -0700 |
|---|---|---|
| committer | Igor Minar | 2010-09-26 23:54:31 -0700 |
| commit | 3eec8c1a517f8b93a5afd15b7f83b33c5df7e54b (patch) | |
| tree | 9d9574d2245257456966bb0d15853f8f0d620958 /test/servicesSpec.js | |
| parent | 9171a2b2b50d0a8217c98e0017a7d2a0a1a37380 (diff) | |
| download | angular.js-3eec8c1a517f8b93a5afd15b7f83b33c5df7e54b.tar.bz2 | |
Properly initialize cookie service in order to preserve existing cookies
- previously the poller initialized the cookie cache too late which
was causing previously existing cookies to be deleted by cookie service
- refactored the poller api so that the addPollFn returns the added fn
- fixed older cookie service tests
- removed "this.$onEval(PRIORITY_LAST, update);" because it is not needed
Diffstat (limited to 'test/servicesSpec.js')
| -rw-r--r-- | test/servicesSpec.js | 42 |
1 files changed, 28 insertions, 14 deletions
diff --git a/test/servicesSpec.js b/test/servicesSpec.js index 3416f0ea..258af46b 100644 --- a/test/servicesSpec.js +++ b/test/servicesSpec.js @@ -373,22 +373,33 @@ describe("service", function(){ describe('$cookies', function() { + var scope; + + beforeEach(function() { + var browser = new MockBrowser(); + browser.cookieHash['preexisting'] = 'oldCookie'; + scope = createScope(null, angularService, {$browser: browser}); + }); + + it('should provide access to existing cookies via object properties and keep them in sync', function(){ - expect(scope.$cookies).toEqual({}); + expect(scope.$cookies).toEqual({'preexisting': 'oldCookie'}); - scope.$browser.cookies('brandNew', 'cookie'); + // access internal cookie storage of the browser mock directly to simulate behavior of + // document.cookie + scope.$browser.cookieHash['brandNew'] = 'cookie'; scope.$browser.poll(); - expect(scope.$cookies).toEqual({'brandNew':'cookie'}); + expect(scope.$cookies).toEqual({'preexisting': 'oldCookie', 'brandNew':'cookie'}); - scope.$browser.cookies('brandNew', 'cookie2'); + scope.$browser.cookieHash['brandNew'] = 'cookie2'; scope.$browser.poll(); - expect(scope.$cookies).toEqual({'brandNew':'cookie2'}); + expect(scope.$cookies).toEqual({'preexisting': 'oldCookie', 'brandNew':'cookie2'}); - scope.$browser.cookies('brandNew', undefined); + delete scope.$browser.cookieHash['brandNew']; scope.$browser.poll(); - expect(scope.$cookies).toEqual({}); + expect(scope.$cookies).toEqual({'preexisting': 'oldCookie'}); }); @@ -396,20 +407,22 @@ describe("service", function(){ scope.$cookies.oatmealCookie = 'nom nom'; scope.$eval(); - expect(scope.$browser.cookies()).toEqual({'oatmealCookie':'nom nom'}); + expect(scope.$browser.cookies()). + toEqual({'preexisting': 'oldCookie', 'oatmealCookie':'nom nom'}); scope.$cookies.oatmealCookie = 'gone'; scope.$eval(); - expect(scope.$browser.cookies()).toEqual({'oatmealCookie':'gone'}); + expect(scope.$browser.cookies()). + toEqual({'preexisting': 'oldCookie', 'oatmealCookie': 'gone'}); }); 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({}); - expect(scope.$cookies).toEqual({}); + expect(scope.$browser.cookies()).toEqual({'preexisting': 'oldCookie'}); + expect(scope.$cookies).toEqual({'preexisting': 'oldCookie'}); }); @@ -418,19 +431,20 @@ describe("service", function(){ scope.$cookies.undefVal = undefined; scope.$eval(); - expect(scope.$browser.cookies()).toEqual({}); + expect(scope.$browser.cookies()).toEqual({'preexisting': 'oldCookie'}); }); it('should remove a cookie when a $cookies property is deleted', function() { scope.$cookies.oatmealCookie = 'nom nom'; scope.$eval(); - expect(scope.$browser.cookies()).toEqual({'oatmealCookie':'nom nom'}); + expect(scope.$browser.cookies()). + toEqual({'preexisting': 'oldCookie', 'oatmealCookie':'nom nom'}); delete scope.$cookies.oatmealCookie; scope.$eval(); - expect(scope.$browser.cookies()).toEqual({}); + expect(scope.$browser.cookies()).toEqual({'preexisting': 'oldCookie'}); }); }); |
