Prevent making a request if clicking on local anchor link

This commit is contained in:
Kamal Fariz Mahyuddin 2008-03-06 23:04:01 +08:00 committed by Bryan Helmkamp
parent db3fe608ea
commit 407617b0be
3 changed files with 11 additions and 2 deletions

View File

@ -1,5 +1,6 @@
== Trunk == 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) * Serialize empty text field values just like browsers (Patch from Kamal Fariz Mahyuddi)
* Added clicks_link_within(selector, link_text), allowing restricting link search * Added clicks_link_within(selector, link_text), allowing restricting link search
to within a given css selector (Path from Luke Melia) to within a given css selector (Path from Luke Melia)

View File

@ -241,7 +241,7 @@ module ActionController
http_method = http_method_from_js(onclick) http_method = http_method_from_js(onclick)
authenticity_token = authenticity_token_value(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 end
def find_field_by_name_or_label(name_or_label) # :nodoc: def find_field_by_name_or_label(name_or_label) # :nodoc:

View File

@ -182,4 +182,12 @@ class ClicksLinkTest < Test::Unit::TestCase
@session.clicks_link_within "#container", "Link" @session.clicks_link_within "#container", "Link"
end end
def test_should_not_make_request_when_link_is_local_anchor
@response.stubs(:body).returns(<<-EOS)
<a href="#section-1">Jump to Section 1</a>
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 end