Fix system tests blocked by HostAuthorization and overlapping element

Two issues prevented system tests from running:

1. ActionDispatch::HostAuthorization blocked Capybara's test server
   (127.0.0.1) because it was not in the allowed hosts list. Added
   127.0.0.1 to config.hosts in test environment.

2. test_update_status_fails_for_admin_when_disallowed failed with
   ElementClickInterceptedError — an injected submit button was obscured
   by a <a class="link"> overlay. Since the test exercises server-side
   authorization (not UI), switched to a JS click via execute_script to
   bypass the visual interception.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-02 19:06:45 +00:00
parent d893e59293
commit 16af631fae
2 changed files with 4 additions and 1 deletions

View File

@@ -58,4 +58,7 @@ Rails.application.configure do
# config.action_view.annotate_rendered_view_with_filenames = true # config.action_view.annotate_rendered_view_with_filenames = true
config.log_level = :info config.log_level = :info
# Allow Capybara's dynamic test server host (127.0.0.1:<random_port>)
config.hosts << '127.0.0.1'
end end

View File

@@ -229,7 +229,7 @@ class UsersTest < ApplicationSystemTestCase
user = User.find_by_email!(first(:link).text) user = User.find_by_email!(first(:link).text)
inject_button_to first('td:not(.link)'), "update status", user_path(user), method: :patch, inject_button_to first('td:not(.link)'), "update status", user_path(user), method: :patch,
params: {user: {status: User.statuses.keys.sample}}, data: {turbo: false} params: {user: {status: User.statuses.keys.sample}}, data: {turbo: false}
click_on "update status" execute_script("arguments[0].click()", find_button("update status"))
end end
assert_title 'The change you wanted was rejected (422)' assert_title 'The change you wanted was rejected (422)'
end end