mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Ensure rack_test driver processes 307/308 redirects correctly
This commit is contained in:
parent
cc43b63037
commit
3a300955f5
4 changed files with 27 additions and 1 deletions
|
@ -44,7 +44,13 @@ class Capybara::RackTest::Browser
|
|||
return unless driver.follow_redirects?
|
||||
|
||||
driver.redirect_limit.times do
|
||||
process(:get, last_response["Location"], {}, env) if last_response.redirect?
|
||||
if last_response.redirect?
|
||||
if [307, 308].include? last_response.status
|
||||
process(last_request.request_method, last_response["Location"], last_request.params, env)
|
||||
else
|
||||
process(:get, last_response["Location"], {}, env)
|
||||
end
|
||||
end
|
||||
end
|
||||
raise Capybara::InfiniteRedirectError, "redirected more than #{driver.redirect_limit} times, check for infinite redirects." if last_response.redirect?
|
||||
end
|
||||
|
|
|
@ -396,6 +396,11 @@ Capybara::SpecHelper.spec '#click_button' do
|
|||
expect(@session.current_url).to match(%r{/landed$})
|
||||
end
|
||||
|
||||
it "should follow redirects that maintain method" do
|
||||
@session.click_button('Go 307')
|
||||
expect(@session).to have_content('You post landed: 307')
|
||||
end
|
||||
|
||||
it "should post pack to the same URL when no action given" do
|
||||
@session.visit('/postback')
|
||||
@session.click_button('With no action')
|
||||
|
|
|
@ -38,6 +38,10 @@ class TestApp < Sinatra::Base
|
|||
redirect '/landed'
|
||||
end
|
||||
|
||||
post '/redirect_307' do
|
||||
redirect '/landed', 307
|
||||
end
|
||||
|
||||
get '/referer_base' do
|
||||
'<a href="/get_referer">direct link</a>' \
|
||||
'<a href="/redirect_to_get_referer">link via redirect</a>' \
|
||||
|
@ -69,6 +73,10 @@ class TestApp < Sinatra::Base
|
|||
"You landed"
|
||||
end
|
||||
|
||||
post '/landed' do
|
||||
"You post landed: #{params.dig(:form, 'data')}"
|
||||
end
|
||||
|
||||
get '/with-quotes' do
|
||||
%q("No," he said, "you can't do that.")
|
||||
end
|
||||
|
|
|
@ -554,6 +554,13 @@ New line after and before textarea tag
|
|||
</p>
|
||||
</form>
|
||||
|
||||
<form action="/redirect_307" method="post">
|
||||
<input type="hidden" name="form[data]" value="307"/>
|
||||
<p>
|
||||
<input type="submit" value="Go 307"/>
|
||||
</p>
|
||||
</form>
|
||||
|
||||
<form action="/form" method="post">
|
||||
<p>
|
||||
<label for="html5_email">Html5 Email</label>
|
||||
|
|
Loading…
Add table
Reference in a new issue