On Wed, Jul 2, 2008 at 4:06 AM, David C. [email protected]
wrote:
This is just one of those goofy things in Rails testing. I’m not sure
the best way to make it easier in rspec without breaking existing
examples in the process. Regardless, here’s how you interact with
cookies from an example:
To set a cookie:
request.cookies[:cookie_key] = CGI::Cookie.new(‘cookie_key’, ‘cookie value’)
When I do this, in order to get to this cookie in my controller code,
I have to do
cookies[:cookie_key][:cookie_key]
Basically, it appears that what it does is assign that key a hash of
its own. That makes sense of course, as I realize a cookie is really
a hash of name, value, path, expires, and so on. However, it doesn’t
jive with the retrieval, as you shouldn’t have to double reference it
(which I believe is essentially the point of the [] method on
ActionController::CookieJar and is not how things are documented).
However, what’s really behaving weird, is if I do:
cookies[:cookie_key] = “1234”
Then, in my controller code, if I look at “cookies”, it shows that
cookies is a hash, and if I call .keys on it, it spits out
“:cookie_key”, and if I call .values on it, it says “1234”, but if I
then go and do cookies[:cookie_key], it gives me nil.
Again, I have to suspect something weird going on with Rails test
environment/RSpec, since all this works fine outside of tests. Any
suggestions on how to debug this further or what might be wrong?
I should note I’m using Rails 2.1, and RSpec and rspec-rails from
about a week ago (from GitHub).
however, as I’ve been known to try to set a cookie in an example using
cookies when I should have been using request.cookies. So I try to
keep them explicit.
HTH,
David
rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users
–
Christopher B.
Cobalt Edge LLC
http://cobaltedge.com