Cleaning up the Rails session code. Extract scoped_html method in Scope

This commit is contained in:
Bryan Helmkamp 2008-09-14 14:37:24 -04:00
parent fb5b663590
commit 44db244a76
3 changed files with 17 additions and 19 deletions

View File

@ -165,19 +165,21 @@ module Webrat
alias_method :click_button, :clicks_button alias_method :click_button, :clicks_button
def dom # :nodoc: def dom # :nodoc:
return @dom if defined?(@dom) && @dom @dom ||= Hpricot(scoped_html)
@dom = Hpricot(@html)
if @selector
html = (@dom / @selector).first.to_html
@dom = Hpricot(html)
end
return @dom
end end
protected protected
def scoped_html
@scoped_html ||= begin
if @selector
(Hpricot(@html) / @selector).first.to_html
else
@html
end
end
end
def find_select_option(option_text, id_or_name_or_label) def find_select_option(option_text, id_or_name_or_label)
if id_or_name_or_label if id_or_name_or_label
field = find_field(id_or_name_or_label, SelectField) field = find_field(id_or_name_or_label, SelectField)

View File

@ -109,6 +109,11 @@ module Webrat
yield Scope.new(self, response_body, selector) yield Scope.new(self, response_body, selector)
end end
# Issues a GET request for a page, follows any redirects, and verifies the final page
# load was successful.
#
# Example:
# visits "/"
def visits(url = nil, http_method = :get, data = {}) def visits(url = nil, http_method = :get, data = {})
request_page(url, http_method, data) request_page(url, http_method, data)
end end
@ -136,6 +141,5 @@ module Webrat
def_delegators :current_scope, :click_post_link, :clicks_post_link def_delegators :current_scope, :click_post_link, :clicks_post_link
def_delegators :current_scope, :click_put_link, :clicks_put_link def_delegators :current_scope, :click_put_link, :clicks_put_link
def_delegators :current_scope, :click_button, :clicks_button def_delegators :current_scope, :click_button, :clicks_button
end end
end end

View File

@ -5,15 +5,6 @@ module ActionController
unless instance_methods.include?("put_via_redirect") unless instance_methods.include?("put_via_redirect")
include Webrat::RedirectActions include Webrat::RedirectActions
end end
# Issues a GET request for a page, follows any redirects, and verifies the final page
# load was successful.
#
# Example:
# visits "/"
def visits(*args)
webrat_session.visits(*args)
end
def respond_to?(name) def respond_to?(name)
super || webrat_session.respond_to?(name) super || webrat_session.respond_to?(name)
@ -32,6 +23,7 @@ module ActionController
def webrat_session def webrat_session
@webrat_session ||= Webrat::RailsSession.new(self) @webrat_session ||= Webrat::RailsSession.new(self)
end end
end end
end end
end end