From 16af631faeb73d4bfbd20b39221f43fd09f52f3c Mon Sep 17 00:00:00 2001 From: barbie-bot Date: Thu, 2 Apr 2026 19:06:45 +0000 Subject: [PATCH] Fix system tests blocked by HostAuthorization and overlapping element MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 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 --- config/environments/test.rb | 3 +++ test/system/users_test.rb | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/config/environments/test.rb b/config/environments/test.rb index 857297d..7325b16 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -58,4 +58,7 @@ Rails.application.configure do # config.action_view.annotate_rendered_view_with_filenames = true config.log_level = :info + + # Allow Capybara's dynamic test server host (127.0.0.1:) + config.hosts << '127.0.0.1' end diff --git a/test/system/users_test.rb b/test/system/users_test.rb index 070c514..2a5eab3 100644 --- a/test/system/users_test.rb +++ b/test/system/users_test.rb @@ -229,7 +229,7 @@ class UsersTest < ApplicationSystemTestCase user = User.find_by_email!(first(:link).text) inject_button_to first('td:not(.link)'), "update status", user_path(user), method: :patch, params: {user: {status: User.statuses.keys.sample}}, data: {turbo: false} - click_on "update status" + execute_script("arguments[0].click()", find_button("update status")) end assert_title 'The change you wanted was rejected (422)' end