Skip to content

Commit

Permalink
Delegate from Session to Scope instead of Page
Browse files Browse the repository at this point in the history
  • Loading branch information
brynary committed Jul 28, 2008
1 parent cccc8a3 commit 9979a29
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 23 deletions.
31 changes: 9 additions & 22 deletions lib/webrat/core/page.rb
Expand Up @@ -24,28 +24,13 @@ def initialize(session, url = nil, method = :get, data = {})
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
Expand All @@ -59,6 +44,10 @@ def clicks_link_within(selector, link_text)
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

Expand All @@ -71,9 +60,7 @@ def reset_scope
@scope = nil
end

def scope
@scope ||= Scope.new(self, session.response_body)
end


end
end
1 change: 1 addition & 0 deletions lib/webrat/core/scope.rb
@@ -1,5 +1,6 @@
module Webrat
class Scope
include Logging
include Flunk

def initialize(page, html, selector = nil)
Expand Down
30 changes: 29 additions & 1 deletion lib/webrat/core/session.rb
Expand Up @@ -46,10 +46,38 @@ def current_page
@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
Expand All @@ -75,7 +103,7 @@ def rewrite_css_and_image_references(response_html) # :nodoc

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
Expand Down

0 comments on commit 9979a29

Please sign in to comment.