Moving Webrat/Merb integratio to Webrat

This commit is contained in:
Bryan Helmkamp 2008-11-06 14:44:17 -05:00
parent 0943d537ea
commit 11f291ceb3
4 changed files with 18 additions and 26 deletions

View File

@ -16,6 +16,4 @@ require "webrat/core"
# Probably better for webrat users to require "webrat/rails" etc. directly
if defined?(RAILS_ENV)
require "webrat/rails"
elsif defined?(Merb)
require "webrat/merb"
end

View File

@ -59,7 +59,16 @@ module Webrat
def to_param
return nil if disabled?
param_parser.parse_query_parameters("#{name}=#{escaped_value}")
key_and_value = "#{name}=#{escaped_value}"
if defined?(CGIMethods)
CGIMethods.parse_query_parameters(key_and_value)
elsif defined?(ActionController::AbstractRequest)
ActionController::AbstractRequest.parse_query_parameters(key_and_value)
else
Merb::Parse.query(key_and_value)
end
end
def set(value)
@ -112,17 +121,6 @@ module Webrat
@element["value"]
end
def param_parser
if defined?(CGIMethods)
CGIMethods
elsif defined?(ActionController::AbstractRequest)
ActionController::AbstractRequest
else
require "webrat/merb/param_parser"
Webrat::MerbParamParser
end
end
def replace_param_value(params, oval, nval)
output = Hash.new
params.each do |key, value|

View File

@ -1,19 +1,22 @@
module Webrat
module Methods
def self.delegate_to_session(*meths)
meths.each do |meth|
self.class_eval <<-RUBY
def #{meth}(*args, &blk)
webrat_session.#{meth}(*args, &blk)
@session ||= ::Webrat::Session.new
@session.#{meth}(*args, &blk)
end
RUBY
end
end
def webrat_session
@webrat_session ||= ::Webrat::Session.new
end
# all of these methods delegate to the @session, which should
# be created transparently.
#
# Note that when using Webrat, #request also uses @session, so
# that #request and webrat native functions behave interchangably
delegate_to_session \
:visits, :visit,

View File

@ -1,7 +0,0 @@
module Webrat
class MerbParamParser
def self.parse_query_parameters(query_string)
Merb::Parse.query(query_string)
end
end
end