1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

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>
This commit is contained in:
abcang 2020-01-11 03:48:42 +09:00 committed by Rafael França
parent 25a5b296a3
commit b9fac5c3d6
2 changed files with 8 additions and 2 deletions

View file

@ -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

View file

@ -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