Permalink
Browse files

Switch functional tests to run through the rack interface instead of …

…process
  • Loading branch information...
josh committed May 2, 2009
1 parent a8b75c4 commit f32cf44870549c6cc5b6e6c84cffc1facf6ec38e
@@ -371,10 +371,7 @@ def session
class << self
def call(env)
- # HACK: For global rescue to have access to the original request and response
- request = env["action_controller.rescue.request"] ||= ActionDispatch::Request.new(env)
- response = env["action_controller.rescue.response"] ||= ActionDispatch::Response.new
- process(request, response)
+ new.call(env)
end
# Factory for the standard create, process loop where the controller is discarded after processing.
@@ -511,6 +508,13 @@ def exempt_from_layout(*types)
end
public
+ def call(env)
+ # HACK: For global rescue to have access to the original request and response
+ request = env["action_dispatch.rescue.request"] ||= ActionDispatch::Request.new(env)
+ response = env["action_dispatch.rescue.response"] ||= ActionDispatch::Response.new
+ process(request, response).to_a
+ end
+
# Extracts the action_name from the request parameters and performs that action.
def process(request, response, method = :perform_action, *arguments) #:nodoc:
response.request = request
@@ -80,7 +80,7 @@ def _call(env)
Routing::Routes.call(env)
rescue Exception => exception
if controller ||= (::ApplicationController rescue Base)
- controller.call_with_exception(env, exception).to_a
+ controller.call_with_exception(env, exception)
else
raise exception
end
@@ -62,7 +62,7 @@ module ClassMethods
def call_with_exception(env, exception) #:nodoc:
request = env["action_controller.rescue.request"] ||= ActionDispatch::Request.new(env)
response = env["action_controller.rescue.response"] ||= ActionDispatch::Response.new
- new.process(request, response, :rescue_action, exception)
+ new.process(request, response, :rescue_action, exception).to_a
end
end
@@ -430,7 +430,7 @@ def raise_named_route_error(options, named_route, named_route_name)
def call(env)
request = ActionDispatch::Request.new(env)
app = Routing::Routes.recognize(request)
- app.call(env).to_a
+ app.call(env)
end
def recognize(request)
@@ -35,12 +35,13 @@ def assign_parameters(controller_path, action, parameters)
end
data = params.to_query
- @env['CONTENT_LENGTH'] = data.length
+ @env['CONTENT_LENGTH'] = data.length.to_s
@env['rack.input'] = StringIO.new(data)
end
def recycle!
@env.delete_if { |k, v| k =~ /^(action_dispatch|rack)\.request/ }
+ @env.delete_if { |k, v| k =~ /^action_dispatch\.rescue/ }
@env['action_dispatch.request.query_parameters'] = {}
end
end
@@ -132,7 +133,15 @@ def process(action, parameters = nil, session = nil, flash = nil, http_method =
Base.class_eval { include ProcessWithTest } unless Base < ProcessWithTest
- response = Rack::MockResponse.new(*@controller.process(@request, ActionDispatch::Response.new).to_a)
+ env = @request.env
+ app = @controller
+
+ # TODO: Enable Lint
+ # app = Rack::Lint.new(app)
+
+ status, headers, body = app.call(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
@response
@@ -16,6 +16,7 @@ def initialize(env = {})
def env
write_cookies!
+ delete_nil_values!
super
end
@@ -74,5 +75,9 @@ def write_cookies!
@env['HTTP_COOKIE'] = @cookies.map { |name, value| "#{name}=#{value};" }.join(' ')
end
end
+
+ def delete_nil_values!
+ @env.delete_if { |k, v| v.nil? }
+ end
end
end
@@ -111,7 +111,7 @@ def test_should_cache_with_trailing_slash_on_url
end
def test_should_cache_ok_at_custom_path
- @request.stubs(:path).returns("/index.html")
+ @request.request_uri = "/index.html"
get :ok
assert_response :ok
assert File.exist?("#{FILE_STORE_PATH}/index.html")

0 comments on commit f32cf44

Please sign in to comment.