add support for Rails 2.3.4 form authenticity tokens

This commit is contained in:
Jonathan Weiss 2009-11-09 17:32:46 +01:00 committed by Bryan Helmkamp
parent cbb07306d4
commit ea4a52ccf1
2 changed files with 22 additions and 1 deletions

View File

@ -53,7 +53,7 @@ module Webrat
def authenticity_token
return unless onclick && onclick.include?("s.setAttribute('name', 'authenticity_token');") &&
onclick =~ /s\.setAttribute\('value', '([a-f0-9]{40})'\);/
( onclick =~ /s\.setAttribute\('value', '([a-f0-9]{40})'\);/ || onclick =~ /s\.setAttribute\('value', '(.{44})'\);/ )
$LAST_MATCH_INFO.captures.first
end

View File

@ -143,6 +143,27 @@ describe "click_link" do
webrat_session.should_receive(:post).with("/posts", "authenticity_token" => "aa79cb354597a60a3786e7e291ed4f74d77d3a62")
click_link "Posts"
end
it "should click rails 2.3.4 javascript links with authenticity tokens" 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 s = document.createElement('input');
s.setAttribute('type', 'hidden');
s.setAttribute('name', 'authenticity_token');
s.setAttribute('value', 'aa79cb354597a60a3786e7e291ed4f74d77d3a62=/$a');
f.appendChild(s);
f.submit();
return false;">Posts</a>
</html>
HTML
webrat_session.should_receive(:post).with("/posts", "authenticity_token" => "aa79cb354597a60a3786e7e291ed4f74d77d3a62=/$a")
click_link "Posts"
end
it "should click rails javascript delete links" do
with_html <<-HTML