Restore clicks_link_within()

This commit is contained in:
Kyle Hargraves 2008-04-12 16:07:33 -05:00 committed by Kyle Hargraves
parent 7ab6dd720f
commit c2ace0efad
3 changed files with 28 additions and 25 deletions

View File

@ -35,7 +35,7 @@ module ActionController
current_page.save_and_open
end
[:reloads, :fills_in, :clicks_button, :selects, :chooses, :checks, :unchecks, :clicks_link, :clicks_put_link, :clicks_get_link, :clicks_post_link, :clicks_delete_link].each do |method_name|
[:reloads, :fills_in, :clicks_button, :selects, :chooses, :checks, :unchecks, :clicks_link, :clicks_link_within, :clicks_put_link, :clicks_get_link, :clicks_post_link, :clicks_delete_link].each do |method_name|
define_method(method_name) do |*args|
current_page.send(method_name, *args)
end

View File

@ -117,13 +117,14 @@ module Webrat
link.click
end
# # Works like clicks_link, but only looks for the link text within a given selector
# #
# # Example:
# # clicks_link_within "#user_12", "Vote"
# def clicks_link_within(selector, link_text)
# clicks_one_link_of(links_within(selector), link_text)
# end
# Works like clicks_link, but only looks for the link text within a given selector
#
# Example:
# clicks_link_within "#user_12", "Vote"
def clicks_link_within(selector, link_text)
link = find_link(link_text, selector)
link.click
end
# Works like clicks_link, but forces a GET request
#
@ -206,10 +207,10 @@ module Webrat
end
def find_link(text)
def find_link(text, selector = nil)
matching_links = []
links.each do |possible_link|
links_within(selector).each do |possible_link|
matching_links << possible_link if possible_link.matches_text?(text)
end
@ -253,11 +254,13 @@ module Webrat
end
def links
return @links if @links
@links = (dom / "a[@href]").map do |link_element|
@links ||= links_within(nil)
end
def links_within(selector)
(dom / selector / "a[@href]").map do |link_element|
Link.new(self, link_element)
end
end
end
def forms

View File

@ -170,17 +170,17 @@ class ClicksLinkTest < Test::Unit::TestCase
@session.clicks_link "Link"
end
# def test_should_click_link_within_a_selector
# @response.stubs(:body).returns(<<-EOS)
# <a href="/page1">Link</a>
# <div id="container">
# <a href="/page2">Link</a>
# </div>
# EOS
#
# @session.expects(:get_via_redirect).with("/page2", {})
# @session.clicks_link_within "#container", "Link"
# end
def test_should_click_link_within_a_selector
@response.stubs(:body).returns(<<-EOS)
<a href="/page1">Link</a>
<div id="container">
<a href="/page2">Link</a>
</div>
EOS
@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)