Add support for Rails javascript post links.

This commit is contained in:
Mark Menard 2009-03-12 15:42:20 -04:00
parent 73f4c441c1
commit 0c2261d869
2 changed files with 23 additions and 0 deletions

View File

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

View File

@ -176,6 +176,27 @@ describe "click_link" do
click_link "Posts", :javascript => false
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
with_html <<-HTML
<html>