Permalink
Browse files

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

  • Loading branch information...
josevalim committed Apr 9, 2010
1 parent 5661d67 commit 58d4d0caf7d4fad5519033e9bfd0786146750a13
@@ -74,7 +74,8 @@ def unselect(option)

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 @@ def initialize(app)
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

@@ -18,6 +18,14 @@
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"
@@ -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
@@ -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>

0 comments on commit 58d4d0c

Please sign in to comment.