Add backwards compatability for current_page. Fix some bugs with Rails integration
This commit is contained in:
parent
a610d1f9e0
commit
40f7929a5f
@ -1,16 +1,18 @@
|
|||||||
require "forwardable"
|
require "forwardable"
|
||||||
|
require "ostruct"
|
||||||
|
|
||||||
module Webrat
|
module Webrat
|
||||||
class Session
|
class Session
|
||||||
extend Forwardable
|
extend Forwardable
|
||||||
include Logging
|
include Logging
|
||||||
|
|
||||||
|
attr_reader :current_url
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@current_url = nil
|
|
||||||
@http_method = :get
|
@http_method = :get
|
||||||
@data = {}
|
@data = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
# Saves the page out to RAILS_ROOT/tmp/ and opens it in the default
|
# Saves the page out to RAILS_ROOT/tmp/ and opens it in the default
|
||||||
# web browser if on OS X. Useful for debugging.
|
# web browser if on OS X. Useful for debugging.
|
||||||
#
|
#
|
||||||
@ -28,8 +30,13 @@ module Webrat
|
|||||||
open_in_browser(filename)
|
open_in_browser(filename)
|
||||||
end
|
end
|
||||||
|
|
||||||
def current_url
|
# For backwards compatibility -- removing in 1.0
|
||||||
@current_url
|
def current_page
|
||||||
|
page = OpenStruct.new
|
||||||
|
page.url = @current_url
|
||||||
|
page.http_method = @http_method
|
||||||
|
page.data = @data
|
||||||
|
page
|
||||||
end
|
end
|
||||||
|
|
||||||
def doc_root
|
def doc_root
|
||||||
@ -40,12 +47,17 @@ module Webrat
|
|||||||
File.expand_path(".")
|
File.expand_path(".")
|
||||||
end
|
end
|
||||||
|
|
||||||
def request_page(url, method, data)
|
def request_page(url, http_method, data)
|
||||||
debug_log "REQUESTING PAGE: #{method.to_s.upcase} #{url} with #{data.inspect}"
|
debug_log "REQUESTING PAGE: #{http_method.to_s.upcase} #{url} with #{data.inspect}"
|
||||||
send "#{method}", url, data || {}
|
send "#{http_method}", url, data || {}
|
||||||
|
|
||||||
save_and_open_page if exception_caught?
|
save_and_open_page if exception_caught?
|
||||||
flunk("Page load was not successful (Code: #{session.response_code.inspect})") unless success_code?
|
flunk("Page load was not successful (Code: #{response_code.inspect})") unless success_code?
|
||||||
|
|
||||||
|
@scope = nil
|
||||||
|
@current_url = url
|
||||||
|
@http_method = http_method
|
||||||
|
@data = data
|
||||||
end
|
end
|
||||||
|
|
||||||
def success_code?
|
def success_code?
|
||||||
@ -89,10 +101,6 @@ module Webrat
|
|||||||
end
|
end
|
||||||
|
|
||||||
def visits(url = nil, http_method = :get, data = {})
|
def visits(url = nil, http_method = :get, data = {})
|
||||||
@current_url = url
|
|
||||||
@http_method = http_method
|
|
||||||
@data = data
|
|
||||||
|
|
||||||
request_page(url, http_method, data)
|
request_page(url, http_method, data)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ module Webrat
|
|||||||
class RailsSession < Session
|
class RailsSession < Session
|
||||||
|
|
||||||
def initialize(integration_session)
|
def initialize(integration_session)
|
||||||
super
|
super()
|
||||||
@integration_session = integration_session
|
@integration_session = integration_session
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ module ActionController
|
|||||||
# Example:
|
# Example:
|
||||||
# visits "/"
|
# visits "/"
|
||||||
def visits(*args)
|
def visits(*args)
|
||||||
@webrat_session.visits(*args)
|
webrat_session.visits(*args)
|
||||||
end
|
end
|
||||||
|
|
||||||
def respond_to?(name)
|
def respond_to?(name)
|
||||||
|
Loading…
Reference in New Issue
Block a user