1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00

Query rewriting in rack_test form submission

This commit is contained in:
Thomas Walpole 2020-02-17 11:14:51 -08:00
parent f05a2a033a
commit 6dc1615504
3 changed files with 18 additions and 1 deletions

View file

@ -30,7 +30,9 @@ class Capybara::RackTest::Browser
def submit(method, path, attributes) def submit(method, path, attributes)
path = request_path if path.nil? || path.empty? 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 end
def follow(method, path, **attributes) def follow(method, path, **attributes)

View file

@ -517,6 +517,7 @@ New line after and before textarea tag
<p> <p>
<input type="submit" name="form[mediocre]" id="mediocre" value="med" aria-label="Mediocre Button"/> <input type="submit" name="form[mediocre]" id="mediocre" value="med" aria-label="Mediocre Button"/>
<input type="submit" formaction="/form/get?bar=foo" id="mediocre2" value="med2"/>
<p> <p>
</form> </form>

View file

@ -127,6 +127,20 @@ RSpec.describe Capybara::Session do # rubocop:disable RSpec/MultipleDescribes
session.find(:label, 'Female').click session.find(:label, 'Female').click
expect(session).to have_unchecked_field('gender_male') expect(session).to have_unchecked_field('gender_male')
end 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
end end