Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delegate child session assertions to parent session #32143

Merged
merged 1 commit into from Dec 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions actionpack/CHANGELOG.md
@@ -1,3 +1,15 @@
* Include child session assertion count in ActionDispatch::IntegrationTest

`IntegrationTest#open_session` uses `dup` to create the new session, which
meant it had its own copy of `@assertions`. This prevented the assertions
from being correctly counted and reported.

Child sessions now have their `attr_accessor` overriden to delegate to the
root session.

Fixes #32142

*Sam Bostock*


Please check [6-0-stable](https://github.com/rails/rails/blob/6-0-stable/actionpack/CHANGELOG.md) for previous changes.
10 changes: 10 additions & 0 deletions actionpack/lib/action_dispatch/testing/integration.rb
Expand Up @@ -310,6 +310,7 @@ module Runner
APP_SESSIONS = {}

attr_reader :app
attr_accessor :root_session # :nodoc:

def initialize(*args, &blk)
super(*args, &blk)
Expand Down Expand Up @@ -373,10 +374,19 @@ def remove! # :nodoc:
def open_session
dup.tap do |session|
session.reset!
session.root_session = self.root_session || self
yield session if block_given?
end
end

def assertions # :nodoc:
root_session ? root_session.assertions : super
end

def assertions=(assertions) # :nodoc:
root_session ? root_session.assertions = assertions : super
end

# Copy the instance variables from the current session instance into the
# test instance.
def copy_session_variables! #:nodoc:
Expand Down
8 changes: 8 additions & 0 deletions actionpack/test/controller/integration_test.rb
Expand Up @@ -138,6 +138,14 @@ def test_opens_new_session
assert_not session1.equal?(session2)
end

def test_child_session_assertions_bubble_up_to_root
assertions_before = @test.assertions
@test.open_session.assert(true)
assertions_after = @test.assertions

assert_equal 1, assertions_after - assertions_before
end

# RSpec mixes Matchers (which has a #method_missing) into
# IntegrationTest's superclass. Make sure IntegrationTest does not
# try to delegate these methods to the session object.
Expand Down