From ac9c60cf324ae76bf4617228a0b661b55605c649 Mon Sep 17 00:00:00 2001
From: Theodor Tonum
Date: Wed, 26 Jun 2024 12:41:35 +0200
Subject: [PATCH] RackTest nodes should not submit when disabled
---
lib/capybara/rack_test/node.rb | 1 +
lib/capybara/spec/views/form.erb | 5 ++++-
spec/rack_test_spec.rb | 6 ++++++
3 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/lib/capybara/rack_test/node.rb b/lib/capybara/rack_test/node.rb
index 361041a7b..734d18faa 100644
--- a/lib/capybara/rack_test/node.rb
+++ b/lib/capybara/rack_test/node.rb
@@ -271,6 +271,7 @@ def link?
end
def submits?
+ return false if disabled?
(tag_name == 'input' && %w[submit image].include?(type)) || (tag_name == 'button' && [nil, 'submit'].include?(type))
end
diff --git a/lib/capybara/spec/views/form.erb b/lib/capybara/spec/views/form.erb
index 96520eb34..ab4000dab 100644
--- a/lib/capybara/spec/views/form.erb
+++ b/lib/capybara/spec/views/form.erb
@@ -474,7 +474,6 @@ New line after and before textarea tag
role=button within label element
with other text
-
ARIA button
@@ -742,3 +741,7 @@ New line after and before textarea tag
Visual representation of the checkbox
+
+
diff --git a/spec/rack_test_spec.rb b/spec/rack_test_spec.rb
index d4168af4a..31da7cfc1 100644
--- a/spec/rack_test_spec.rb
+++ b/spec/rack_test_spec.rb
@@ -148,6 +148,12 @@ module TestSessions
expect(session).not_to have_current_path(/foo|bar/)
end
end
+
+ it 'does not click disabled inputs or buttons' do
+ session.visit('/form')
+ session.find(:css, 'input[value="Disabled button"]').click
+ expect(session).to have_current_path('/form')
+ end
end
describe '#send_keys' do