Permalink
Browse files

Port cookies to new base

  • Loading branch information...
1 parent c90f613 commit f9dde8fe4e14e7750e9a00c666b052bb409ead05 @jeremy jeremy committed May 22, 2009
View
@@ -63,7 +63,6 @@ Rake::TestTask.new(:test_new_base_on_old_tests) do |t|
# Dir.glob( "test/{dispatch,template}/**/*_test.rb" ).sort +
# ==== Not ported
- # * cookie
# * filters
# * integration
# * render_js
@@ -73,7 +72,7 @@ Rake::TestTask.new(:test_new_base_on_old_tests) do |t|
# * view_paths
t.test_files = %w(
action_pack_assertions addresses_render assert_select
- base benchmark caching capture content_type dispatcher
+ base benchmark caching capture content_type cookie dispatcher
filter_params flash helper http_basic_authentication
http_digest_authentication layout logging mime_responds
record_identifier redirect render render_json render_other render_xml
@@ -35,9 +35,10 @@ module ActionController
autoload :HttpAuthentication, 'action_controller/base/http_authentication'
autoload :FilterParameterLogging, 'action_controller/base/filter_parameter_logging'
autoload :Translation, 'action_controller/translation'
+ autoload :Cookies, 'action_controller/base/cookies'
require 'action_controller/routing'
end
require 'action_dispatch'
-require 'action_view'
+require 'action_view'
@@ -26,6 +26,7 @@ class Base < Http
# Rails 2.x compatibility
include ActionController::Rails2Compatibility
+ include ActionController::Cookies
include ActionController::Session
include ActionController::Flash
include ActionController::Verification
@@ -4,44 +4,48 @@ class CookieTest < ActionController::TestCase
class TestController < ActionController::Base
def authenticate
cookies["user_name"] = "david"
+ head :ok
end
def set_with_with_escapable_characters
cookies["that & guy"] = "foo & bar => baz"
+ head :ok
end
def authenticate_for_fourteen_days
cookies["user_name"] = { "value" => "david", "expires" => Time.utc(2005, 10, 10,5) }
+ head :ok
end
def authenticate_for_fourteen_days_with_symbols
cookies[:user_name] = { :value => "david", :expires => Time.utc(2005, 10, 10,5) }
+ head :ok
end
def set_multiple_cookies
cookies["user_name"] = { "value" => "david", "expires" => Time.utc(2005, 10, 10,5) }
cookies["login"] = "XJ-122"
+ head :ok
end
def access_frozen_cookies
cookies["will"] = "work"
+ head :ok
end
def logout
cookies.delete("user_name")
+ head :ok
end
def delete_cookie_with_path
cookies.delete("user_name", :path => '/beaten')
- render :text => "hello world"
+ head :ok
end
def authenticate_with_http_only
cookies["user_name"] = { :value => "david", :httponly => true }
- end
-
- def rescue_action(e)
- raise unless ActionView::MissingTemplate # No templates here, and we don't care about the output
+ head :ok
end
end
@@ -54,38 +58,38 @@ def setup
def test_setting_cookie
get :authenticate
- assert_equal "user_name=david; path=/", @response.headers["Set-Cookie"]
+ assert_cookie_header "user_name=david; path=/"
assert_equal({"user_name" => "david"}, @response.cookies)
end
def test_setting_with_escapable_characters
get :set_with_with_escapable_characters
- assert_equal "that+%26+guy=foo+%26+bar+%3D%3E+baz; path=/", @response.headers["Set-Cookie"]
+ assert_cookie_header "that+%26+guy=foo+%26+bar+%3D%3E+baz; path=/"
assert_equal({"that & guy" => "foo & bar => baz"}, @response.cookies)
end
def test_setting_cookie_for_fourteen_days
get :authenticate_for_fourteen_days
- assert_equal "user_name=david; path=/; expires=Mon, 10-Oct-2005 05:00:00 GMT", @response.headers["Set-Cookie"]
+ assert_cookie_header "user_name=david; path=/; expires=Mon, 10-Oct-2005 05:00:00 GMT"
assert_equal({"user_name" => "david"}, @response.cookies)
end
def test_setting_cookie_for_fourteen_days_with_symbols
get :authenticate_for_fourteen_days_with_symbols
- assert_equal "user_name=david; path=/; expires=Mon, 10-Oct-2005 05:00:00 GMT", @response.headers["Set-Cookie"]
+ assert_cookie_header "user_name=david; path=/; expires=Mon, 10-Oct-2005 05:00:00 GMT"
assert_equal({"user_name" => "david"}, @response.cookies)
end
def test_setting_cookie_with_http_only
get :authenticate_with_http_only
- assert_equal "user_name=david; path=/; HttpOnly", @response.headers["Set-Cookie"]
+ assert_cookie_header "user_name=david; path=/; HttpOnly"
assert_equal({"user_name" => "david"}, @response.cookies)
end
def test_multiple_cookies
get :set_multiple_cookies
assert_equal 2, @response.cookies.size
- assert_equal "user_name=david; path=/; expires=Mon, 10-Oct-2005 05:00:00 GMT\nlogin=XJ-122; path=/", @response.headers["Set-Cookie"]
+ assert_cookie_header "user_name=david; path=/; expires=Mon, 10-Oct-2005 05:00:00 GMT\nlogin=XJ-122; path=/"
assert_equal({"login" => "XJ-122", "user_name" => "david"}, @response.cookies)
end
@@ -95,7 +99,7 @@ def test_setting_test_cookie
def test_expiring_cookie
get :logout
- assert_equal "user_name=; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT", @response.headers["Set-Cookie"]
+ assert_cookie_header "user_name=; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT"
assert_equal({"user_name" => nil}, @response.cookies)
end
@@ -116,6 +120,16 @@ def test_cookiejar_accessor_with_array_value
def test_delete_cookie_with_path
get :delete_cookie_with_path
- assert_equal "user_name=; path=/beaten; expires=Thu, 01-Jan-1970 00:00:00 GMT", @response.headers["Set-Cookie"]
+ assert_cookie_header "user_name=; path=/beaten; expires=Thu, 01-Jan-1970 00:00:00 GMT"
end
+
+ private
+ def assert_cookie_header(expected)
+ header = @response.headers["Set-Cookie"]
+ if header.respond_to?(:to_str)
+ assert_equal expected, header
+ else
+ assert_equal expected.split("\n"), header
+ end
+ end
end

0 comments on commit f9dde8f

Please sign in to comment.