Delegate from Session to Scope instead of Page

This commit is contained in:
Bryan Helmkamp 2008-07-28 09:59:22 -04:00
parent cccc8a34f8
commit 9979a29524
3 changed files with 39 additions and 23 deletions

View File

@ -24,28 +24,13 @@ module Webrat
session.current_page = self
end
# Reloads the last page requested. Note that this will resubmit forms
# and their data.
#
# Example:
# reloads
def reloads
load_page
def http_method
@method
end
alias_method :reload, :reloads
# 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)
session.within(selector) do |scope|
scope.clicks_link(link_text)
end
def data
@data
end
alias_method :click_link_within, :clicks_link_within
def_delegators :scope, :fill_in, :fills_in
def_delegators :scope, :check, :checks
@ -59,6 +44,10 @@ module Webrat
def_delegators :scope, :click_post_link, :clicks_post_link
def_delegators :scope, :click_put_link, :clicks_put_link
def_delegators :scope, :click_button, :clicks_button
def scope
@scope ||= Scope.new(self, session.response_body)
end
protected
@ -71,9 +60,7 @@ module Webrat
@scope = nil
end
def scope
@scope ||= Scope.new(self, session.response_body)
end
end
end

View File

@ -1,5 +1,6 @@
module Webrat
class Scope
include Logging
include Flunk
def initialize(page, html, selector = nil)

View File

@ -46,10 +46,38 @@ module Webrat
@current_page ||= Page.new(self)
end
def current_scope
current_page.scope
end
def current_page=(new_page)
@current_page = new_page
end
# Reloads the last page requested. Note that this will resubmit forms
# and their data.
#
# Example:
# reloads
def reloads
request_page(@current_page.url, current_page.http_method, current_page.data)
end
alias_method :reload, :reloads
# 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)
within(selector) do |scope|
scope.clicks_link(link_text)
end
end
alias_method :click_link_within, :clicks_link_within
def within(selector)
yield Scope.new(current_page, response_body, selector)
end
@ -75,7 +103,7 @@ module Webrat
def method_missing(name, *args, &block)
if current_page.respond_to?(name)
current_page.send(name, *args, &block)
current_scope.send(name, *args, &block)
else
super
end