mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Merge pull request #2312 from teamcapybara/rack_form_submit
Rack form submit - Fix Issue #2311
This commit is contained in:
commit
ec658052a0
9 changed files with 79 additions and 45 deletions
|
@ -162,5 +162,8 @@ RSpec/FilePath:
|
|||
RSpec/PredicateMatcher:
|
||||
Enabled: false
|
||||
|
||||
# RSpec/InstanceVariable:
|
||||
# Enabled: false
|
||||
|
||||
Capybara/FeatureMethods:
|
||||
Enabled: false
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -451,32 +451,35 @@ Capybara::SpecHelper.spec '#find' do
|
|||
context 'with spatial filters', requires: [:spatial] do
|
||||
before do
|
||||
@session.visit('/spatial')
|
||||
@center = @session.find(:css, 'div.center')
|
||||
end
|
||||
|
||||
let :center do
|
||||
@session.find(:css, 'div.center')
|
||||
end
|
||||
|
||||
it 'should find an element above another element' do
|
||||
expect(@session.find(:css, 'div:not(.corner)', above: @center).text).to eq('2')
|
||||
expect(@session.find(:css, 'div:not(.corner)', above: center).text).to eq('2')
|
||||
end
|
||||
|
||||
it 'should find an element below another element' do
|
||||
expect(@session.find(:css, 'div:not(.corner):not(.footer)', below: @center).text).to eq('8')
|
||||
expect(@session.find(:css, 'div:not(.corner):not(.footer)', below: center).text).to eq('8')
|
||||
end
|
||||
|
||||
it 'should find an element left of another element' do
|
||||
expect(@session.find(:css, 'div:not(.corner)', left_of: @center).text).to eq('4')
|
||||
expect(@session.find(:css, 'div:not(.corner)', left_of: center).text).to eq('4')
|
||||
end
|
||||
|
||||
it 'should find an element right of another element' do
|
||||
expect(@session.find(:css, 'div:not(.corner)', right_of: @center).text).to eq('6')
|
||||
expect(@session.find(:css, 'div:not(.corner)', right_of: center).text).to eq('6')
|
||||
end
|
||||
|
||||
it 'should combine spatial filters' do
|
||||
expect(@session.find(:css, 'div', left_of: @center, above: @center).text).to eq('1')
|
||||
expect(@session.find(:css, 'div', right_of: @center, below: @center).text).to eq('9')
|
||||
expect(@session.find(:css, 'div', left_of: center, above: center).text).to eq('1')
|
||||
expect(@session.find(:css, 'div', right_of: center, below: center).text).to eq('9')
|
||||
end
|
||||
|
||||
it 'should find an element "near" another element' do
|
||||
expect(@session.find(:css, 'div.distance', near: @center).text).to eq('2')
|
||||
expect(@session.find(:css, 'div.distance', near: center).text).to eq('2')
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -234,18 +234,21 @@ Capybara::SpecHelper.spec '#has_css?' do
|
|||
context 'with spatial requirements', requires: [:spatial] do
|
||||
before do
|
||||
@session.visit('/spatial')
|
||||
@center = @session.find(:css, '.center')
|
||||
end
|
||||
|
||||
let :center do
|
||||
@session.find(:css, '.center')
|
||||
end
|
||||
|
||||
it 'accepts spatial options' do
|
||||
expect(@session).to have_css('div', above: @center).thrice
|
||||
expect(@session).to have_css('div', above: @center, right_of: @center).once
|
||||
expect(@session).to have_css('div', above: center).thrice
|
||||
expect(@session).to have_css('div', above: center, right_of: center).once
|
||||
end
|
||||
|
||||
it 'supports spatial sugar' do
|
||||
expect(@session).to have_css('div').left_of(@center).thrice
|
||||
expect(@session).to have_css('div').below(@center).right_of(@center).once
|
||||
expect(@session).to have_css('div').near(@center).exactly(8).times
|
||||
expect(@session).to have_css('div').left_of(center).thrice
|
||||
expect(@session).to have_css('div').below(center).right_of(center).once
|
||||
expect(@session).to have_css('div').near(center).exactly(8).times
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -808,7 +808,10 @@ Capybara::SpecHelper.spec 'node' do
|
|||
context 'offset', requires: [:js] do
|
||||
before do
|
||||
@session.visit('/offset')
|
||||
@clicker = @session.find(:id, 'clicker')
|
||||
end
|
||||
|
||||
let :clicker do
|
||||
@session.find(:id, 'clicker')
|
||||
end
|
||||
|
||||
context 'when w3c_click_offset is false' do
|
||||
|
@ -817,17 +820,17 @@ Capybara::SpecHelper.spec 'node' do
|
|||
end
|
||||
|
||||
it 'should offset from top left of element' do
|
||||
@clicker.click(x: 10, y: 5)
|
||||
clicker.click(x: 10, y: 5)
|
||||
expect(@session).to have_text(/clicked at 110,105/)
|
||||
end
|
||||
|
||||
it 'should offset outside the element' do
|
||||
@clicker.click(x: -15, y: -10)
|
||||
clicker.click(x: -15, y: -10)
|
||||
expect(@session).to have_text(/clicked at 85,90/)
|
||||
end
|
||||
|
||||
it 'should default to click the middle' do
|
||||
@clicker.click
|
||||
clicker.click
|
||||
expect(@session).to have_text(/clicked at 150,150/)
|
||||
end
|
||||
end
|
||||
|
@ -838,17 +841,17 @@ Capybara::SpecHelper.spec 'node' do
|
|||
end
|
||||
|
||||
it 'should offset from center of element' do
|
||||
@clicker.click(x: 10, y: 5)
|
||||
clicker.click(x: 10, y: 5)
|
||||
expect(@session).to have_text(/clicked at 160,155/)
|
||||
end
|
||||
|
||||
it 'should offset outside from center of element' do
|
||||
@clicker.click(x: -65, y: -60)
|
||||
clicker.click(x: -65, y: -60)
|
||||
expect(@session).to have_text(/clicked at 85,90/)
|
||||
end
|
||||
|
||||
it 'should default to click the middle' do
|
||||
@clicker.click
|
||||
clicker.click
|
||||
expect(@session).to have_text(/clicked at 150,150/)
|
||||
end
|
||||
end
|
||||
|
@ -891,7 +894,10 @@ Capybara::SpecHelper.spec 'node' do
|
|||
context 'offset', requires: [:js] do
|
||||
before do
|
||||
@session.visit('/offset')
|
||||
@clicker = @session.find(:id, 'clicker')
|
||||
end
|
||||
|
||||
let :clicker do
|
||||
@session.find(:id, 'clicker')
|
||||
end
|
||||
|
||||
context 'when w3c_click_offset is false' do
|
||||
|
@ -900,17 +906,17 @@ Capybara::SpecHelper.spec 'node' do
|
|||
end
|
||||
|
||||
it 'should offset from top left of element' do
|
||||
@clicker.double_click(x: 10, y: 5)
|
||||
clicker.double_click(x: 10, y: 5)
|
||||
expect(@session).to have_text(/clicked at 110,105/)
|
||||
end
|
||||
|
||||
it 'should offset outside the element' do
|
||||
@clicker.double_click(x: -15, y: -10)
|
||||
clicker.double_click(x: -15, y: -10)
|
||||
expect(@session).to have_text(/clicked at 85,90/)
|
||||
end
|
||||
|
||||
it 'should default to click the middle' do
|
||||
@clicker.double_click
|
||||
clicker.double_click
|
||||
expect(@session).to have_text(/clicked at 150,150/)
|
||||
end
|
||||
end
|
||||
|
@ -921,17 +927,17 @@ Capybara::SpecHelper.spec 'node' do
|
|||
end
|
||||
|
||||
it 'should offset from center of element' do
|
||||
@clicker.double_click(x: 10, y: 5)
|
||||
clicker.double_click(x: 10, y: 5)
|
||||
expect(@session).to have_text(/clicked at 160,155/)
|
||||
end
|
||||
|
||||
it 'should offset outside from center of element' do
|
||||
@clicker.double_click(x: -65, y: -60)
|
||||
clicker.double_click(x: -65, y: -60)
|
||||
expect(@session).to have_text(/clicked at 85,90/)
|
||||
end
|
||||
|
||||
it 'should default to click the middle' do
|
||||
@clicker.double_click
|
||||
clicker.double_click
|
||||
expect(@session).to have_text(/clicked at 150,150/)
|
||||
end
|
||||
end
|
||||
|
@ -974,7 +980,10 @@ Capybara::SpecHelper.spec 'node' do
|
|||
context 'offset', requires: [:js] do
|
||||
before do
|
||||
@session.visit('/offset')
|
||||
@clicker = @session.find(:id, 'clicker')
|
||||
end
|
||||
|
||||
let :clicker do
|
||||
@session.find(:id, 'clicker')
|
||||
end
|
||||
|
||||
context 'when w3c_click_offset is false' do
|
||||
|
@ -983,17 +992,17 @@ Capybara::SpecHelper.spec 'node' do
|
|||
end
|
||||
|
||||
it 'should offset from top left of element' do
|
||||
@clicker.right_click(x: 10, y: 5)
|
||||
clicker.right_click(x: 10, y: 5)
|
||||
expect(@session).to have_text(/clicked at 110,105/)
|
||||
end
|
||||
|
||||
it 'should offset outside the element' do
|
||||
@clicker.right_click(x: -15, y: -10)
|
||||
clicker.right_click(x: -15, y: -10)
|
||||
expect(@session).to have_text(/clicked at 85,90/)
|
||||
end
|
||||
|
||||
it 'should default to click the middle' do
|
||||
@clicker.right_click
|
||||
clicker.right_click
|
||||
expect(@session).to have_text(/clicked at 150,150/)
|
||||
end
|
||||
end
|
||||
|
@ -1004,17 +1013,17 @@ Capybara::SpecHelper.spec 'node' do
|
|||
end
|
||||
|
||||
it 'should offset from center of element' do
|
||||
@clicker.right_click(x: 10, y: 5)
|
||||
clicker.right_click(x: 10, y: 5)
|
||||
expect(@session).to have_text(/clicked at 160,155/)
|
||||
end
|
||||
|
||||
it 'should offset outside from center of element' do
|
||||
@clicker.right_click(x: -65, y: -60)
|
||||
clicker.right_click(x: -65, y: -60)
|
||||
expect(@session).to have_text(/clicked at 85,90/)
|
||||
end
|
||||
|
||||
it 'should default to click the middle' do
|
||||
@clicker.right_click
|
||||
clicker.right_click
|
||||
expect(@session).to have_text(/clicked at 150,150/)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -141,12 +141,12 @@ Capybara::SpecHelper.spec Capybara::Window, requires: [:windows] do
|
|||
end
|
||||
|
||||
describe '#maximize' do
|
||||
before do
|
||||
@initial_size = @session.current_window.size
|
||||
let! :initial_size do
|
||||
@session.current_window.size
|
||||
end
|
||||
|
||||
after do
|
||||
@session.current_window.resize_to(*@initial_size)
|
||||
@session.current_window.resize_to(*initial_size)
|
||||
sleep 0.5
|
||||
end
|
||||
|
||||
|
@ -176,7 +176,7 @@ Capybara::SpecHelper.spec Capybara::Window, requires: [:windows] do
|
|||
|
||||
expect(@session.current_window).to eq(orig_window)
|
||||
# Maximizing the browser affects all tabs so this may not be valid in real browsers
|
||||
# expect(@session.current_window.size).to eq(@initial_size)
|
||||
# expect(@session.current_window.size).to eq(initial_size)
|
||||
|
||||
ow_width, ow_height = other_window.size
|
||||
expect(ow_width).to be > 400
|
||||
|
@ -185,12 +185,12 @@ Capybara::SpecHelper.spec Capybara::Window, requires: [:windows] do
|
|||
end
|
||||
|
||||
describe '#fullscreen' do
|
||||
before do
|
||||
@initial_size = @session.current_window.size
|
||||
let! :initial_size do
|
||||
@session.current_window.size
|
||||
end
|
||||
|
||||
after do
|
||||
@session.current_window.resize_to(*@initial_size)
|
||||
@session.current_window.resize_to(*initial_size)
|
||||
sleep 1
|
||||
end
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ module Capybara
|
|||
RSpec.describe Capybara::Session, name, options do # rubocop:disable RSpec/EmptyExampleGroup
|
||||
include Capybara::SpecHelper
|
||||
include Capybara::RSpecMatchers
|
||||
# rubocop:disable RSpec/ScatteredSetup
|
||||
|
||||
before do |example|
|
||||
@session = session
|
||||
instance_exec(example, &filter_block) if filter_block
|
||||
|
@ -81,7 +81,6 @@ module Capybara
|
|||
before :each, :exact_false do
|
||||
Capybara.exact = false
|
||||
end
|
||||
# rubocop:enable RSpec/ScatteredSetup
|
||||
|
||||
specs.each do |spec_name, spec_options, block|
|
||||
describe spec_name, *spec_options do # rubocop:disable RSpec/EmptyExampleGroup
|
||||
|
|
|
@ -517,6 +517,7 @@ New line after and before textarea tag
|
|||
|
||||
<p>
|
||||
<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>
|
||||
</form>
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue