Delegate from Session to Scope instead of Page
This commit is contained in:
parent
cccc8a34f8
commit
9979a29524
@ -24,29 +24,14 @@ 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
|
||||
def_delegators :scope, :uncheck, :unchecks
|
||||
@ -60,6 +45,10 @@ module Webrat
|
||||
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
|
||||
|
||||
def load_page
|
||||
@ -71,9 +60,7 @@ module Webrat
|
||||
@scope = nil
|
||||
end
|
||||
|
||||
def scope
|
||||
@scope ||= Scope.new(self, session.response_body)
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
end
|
@ -1,5 +1,6 @@
|
||||
module Webrat
|
||||
class Scope
|
||||
include Logging
|
||||
include Flunk
|
||||
|
||||
def initialize(page, html, selector = nil)
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user