Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

  • Loading branch information...
commit 4d4eebe57342933ec9a4773cdcfa0c30d1203246 1 parent aeb62d6
@joho joho authored
View
11 lib/capybara/rack_test/browser.rb
@@ -35,13 +35,16 @@ def process(method, path, attributes = {})
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
9 lib/capybara/spec/session/click_button_spec.rb
@@ -12,6 +12,14 @@
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 @@
@session.body.should include('Postback')
end
end
+
end
View
4 lib/capybara/spec/test_app.rb
@@ -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
6 lib/capybara/spec/views/form.erb
@@ -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>
Please sign in to comment.
Something went wrong with that request. Please try again.