From 18c3b77b2381e9f7072d595fa9f599b0994852a7 Mon Sep 17 00:00:00 2001 From: Yehuda Katz + Carl Lerche Date: Tue, 16 Jun 2009 10:46:03 -0700 Subject: Merge process2 into process to people's regular tests run :P --- .../lib/action_controller/testing/integration.rb | 2 +- .../lib/action_controller/testing/process.rb | 51 ++++----------- .../lib/action_controller/testing/process2.rb | 74 ---------------------- 3 files changed, 12 insertions(+), 115 deletions(-) delete mode 100644 actionpack/lib/action_controller/testing/process2.rb (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/testing/integration.rb b/actionpack/lib/action_controller/testing/integration.rb index 37ca93f22c..5cb0f48f82 100644 --- a/actionpack/lib/action_controller/testing/integration.rb +++ b/actionpack/lib/action_controller/testing/integration.rb @@ -245,7 +245,7 @@ module ActionController path = location.query ? "#{location.path}?#{location.query}" : location.path end - [ControllerCapture, ActionController::ProcessWithTest].each do |mod| + [ControllerCapture, ActionController::Testing].each do |mod| unless ActionController::Base < mod ActionController::Base.class_eval { include mod } end diff --git a/actionpack/lib/action_controller/testing/process.rb b/actionpack/lib/action_controller/testing/process.rb index ea5752d4f5..7634290ea1 100644 --- a/actionpack/lib/action_controller/testing/process.rb +++ b/actionpack/lib/action_controller/testing/process.rb @@ -124,30 +124,24 @@ module ActionController #:nodoc: @request.recycle! @response.recycle! + @controller.response_body = nil + @controller.formats = nil + @controller.params = nil @html_document = nil - @request.request_method = http_method + @request.env['REQUEST_METHOD'] = http_method parameters ||= {} @request.assign_parameters(@controller.class.controller_path, action.to_s, parameters) @request.session = ActionController::TestSession.new(session) unless session.nil? @request.session["flash"] = ActionController::Flash::FlashHash.new.update(flash) if flash - build_request_uri(action, parameters) - - Base.class_eval { include ProcessWithTest } unless Base < ProcessWithTest - - env = @request.env - app = @controller - - # TODO: Enable Lint - # app = Rack::Lint.new(app) - status, headers, body = app.action(action, env) - response = Rack::MockResponse.new(status, headers, body) - - @response.request, @response.template = @request, @controller.template - @response.status, @response.headers, @response.body = response.status, response.headers, response.body + @controller.request = @request + @controller.params.merge!(parameters) + build_request_uri(action, parameters) + Base.class_eval { include Testing } + @controller.process_with_new_base_test(@request, @response) @response end @@ -167,7 +161,7 @@ module ActionController #:nodoc: next if ActionController::Base.protected_instance_variables.include?(ivar) assigns[ivar[1..-1]] = @controller.instance_variable_get(ivar) end - + key.nil? ? assigns : assigns[key.to_s] end @@ -263,27 +257,4 @@ module ActionController #:nodoc: ActionController::Routing.const_set(:Routes, real_routes) if real_routes end end - - module ProcessWithTest #:nodoc: - def self.included(base) - base.class_eval { - attr_reader :assigns - alias_method_chain :process, :test - } - end - - def process_with_test(*args) - process_without_test(*args).tap { set_test_assigns } - end - - private - def set_test_assigns - @assigns = {} - (instance_variable_names - self.class.protected_instance_variables).each do |var| - name, value = var[1..-1], instance_variable_get(var) - @assigns[name] = value - @template.assigns[name] = value if response - end - end - end -end +end \ No newline at end of file diff --git a/actionpack/lib/action_controller/testing/process2.rb b/actionpack/lib/action_controller/testing/process2.rb deleted file mode 100644 index 1c6fd2d80a..0000000000 --- a/actionpack/lib/action_controller/testing/process2.rb +++ /dev/null @@ -1,74 +0,0 @@ -require "action_controller/testing/process" - -module ActionController - module TestProcess - - # Executes a request simulating GET HTTP method and set/volley the response - def get(action, parameters = nil, session = nil, flash = nil) - process(action, parameters, session, flash, "GET") - end - - # Executes a request simulating POST HTTP method and set/volley the response - def post(action, parameters = nil, session = nil, flash = nil) - process(action, parameters, session, flash, "POST") - end - - # Executes a request simulating PUT HTTP method and set/volley the response - def put(action, parameters = nil, session = nil, flash = nil) - process(action, parameters, session, flash, "PUT") - end - - # Executes a request simulating DELETE HTTP method and set/volley the response - def delete(action, parameters = nil, session = nil, flash = nil) - process(action, parameters, session, flash, "DELETE") - end - - # Executes a request simulating HEAD HTTP method and set/volley the response - def head(action, parameters = nil, session = nil, flash = nil) - process(action, parameters, session, flash, "HEAD") - end - - def process(action, parameters = nil, session = nil, flash = nil, http_method = 'GET') - # Sanity check for required instance variables so we can give an - # understandable error message. - %w(@controller @request @response).each do |iv_name| - if !(instance_variable_names.include?(iv_name) || instance_variable_names.include?(iv_name.to_sym)) || instance_variable_get(iv_name).nil? - raise "#{iv_name} is nil: make sure you set it in your test's setup method." - end - end - - @request.recycle! - @response.recycle! - @controller.response_body = nil - @controller.formats = nil - @controller.params = nil - - @html_document = nil - @request.env['REQUEST_METHOD'] = http_method - - parameters ||= {} - @request.assign_parameters(@controller.class.controller_path, action.to_s, parameters) - - @request.session = ActionController::TestSession.new(session) unless session.nil? - @request.session["flash"] = ActionController::Flash::FlashHash.new.update(flash) if flash - - @controller.request = @request - @controller.params.merge!(parameters) - build_request_uri(action, parameters) - # Base.class_eval { include ProcessWithTest } unless Base < ProcessWithTest - @controller.process_with_new_base_test(@request, @response) - @response - end - - def build_request_uri(action, parameters) - unless @request.env['REQUEST_URI'] - options = @controller.__send__(:rewrite_options, parameters) - options.update(:only_path => true, :action => action) - - url = ActionController::UrlRewriter.new(@request, parameters) - @request.request_uri = url.rewrite(options) - end - end - - end -end \ No newline at end of file -- cgit v1.2.3