Permalink
Browse files

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

  • Loading branch information...
1 parent aeb62d6 commit 4d4eebe57342933ec9a4773cdcfa0c30d1203246 @joho joho committed May 22, 2011
@@ -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!
@@ -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
@@ -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
@@ -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>

0 comments on commit 4d4eebe

Please sign in to comment.