2010-03-18 20:32:53 -04:00
|
|
|
require "abstract_unit"
|
|
|
|
|
|
|
|
module BareMetalTest
|
|
|
|
class BareController < ActionController::Metal
|
|
|
|
def index
|
|
|
|
self.response_body = "Hello world"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class BareTest < ActiveSupport::TestCase
|
|
|
|
test "response body is a Rack-compatible response" do
|
|
|
|
status, headers, body = BareController.action(:index).call(Rack::MockRequest.env_for("/"))
|
|
|
|
assert_equal 200, status
|
|
|
|
string = ""
|
|
|
|
|
|
|
|
body.each do |part|
|
|
|
|
assert part.is_a?(String), "Each part of the body must be a String"
|
|
|
|
string << part
|
|
|
|
end
|
|
|
|
|
2010-05-18 21:47:24 -04:00
|
|
|
assert_kind_of Hash, headers, "Headers must be a Hash"
|
2010-03-18 20:32:53 -04:00
|
|
|
assert headers["Content-Type"], "Content-Type must exist"
|
|
|
|
|
|
|
|
assert_equal "Hello world", string
|
|
|
|
end
|
|
|
|
end
|
2010-10-10 03:51:52 -04:00
|
|
|
|
|
|
|
class HeadController < ActionController::Metal
|
|
|
|
include ActionController::Head
|
|
|
|
|
|
|
|
def index
|
|
|
|
head :not_found
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class HeadTest < ActiveSupport::TestCase
|
|
|
|
test "head works on its own" do
|
2011-02-07 19:44:27 -05:00
|
|
|
status = HeadController.action(:index).call(Rack::MockRequest.env_for("/")).first
|
2010-10-10 03:51:52 -04:00
|
|
|
assert_equal 404, status
|
|
|
|
end
|
|
|
|
end
|
2010-11-06 19:00:26 -04:00
|
|
|
|
|
|
|
class BareControllerTest < ActionController::TestCase
|
|
|
|
test "GET index" do
|
|
|
|
get :index
|
|
|
|
assert_equal "Hello world", @response.body
|
|
|
|
end
|
|
|
|
end
|
2010-05-18 21:47:24 -04:00
|
|
|
end
|