1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00

Rack-test should use data-method if available in links.

This commit is contained in:
José Valim 2010-04-09 14:01:17 +02:00
parent 5661d67ae9
commit 58d4d0caf7
4 changed files with 20 additions and 2 deletions

View file

@ -74,7 +74,8 @@ class Capybara::Driver::RackTest < Capybara::Driver::Base
def click
if tag_name == 'a'
driver.visit(self[:href].to_s)
method = self["data-method"] || :get
driver.process(method, self[:href].to_s)
elsif (tag_name == 'input' or tag_name == 'button') and %w(submit image).include?(type)
Form.new(driver, form).submit(self)
end
@ -186,8 +187,12 @@ class Capybara::Driver::RackTest < Capybara::Driver::Base
end
def visit(path, attributes = {})
process(:get, path, attributes)
end
def process(method, path, attributes = {})
return if path.gsub(/^#{current_path}/, '') =~ /^#/
get(path, attributes, env)
send(method, path, attributes, env)
follow_redirects!
end

View file

@ -18,6 +18,14 @@ describe Capybara::Session do
end
end
describe '#click_link' do
it "should use data-method if available" do
@session.visit "/with_html"
@session.click_link "A link with data-method"
@session.body.should == 'The requested object was deleted'
end
end
it_should_behave_like "session"
it_should_behave_like "session without javascript support"
it_should_behave_like "session with headers support"

View file

@ -42,6 +42,10 @@ class TestApp < Sinatra::Base
redirect '/redirect_again'
end
delete "/delete" do
"The requested object was deleted"
end
get '/redirect_back' do
redirect back
end

View file

@ -23,6 +23,7 @@
<a href="/redirect_back">BackToMyself</a>
<a title="twas a fine link" href="/redirect">A link came first</a>
<a title="a fine link" href="/with_simple_html">A link</a>
<a title="a fine link with data method" data-method="delete" href="/delete">A link with data-method</a>
<a>No Href</a>
<a href="">Blank Href</a>
<a href="#">Blank Anchor</a>