Custom cookie serializer test

Adapted from
b23ffd0dac/actionpack/test/dispatch/cookies_test.rb (L382-L413)
This commit is contained in:
Greg Ose
2014-06-17 17:08:56 -05:00
committed by Charlie Somerville
parent 0342deaa22
commit 67b3fd5cb8

View File

@@ -63,6 +63,11 @@ class CookiesTest < ActionController::TestCase
head :ok
end
def set_signed_string_cookie
cookies.signed[:foo] = 'bar'
head :ok
end
def raise_data_overflow
cookies.signed[:foo] = 'bye!' * 1024
head :ok
@@ -332,6 +337,22 @@ class CookiesTest < ActionController::TestCase
}
end
class ActionDispatch::Session::CustomJsonSerializer
def self.load(value)
JSON.load(value) + " and loaded"
end
def self.dump(value)
JSON.dump(value + " was dumped")
end
end
def test_signed_cookie_using_serializer_object
@request.env["action_dispatch.session_serializer"] = ActionDispatch::Session::CustomJsonSerializer
get :set_signed_string_cookie
assert_equal 'bar was dumped and loaded', @controller.send(:cookies).signed[:foo]
end
def test_cookie_with_all_domain_option
get :set_cookie_with_domain
assert_response :success