This project is archived and is in readonly mode.
Cookie value set in functional test, key present in controller but unreadable
Reported by Marko Anastasov | January 10th, 2011 @ 02:19 PM | in 3.0.6
Initially I posted a message on rspec-users, but was told[0] that this sounds like a Rails bug.
I set a value in controller spec using @request.cookies:
https://gist.github.com/371356ba0a19666fd3b5
but when the controller reads it, it's nil somehow, even though
the key is present, as this screenshot from the debugger shows:
http://dl.dropbox.com/u/830772/p/Selection_033.jpeg
This happens in test environment only. Eventually I figured out that I can use request.cookies in controller to make it work. But it's strange that I need to.
I'm using RSpec 2.4 and Rails 3.0.3.
[0] http://rubyforge.org/pipermail/rspec-users/2011-January/019143.html
Comments and changes to this ticket
-
Andrew White March 5th, 2011 @ 12:19 PM
- State changed from new to open
- Milestone set to 3.0.6
- Assigned user set to Andrew White
- Importance changed from to Low
It looks as though this has been addressed in master somewhat, but you still need to use string keys when assigning the cookie in the request. The cookies hash is cached in the request and the symbol key is assigned. However the access in the controller is done using a string key and the nil value is cached in the hash so you end up with both the string and symbol keys in the cookies hash.
The fix is to clear the cookies instance variable when the request object is recycled, after first writing out the cookies to HTTP_COOKIE in the environment hash. AD::TestRequest.write_cookies! also needs fixing so that it escapes the cookie values as well.
I'll come up with a patch this weekend, in the meantime just assign cookie value using a string key.
-
Repository March 6th, 2011 @ 03:03 PM
- State changed from open to resolved
(from [e2523ff68309f444cd052031c1fe8a3030d2865a]) Improve testing of cookies in functional tests: - cookies can be set using string or symbol keys - cookies are preserved across calls to get, post, etc. - cookie names and values are escaped - cookies can be cleared using @request.cookies.clear
[#6272 state:resolved] https://github.com/rails/rails/commit/e2523ff68309f444cd052031c1fe8...
-
Repository March 6th, 2011 @ 03:03 PM
(from [31f09f9dbc1b8e598fc82d86b622167bfc01d18a]) Improve testing of cookies in functional tests: - cookies can be set using string or symbol keys - cookies are preserved across calls to get, post, etc. - cookie names and values are escaped - cookies can be cleared using @request.cookies.clear
[#6272 state:resolved] https://github.com/rails/rails/commit/31f09f9dbc1b8e598fc82d86b6221...
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Referenced by
- 6272 Cookie value set in functional test, key present in controller but unreadable [#6272 state:resolved] https://github.com/rails/rails/co...
- 6272 Cookie value set in functional test, key present in controller but unreadable [#6272 state:resolved] https://github.com/rails/rails/co...