vendor/rails/actionpack/test/controller/cookie_test.rb in radiant-0.9.1 vs vendor/rails/actionpack/test/controller/cookie_test.rb in radiant-1.0.0.rc1
- old
+ new
@@ -40,10 +40,14 @@
def authenticate_with_http_only
cookies["user_name"] = { :value => "david", :httponly => true }
end
+ def authenticate_with_secure
+ cookies["user_name"] = { :value => "david", :secure => true }
+ end
+
def set_permanent_cookie
cookies.permanent[:user_name] = "Jamie"
end
def set_signed_cookie
@@ -93,10 +97,31 @@
get :authenticate_with_http_only
assert_equal ["user_name=david; path=/; HttpOnly"], @response.headers["Set-Cookie"]
assert_equal({"user_name" => "david"}, @response.cookies)
end
+ def test_setting_cookie_with_secure
+ @request.env["HTTPS"] = "on"
+ get :authenticate_with_secure
+ assert_equal ["user_name=david; path=/; secure"], @response.headers["Set-Cookie"]
+ assert_equal({"user_name" => "david"}, @response.cookies)
+ end
+
+ def test_setting_cookie_with_secure_in_development
+ with_environment(:development) do
+ get :authenticate_with_secure
+ assert_equal ["user_name=david; path=/; secure"], @response.headers["Set-Cookie"]
+ assert_equal({"user_name" => "david"}, @response.cookies)
+ end
+ end
+
+ def test_not_setting_cookie_with_secure
+ get :authenticate_with_secure
+ assert_not_equal ["user_name=david; path=/; secure"], @response.headers["Set-Cookie"]
+ assert_not_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", @response.headers["Set-Cookie"][0]
assert_equal "login=XJ-122; path=/", @response.headers["Set-Cookie"][1]
@@ -165,6 +190,19 @@
def test_permanent_signed_cookie
get :set_permanent_signed_cookie
assert_match %r(#{20.years.from_now.year}), @response.headers["Set-Cookie"].first
assert_equal 100, @controller.send(:cookies).signed[:remember_me]
end
+
+ private
+ def with_environment(enviroment)
+ old_rails = Object.const_get(:Rails) rescue nil
+ mod = Object.const_set(:Rails, Module.new)
+ (class << mod; self; end).instance_eval do
+ define_method(:env) { @_env ||= ActiveSupport::StringInquirer.new(enviroment.to_s) }
+ end
+ yield
+ ensure
+ Object.module_eval { remove_const(:Rails) } if defined?(Rails)
+ Object.const_set(:Rails, old_rails) if old_rails
+ end
end
\ No newline at end of file