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 # Probably better for webrat users to require "webrat/rails" etc. directly
if defined?(RAILS_ENV) if defined?(RAILS_ENV)
require "webrat/rails" require "webrat/rails"
elsif defined?(Merb)
require "webrat/merb"
end end

View File

@ -59,7 +59,16 @@ module Webrat
def to_param def to_param
return nil if disabled? 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 end
def set(value) def set(value)
@ -112,17 +121,6 @@ module Webrat
@element["value"] @element["value"]
end 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) def replace_param_value(params, oval, nval)
output = Hash.new output = Hash.new
params.each do |key, value| params.each do |key, value|

View File

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