mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fix random failure on system test with ajax
If application has ajax, browser may begin request after rollback.
`teardown_fixtures` will be called after `super` on `after_teardown`
so we must call `Capybara.reset_sessions!` before `super`
b61a56541a/activerecord/lib/active_record/fixtures.rb (L857)
This commit is contained in:
parent
e1a72fef7d
commit
5edbdca5c0
2 changed files with 29 additions and 1 deletions
|
@ -11,8 +11,8 @@ module ActionDispatch
|
|||
|
||||
def after_teardown
|
||||
take_failed_screenshot
|
||||
super
|
||||
Capybara.reset_sessions!
|
||||
super
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -576,6 +576,34 @@ module ApplicationTests
|
|||
capture(:stderr) { run_test_command("test/models/warnings_test.rb -w") })
|
||||
end
|
||||
|
||||
def test_reset_sessions_before_rollback_on_system_tests
|
||||
app_file "test/system/reset_session_before_rollback_test.rb", <<-RUBY
|
||||
require "application_system_test_case"
|
||||
|
||||
class ResetSessionBeforeRollbackTest < ApplicationSystemTestCase
|
||||
def teardown_fixtures
|
||||
puts "rollback"
|
||||
super
|
||||
end
|
||||
|
||||
Capybara.singleton_class.prepend(Module.new do
|
||||
def reset_sessions!
|
||||
puts "reset sessions"
|
||||
super
|
||||
end
|
||||
end)
|
||||
|
||||
test "dummy" do
|
||||
end
|
||||
end
|
||||
RUBY
|
||||
|
||||
run_test_command("test/system/reset_session_before_rollback_test.rb").tap do |output|
|
||||
assert_match "reset sessions\nrollback", output
|
||||
assert_match "1 runs, 0 assertions, 0 failures, 0 errors, 0 skips", output
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def run_test_command(arguments = "test/unit/test_test.rb")
|
||||
Dir.chdir(app_path) { `bin/rails t #{arguments}` }
|
||||
|
|
Loading…
Reference in a new issue