From b9fac5c3d6fe4769cc83c3eeea6470725e068b51 Mon Sep 17 00:00:00 2001 From: abcang Date: Sat, 11 Jan 2020 03:48:42 +0900 Subject: [PATCH] Fix ActionController::TestSession#id to return Rack::Session::SessionId instance (#38063) * Fix ActionController::TestSession#id to return Rack::Session::SessionId instance * test SessionId#public_id * test session["session_id"] Co-authored-by: Benjamin Quorning <22333+bquorning@users.noreply.github.com> --- actionpack/lib/action_controller/test_case.rb | 4 ++-- actionpack/test/dispatch/session/test_session_test.rb | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index d5c1aaca12..a219bbdfa3 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -176,12 +176,12 @@ module ActionController # Methods #destroy and #load! are overridden to avoid calling methods on the # @store object, which does not exist for the TestSession class. - class TestSession < Rack::Session::Abstract::SessionHash #:nodoc: + class TestSession < Rack::Session::Abstract::PersistedSecure::SecureSessionHash #:nodoc: DEFAULT_OPTIONS = Rack::Session::Abstract::Persisted::DEFAULT_OPTIONS def initialize(session = {}) super(nil, nil) - @id = SecureRandom.hex(16) + @id = Rack::Session::SessionId.new(SecureRandom.hex(16)) @data = stringify_keys(session) @loaded = true end diff --git a/actionpack/test/dispatch/session/test_session_test.rb b/actionpack/test/dispatch/session/test_session_test.rb index 2d36990250..f3b1452d63 100644 --- a/actionpack/test/dispatch/session/test_session_test.rb +++ b/actionpack/test/dispatch/session/test_session_test.rb @@ -68,4 +68,10 @@ class ActionController::TestSessionTest < ActiveSupport::TestCase session = ActionController::TestSession.new(one: "1") assert_equal(2, session.fetch("2") { |key| key.to_i }) end + + def test_session_id + session = ActionController::TestSession.new + assert_instance_of String, session.id.public_id + assert_equal(session.id.public_id, session["session_id"]) + end end