Skip to content
Browse files

Merge process2 into process to people's regular tests run :P

  • Loading branch information...
1 parent 1fbfa3e commit 18c3b77b2381e9f7072d595fa9f599b0994852a7 Yehuda Katz + Carl Lerche committed Jun 16, 2009
View
2 actionpack/lib/action_controller/testing/integration.rb
@@ -245,7 +245,7 @@ def process(method, path, parameters = nil, rack_environment = nil)
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
View
51 actionpack/lib/action_controller/testing/process.rb
@@ -124,30 +124,24 @@ def process(action, parameters = nil, session = nil, flash = nil, http_method =
@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 @@ def assigns(key = nil)
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 @@ def with_routing
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
View
74 actionpack/lib/action_controller/testing/process2.rb
@@ -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

0 comments on commit 18c3b77

Please sign in to comment.
Something went wrong with that request. Please try again.