Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Allow symbols to be used as keys for setting cookies

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@21 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit defda16b834ffc4a78def1c4b6c2299b754fe901 1 parent d0c9033
@dhh dhh authored
View
5 actionpack/lib/action_controller/cookies.rb
@@ -4,14 +4,14 @@ module ActionController #:nodoc:
# itself back -- just the value it holds). Examples for writting:
#
# cookies["user_name"] = "david" # => Will set a simple session cookie
- # cookies["login"] = { "value" => "XJ-122", "expires" => Time.now + 360} # => Will set a cookie that expires in 1 hour
+ # cookies["login"] = { :value => "XJ-122", :expires => Time.now + 360} # => Will set a cookie that expires in 1 hour
#
# Examples for reading:
#
# cookies["user_name"] # => "david"
# cookies.size # => 2
#
- # All the options for setting cookies are:
+ # All the option symbols for setting cookies are:
#
# value:: the cookie's value or list of values (as an array).
# path:: the path for which this cookie applies. Defaults to the root of the application.
@@ -41,6 +41,7 @@ def [](name)
def []=(name, options)
if options.is_a?(Hash)
+ options.each { |key, value| options[key.to_s] = value }
options["name"] = name
else
options = [ name, options ]
View
10 actionpack/test/controller/cookie_test.rb
@@ -17,6 +17,11 @@ def authenticate_for_fourten_days
render_text "hello world"
end
+ def authenticate_for_fourten_days_with_symbols
+ cookies["user_name"] = { :value => "david", :expires => Time.local(2005, 10, 10) }
+ render_text "hello world"
+ end
+
def set_multiple_cookies
cookies["user_name"] = { "value" => "david", "expires" => Time.local(2005, 10, 10) }
cookies["login"] = "XJ-122"
@@ -52,6 +57,11 @@ def test_setting_cookie_for_fourteen_days
assert_equal [ CGI::Cookie::new("name" => "user_name", "value" => "david", "expires" => Time.local(2005, 10, 10)) ], process_request.headers["cookie"]
end
+ def test_setting_cookie_for_fourteen_days_with_symbols
+ @request.action = "authenticate_for_fourten_days"
+ assert_equal [ CGI::Cookie::new("name" => "user_name", "value" => "david", "expires" => Time.local(2005, 10, 10)) ], process_request.headers["cookie"]
+ end
+
def test_multiple_cookies
@request.action = "set_multiple_cookies"
assert_equal 2, process_request.headers["cookie"].size
Please sign in to comment.
Something went wrong with that request. Please try again.