diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-03-07 08:50:50 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-03-07 08:50:50 -0800 |
commit | 9cee693213e0205cb5992728bb516215e34cb79f (patch) | |
tree | 097e97b585521c6d3eb7ae0d2e80b95c26603980 /actionpack/test/dispatch/cookies_test.rb | |
parent | 09d3e89cf0b3e7be03f97739e297fd40ebba1178 (diff) | |
parent | 2159e9eb64fd47635c84097e93f8708018e87751 (diff) | |
download | rails-9cee693213e0205cb5992728bb516215e34cb79f.tar.gz rails-9cee693213e0205cb5992728bb516215e34cb79f.tar.bz2 rails-9cee693213e0205cb5992728bb516215e34cb79f.zip |
Merge branch 'master' of github.com:rails/rails
* 'master' of github.com:rails/rails: (44 commits)
Fixed indentation in actionmailer base_test [#6538 state:committed]
remove unused assigned variable
removes merge conflicts
removes Examples headers introduced in 9b96de6
Revert "Fixed identation in actionmailer base_test"
Report the correct value of nil.id in the exception message as different ruby implementations may have different values, for example Rubinius returns 53 for nil.id.
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
more style changes
Some style changes
style changes
Revert "style changes"
Raise ArgumentError if route name is invalid [#6517 state:resolved]
style changes
Allow model to be inherited from Hash [#6487 state:resolved]
styles applied for usage
added failing test for fields_for with a record object that inherits from Hash
Fixed identation in actionmailer base_test
wrong SQL statement
commas to set off expressions that interrupt sentence flow
typo changes
...
Diffstat (limited to 'actionpack/test/dispatch/cookies_test.rb')
-rw-r--r-- | actionpack/test/dispatch/cookies_test.rb | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/actionpack/test/dispatch/cookies_test.rb b/actionpack/test/dispatch/cookies_test.rb index 1cfea6aa12..39159fd629 100644 --- a/actionpack/test/dispatch/cookies_test.rb +++ b/actionpack/test/dispatch/cookies_test.rb @@ -124,6 +124,20 @@ class CookiesTest < ActionController::TestCase cookies['user_name'] = "david" head :ok end + + def symbol_key_mock + cookies[:user_name] = "david" if cookies[:user_name] == "andrew" + head :ok + end + + def string_key_mock + cookies['user_name'] = "david" if cookies['user_name'] == "andrew" + head :ok + end + + def noop + head :ok + end end tests TestController @@ -411,6 +425,57 @@ class CookiesTest < ActionController::TestCase end end + def test_setting_request_cookies_is_indifferent_access + @request.cookies.clear + @request.cookies[:user_name] = "andrew" + get :string_key_mock + assert_equal "david", cookies[:user_name] + + @request.cookies.clear + @request.cookies['user_name'] = "andrew" + get :symbol_key_mock + assert_equal "david", cookies['user_name'] + end + + def test_cookies_retained_across_requests + get :symbol_key + assert_equal "user_name=david; path=/", @response.headers["Set-Cookie"] + assert_equal "david", cookies[:user_name] + + get :noop + assert_nil @response.headers["Set-Cookie"] + assert_equal "user_name=david", @request.env['HTTP_COOKIE'] + assert_equal "david", cookies[:user_name] + + get :noop + assert_nil @response.headers["Set-Cookie"] + assert_equal "user_name=david", @request.env['HTTP_COOKIE'] + assert_equal "david", cookies[:user_name] + end + + def test_cookies_can_be_cleared + get :symbol_key + assert_equal "user_name=david; path=/", @response.headers["Set-Cookie"] + assert_equal "david", cookies[:user_name] + + @request.cookies.clear + get :noop + assert_nil @response.headers["Set-Cookie"] + assert_nil @request.env['HTTP_COOKIE'] + assert_nil cookies[:user_name] + + get :symbol_key + assert_equal "user_name=david; path=/", @response.headers["Set-Cookie"] + assert_equal "david", cookies[:user_name] + end + + def test_cookies_are_escaped + @request.cookies[:user_ids] = '1;2' + get :noop + assert_equal "user_ids=1%3B2", @request.env['HTTP_COOKIE'] + assert_equal "1;2", cookies[:user_ids] + end + private def assert_cookie_header(expected) header = @response.headers["Set-Cookie"] |