diff options
author | Jesse Newland <jnewland@gmail.com> | 2008-12-17 09:21:20 -0500 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2008-12-17 15:59:47 +0100 |
commit | 97a178bfa4d5101dca73ae931cc9c77385d8c97e (patch) | |
tree | 0b7989afbc55ccdb4654de8c6b7eeb577de4ded3 /actionpack/lib/action_controller | |
parent | 1bcfce0130d4fa13d56f58d5cd5e0f5de33e015f (diff) | |
download | rails-97a178bfa4d5101dca73ae931cc9c77385d8c97e.tar.gz rails-97a178bfa4d5101dca73ae931cc9c77385d8c97e.tar.bz2 rails-97a178bfa4d5101dca73ae931cc9c77385d8c97e.zip |
Decorate responses from Rack Middleware and Rails Metal for the purposes of integration testing. A test for the following Metal:
class Poller < Rails::Rack::Metal
def call(env)
if env["PATH_INFO"] =~ /^\/poller/
[200, {"Content-Type" => "text/plain"}, "Hello World!"]
else
super
end
end
end
might be tested like so:
class PollerTest < ActionController::IntegrationTest
test "poller returns hello world" do
get "/poller"
assert_response 200
assert_response :success
assert_response :ok
assert_equal "Hello World!", response.body
end
end
[#1588 state:committed]
Signed-off-by: David Heinemeier Hansson <david@loudthinking.com>
Diffstat (limited to 'actionpack/lib/action_controller')
-rw-r--r-- | actionpack/lib/action_controller/integration.rb | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/actionpack/lib/action_controller/integration.rb b/actionpack/lib/action_controller/integration.rb index 1b0543033b..277cede1cf 100644 --- a/actionpack/lib/action_controller/integration.rb +++ b/actionpack/lib/action_controller/integration.rb @@ -276,6 +276,7 @@ module ActionController "SCRIPT_NAME" => "", "REQUEST_URI" => path, + "PATH_INFO" => path, "HTTP_HOST" => host, "REMOTE_ADDR" => remote_addr, "CONTENT_TYPE" => "application/x-www-form-urlencoded", @@ -310,16 +311,6 @@ module ActionController status, headers, body = app.call(env) @request_count += 1 - if @controller = ActionController::Base.last_instantiation - @request = @controller.request - @response = @controller.response - - # Decorate the response with the standard behavior of the - # TestResponse so that things like assert_response can be - # used in integration tests. - @response.extend(TestResponseBehavior) - end - @html_document = nil @status = status.to_i @@ -335,6 +326,22 @@ module ActionController @body = "" body.each { |part| @body << part } + if @controller = ActionController::Base.last_instantiation + @request = @controller.request + @response = @controller.response + else + # Decorate responses from Rack Middleware and Rails Metal + # as an AbstractResponse for the purposes of integration testing + @response = AbstractResponse.new + @response.headers = @headers.merge('Status' => status.to_s) + @response.body = @body + end + + # Decorate the response with the standard behavior of the + # TestResponse so that things like assert_response can be + # used in integration tests. + @response.extend(TestResponseBehavior) + return @status rescue MultiPartNeededException boundary = "----------XnJLe9ZIbbGUYtzPQJ16u1" |