diff --git a/lib/capybara/rack_test/browser.rb b/lib/capybara/rack_test/browser.rb index d2d583d3..4e4e23b1 100644 --- a/lib/capybara/rack_test/browser.rb +++ b/lib/capybara/rack_test/browser.rb @@ -30,7 +30,9 @@ class Capybara::RackTest::Browser def submit(method, path, attributes) path = request_path if path.nil? || path.empty? - process_and_follow_redirects(method, path, attributes, 'HTTP_REFERER' => current_url) + uri = build_uri(path) + uri.query = '' if method&.to_s&.downcase == 'get' + process_and_follow_redirects(method, uri.to_s, attributes, 'HTTP_REFERER' => current_url) end def follow(method, path, **attributes) diff --git a/lib/capybara/spec/views/form.erb b/lib/capybara/spec/views/form.erb index 28c96ab7..7e2f97e9 100644 --- a/lib/capybara/spec/views/form.erb +++ b/lib/capybara/spec/views/form.erb @@ -517,6 +517,7 @@ New line after and before textarea tag

+

diff --git a/spec/rack_test_spec.rb b/spec/rack_test_spec.rb index 6419bac2..031d0304 100644 --- a/spec/rack_test_spec.rb +++ b/spec/rack_test_spec.rb @@ -127,6 +127,20 @@ RSpec.describe Capybara::Session do # rubocop:disable RSpec/MultipleDescribes session.find(:label, 'Female').click expect(session).to have_unchecked_field('gender_male') end + + it 'should rewrite the forms action query for get submission' do + session.visit('/form') + session.click_button('mediocre') + puts session.current_url + expect(session).not_to have_current_path(/foo|bar/) + end + + it 'should rewrite the submit buttons formaction query for get submission' do + session.visit('/form') + session.click_button('mediocre2') + puts session.current_url + expect(session).not_to have_current_path(/foo|bar/) + end end end