From 407617b0be8034591ee16979777bc63bc90231a8 Mon Sep 17 00:00:00 2001 From: Kamal Fariz Mahyuddin Date: Thu, 6 Mar 2008 23:04:01 +0800 Subject: [PATCH] Prevent making a request if clicking on local anchor link --- History.txt | 1 + lib/webrat/session.rb | 2 +- test/clicks_link_test.rb | 10 +++++++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/History.txt b/History.txt index 66f5664..5efe6f3 100644 --- a/History.txt +++ b/History.txt @@ -1,5 +1,6 @@ == Trunk +* Prevent making a request if clicking on local anchor link (Patch from Kamal Fariz Mahyuddi) * Serialize empty text field values just like browsers (Patch from Kamal Fariz Mahyuddi) * Added clicks_link_within(selector, link_text), allowing restricting link search to within a given css selector (Path from Luke Melia) diff --git a/lib/webrat/session.rb b/lib/webrat/session.rb index b1c8da7..1d756f8 100644 --- a/lib/webrat/session.rb +++ b/lib/webrat/session.rb @@ -241,7 +241,7 @@ module ActionController http_method = http_method_from_js(onclick) authenticity_token = authenticity_token_value(onclick) - request_page(http_method, href, authenticity_token.blank? ? {} : {"authenticity_token" => authenticity_token}) + request_page(http_method, href, authenticity_token.blank? ? {} : {"authenticity_token" => authenticity_token}) unless href =~ /^#/ && http_method == :get end def find_field_by_name_or_label(name_or_label) # :nodoc: diff --git a/test/clicks_link_test.rb b/test/clicks_link_test.rb index 8d4580e..b8c87f6 100644 --- a/test/clicks_link_test.rb +++ b/test/clicks_link_test.rb @@ -181,5 +181,13 @@ class ClicksLinkTest < Test::Unit::TestCase @session.expects(:get_via_redirect).with("/page2", {}) @session.clicks_link_within "#container", "Link" end - + + def test_should_not_make_request_when_link_is_local_anchor + @response.stubs(:body).returns(<<-EOS) + Jump to Section 1 + EOS + # Don't know why @session.expects(:get_via_redirect).never doesn't work here + @session.expects(:send).with('get_via_redirect', '#section-1', {}).never + @session.clicks_link "Jump to Section 1" + end end