Skip to content

Commit

Permalink
add support for Rails 2.3.4 form authenticity tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
jweiss committed Nov 9, 2009
1 parent f51b745 commit 96f2f34
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/webrat/core/elements/link.rb
Expand Up @@ -53,7 +53,7 @@ def absolute_href

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

Expand Down
21 changes: 21 additions & 0 deletions spec/public/click_link_spec.rb
Expand Up @@ -143,6 +143,27 @@
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
Expand Down

0 comments on commit 96f2f34

Please sign in to comment.