mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fix ActionDispatch::IntegrationTest#open_session
Reset a new session directly after its creation in
`ActionDispatch::IntegrationTest#open_session`. Reset the session to a clean
state before making it available to the client's test code.
Issue #22742 reports unexpected behavior of integration tests that run multiple
sessions. For example an `ActionDispatch::Flash` instance is shared across
multiple sessions, though a client code will rightfully assume that each new
session has its own flash hash.
The following test failed due to this behavior:
class Issue22742Test < ActionDispatch::IntegrationTest
test 'issue #22742' do
integration_session # initialize first session
a = open_session
b = open_session
refute_same(a.integration_session, b.integration_session)
end
end
Instead of creating a new `ActionDispatch::Integration::Session` instance,
the same instance is shared across all newly opened test sessions. This is
due to the way how new test sessions are created in
`ActionDispatch::IntegrationTest#open_session`. The already existing
`ActionDispatch::IntegrationTest` instance is duplicated with `Object#dup`,
This approach was introduced in commit 15c31c7639
. `Object#dup` copies the
instance variables, but not the objects they reference. Therefore this issue
only occurred when the current test instance had been tapped in such a way that
the instance variable `@integration_session` was initialized before creating the
new test session.
Close #22742
[Tawan Sierek + Sina Sadeghian]
This commit is contained in:
parent
8dbc1ca339
commit
064744bef6
3 changed files with 15 additions and 0 deletions
|
@ -368,6 +368,7 @@ module ActionDispatch
|
||||||
# simultaneously.
|
# simultaneously.
|
||||||
def open_session
|
def open_session
|
||||||
dup.tap do |session|
|
dup.tap do |session|
|
||||||
|
session.reset!
|
||||||
yield session if block_given?
|
yield session if block_given?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -356,6 +356,14 @@ class IntegrationProcessTest < ActionDispatch::IntegrationTest
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "creation of multiple integration sessions" do
|
||||||
|
integration_session # initialize first session
|
||||||
|
a = open_session
|
||||||
|
b = open_session
|
||||||
|
|
||||||
|
refute_same(a.integration_session, b.integration_session)
|
||||||
|
end
|
||||||
|
|
||||||
def test_get_with_query_string
|
def test_get_with_query_string
|
||||||
with_test_route_set do
|
with_test_route_set do
|
||||||
get "/get_with_params?foo=bar"
|
get "/get_with_params?foo=bar"
|
||||||
|
|
|
@ -1,3 +1,9 @@
|
||||||
|
* Reset a new session directly after its creation in ActionDispatch::IntegrationTest#open_session
|
||||||
|
|
||||||
|
Fixes Issue #22742
|
||||||
|
|
||||||
|
*Tawan Sierek*
|
||||||
|
|
||||||
* Add `:skip_sprockets` to `Rails::PluginBuilder::PASSTHROUGH_OPTIONS`
|
* Add `:skip_sprockets` to `Rails::PluginBuilder::PASSTHROUGH_OPTIONS`
|
||||||
|
|
||||||
*Tsukuru Tanimichi*
|
*Tsukuru Tanimichi*
|
||||||
|
|
Loading…
Reference in a new issue