From 11f291ceb36a54b7a5fee0444cc0486c5d5035e1 Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp Date: Thu, 6 Nov 2008 14:44:17 -0500 Subject: [PATCH] Moving Webrat/Merb integratio to Webrat --- lib/webrat.rb | 2 -- lib/webrat/core/field.rb | 22 ++++++++++------------ lib/webrat/core/methods.rb | 13 ++++++++----- lib/webrat/merb/param_parser.rb | 7 ------- 4 files changed, 18 insertions(+), 26 deletions(-) delete mode 100644 lib/webrat/merb/param_parser.rb diff --git a/lib/webrat.rb b/lib/webrat.rb index e6ca325..748c869 100644 --- a/lib/webrat.rb +++ b/lib/webrat.rb @@ -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 diff --git a/lib/webrat/core/field.rb b/lib/webrat/core/field.rb index 9288f38..2693108 100644 --- a/lib/webrat/core/field.rb +++ b/lib/webrat/core/field.rb @@ -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| diff --git a/lib/webrat/core/methods.rb b/lib/webrat/core/methods.rb index 7f68824..d205cb3 100644 --- a/lib/webrat/core/methods.rb +++ b/lib/webrat/core/methods.rb @@ -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, diff --git a/lib/webrat/merb/param_parser.rb b/lib/webrat/merb/param_parser.rb deleted file mode 100644 index ee56b8d..0000000 --- a/lib/webrat/merb/param_parser.rb +++ /dev/null @@ -1,7 +0,0 @@ -module Webrat - class MerbParamParser - def self.parse_query_parameters(query_string) - Merb::Parse.query(query_string) - end - end -end \ No newline at end of file