Cleaning up the Rails session code. Extract scoped_html method in Scope
This commit is contained in:
parent
fb5b663590
commit
44db244a76
@ -165,19 +165,21 @@ module Webrat
|
||||
alias_method :click_button, :clicks_button
|
||||
|
||||
def dom # :nodoc:
|
||||
return @dom if defined?(@dom) && @dom
|
||||
@dom = Hpricot(@html)
|
||||
|
||||
if @selector
|
||||
html = (@dom / @selector).first.to_html
|
||||
@dom = Hpricot(html)
|
||||
end
|
||||
|
||||
return @dom
|
||||
@dom ||= Hpricot(scoped_html)
|
||||
end
|
||||
|
||||
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)
|
||||
if id_or_name_or_label
|
||||
field = find_field(id_or_name_or_label, SelectField)
|
||||
|
@ -109,6 +109,11 @@ module Webrat
|
||||
yield Scope.new(self, response_body, selector)
|
||||
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 = {})
|
||||
request_page(url, http_method, data)
|
||||
end
|
||||
@ -136,6 +141,5 @@ module Webrat
|
||||
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_button, :clicks_button
|
||||
|
||||
end
|
||||
end
|
@ -5,15 +5,6 @@ module ActionController
|
||||
unless instance_methods.include?("put_via_redirect")
|
||||
include Webrat::RedirectActions
|
||||
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)
|
||||
super || webrat_session.respond_to?(name)
|
||||
@ -32,6 +23,7 @@ module ActionController
|
||||
def webrat_session
|
||||
@webrat_session ||= Webrat::RailsSession.new(self)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user