mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Rack test driver maintain fragment when redirecting
This commit is contained in:
parent
50125e25f6
commit
1a48bc7716
3 changed files with 21 additions and 3 deletions
|
@ -8,6 +8,7 @@ class Capybara::RackTest::Browser
|
|||
|
||||
def initialize(driver)
|
||||
@driver = driver
|
||||
@current_fragment = nil
|
||||
end
|
||||
|
||||
def app
|
||||
|
@ -42,6 +43,7 @@ class Capybara::RackTest::Browser
|
|||
end
|
||||
|
||||
def process_and_follow_redirects(method, path, attributes = {}, env = {})
|
||||
@current_fragment = build_uri(path).fragment
|
||||
process(method, path, attributes, env)
|
||||
|
||||
return unless driver.follow_redirects?
|
||||
|
@ -65,7 +67,7 @@ class Capybara::RackTest::Browser
|
|||
method = method.downcase
|
||||
new_uri = build_uri(path)
|
||||
@current_scheme, @current_host, @current_port = new_uri.select(:scheme, :host, :port)
|
||||
|
||||
@current_fragment = new_uri.fragment || @current_fragment
|
||||
reset_cache!
|
||||
send(method, new_uri.to_s, attributes, env.merge(options[:headers] || {}))
|
||||
end
|
||||
|
@ -83,7 +85,9 @@ class Capybara::RackTest::Browser
|
|||
end
|
||||
|
||||
def current_url
|
||||
last_request.url
|
||||
uri = build_uri(last_request.url)
|
||||
uri.fragment = @current_fragment if @current_fragment
|
||||
uri.to_s
|
||||
rescue Rack::Test::Error
|
||||
''
|
||||
end
|
||||
|
|
|
@ -22,7 +22,7 @@ Capybara::SpecHelper.spec '#current_url, #current_path, #current_host' do
|
|||
|
||||
expect(@session.current_url.chomp('?')).to eq("#{scheme}://#{s.host}:#{s.port}#{path}")
|
||||
expect(@session.current_host).to eq("#{scheme}://#{s.host}") # no port
|
||||
expect(@session.current_path).to eq(path)
|
||||
expect(@session.current_path).to eq(path.split('#')[0])
|
||||
# Server should agree with us
|
||||
expect(@session).to have_content("Current host is #{scheme}://#{s.host}:#{s.port}") if path == '/host'
|
||||
end
|
||||
|
@ -83,6 +83,16 @@ Capybara::SpecHelper.spec '#current_url, #current_path, #current_host' do
|
|||
@session.visit("#{bases[0]}/redirect")
|
||||
should_be_on 0, '/landed'
|
||||
end
|
||||
|
||||
it 'maintains fragment' do
|
||||
@session.visit("#{bases[0]}/redirect#fragment")
|
||||
should_be_on 0, '/landed#fragment'
|
||||
end
|
||||
|
||||
it 'redirects to a fragment' do
|
||||
@session.visit("#{bases[0]}/redirect_with_fragment")
|
||||
should_be_on 0, '/landed#with_fragment'
|
||||
end
|
||||
|
||||
it 'is affected by pushState', requires: [:js] do
|
||||
@session.visit('/with_js')
|
||||
|
|
|
@ -33,6 +33,10 @@ class TestApp < Sinatra::Base
|
|||
redirect '/redirect_again'
|
||||
end
|
||||
|
||||
get '/redirect_with_fragment' do
|
||||
redirect '/landed#with_fragment'
|
||||
end
|
||||
|
||||
get '/redirect_again' do
|
||||
redirect '/landed'
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue