Merge commit 'MarkMenard/master'

This commit is contained in:
Bryan Helmkamp 2009-04-06 12:39:31 -04:00
commit 644478f6f0
3 changed files with 24 additions and 1 deletions

View File

@ -81,6 +81,8 @@ module Webrat
:delete :delete
elsif onclick.include?("m.setAttribute('value', 'put')") elsif onclick.include?("m.setAttribute('value', 'put')")
:put :put
elsif onclick.include?("m.setAttribute('value', 'post')")
:post
else else
raise Webrat::WebratError.new("No HTTP method for _method param in #{onclick.inspect}") raise Webrat::WebratError.new("No HTTP method for _method param in #{onclick.inspect}")
end end

View File

@ -36,7 +36,7 @@ module Webrat #:nodoc:
end end
def mechanize def mechanize
@mechanize = WWW::Mechanize.new @mechanize ||= WWW::Mechanize.new
end end
def_delegators :mechanize, :basic_auth def_delegators :mechanize, :basic_auth

View File

@ -176,6 +176,27 @@ describe "click_link" do
click_link "Posts", :javascript => false click_link "Posts", :javascript => false
end end
it "should click rails javascript post links" do
with_html <<-HTML
<html>
<a href="/posts" onclick="var f = document.createElement('form');
f.style.display = 'none';
this.parentNode.appendChild(f);
f.method = 'POST';
f.action = this.href;
var m = document.createElement('input');
m.setAttribute('type', 'hidden');
m.setAttribute('name', '_method');
m.setAttribute('value', 'post');
f.appendChild(m);
f.submit();
return false;">Post</a></h2>
</html>
HTML
webrat_session.should_receive(:post).with("/posts", {})
click_link "Post"
end
it "should click rails javascript put links" do it "should click rails javascript put links" do
with_html <<-HTML with_html <<-HTML
<html> <html>