Fix problem where capybara can't post to relative urls in form actions.

This commit is contained in:
John Barton (joho) 2011-05-22 17:34:46 +10:00
parent aeb62d6063
commit 4d4eebe573
4 changed files with 26 additions and 4 deletions

View File

@ -35,13 +35,16 @@ class Capybara::RackTest::Browser
new_uri = URI.parse(path)
current_uri = URI.parse(current_url)
path = request_path + path if path.start_with?('?')
path = current_host + path if path.start_with?('/')
if new_uri.host
@current_host = new_uri.scheme + '://' + new_uri.host
end
unless new_uri.absolute?
path = request_path + path if path.start_with?('?')
path = request_path + '/' + path unless path.start_with?('/')
path = current_host + path
end
reset_cache!
send(method, path, attributes, env)
follow_redirects!

View File

@ -12,6 +12,14 @@ shared_examples_for "click_button" do
end
end
context "with a form that has a relative url as an action" do
it "should post to the correct url" do
@session.click_button('Relative Action')
@session.current_path.should == '/form/relative'
extract_results(@session)['relative'].should == 'Relative Action'
end
end
context "with value given on a submit button" do
context "on a form with HTML5 fields" do
before do
@ -284,4 +292,5 @@ shared_examples_for "click_button" do
@session.body.should include('Postback')
end
end
end

View File

@ -47,6 +47,10 @@ class TestApp < Sinatra::Base
'<pre id="results">' + params[:form].to_yaml + '</pre>'
end
post '/form/relative' do
'<pre id="results">' + params[:form].to_yaml + '</pre>'
end
get '/favicon.ico' do
nil
end

View File

@ -351,3 +351,9 @@
<input type="submit" name="form[button]" value="Just a button"/>
</p>
</form>
<form action="relative" method="post">
<p>
<input type="submit" name="form[relative]" value="Relative Action" />
</p>
</form>