2016-08-06 12:54:50 -04:00
|
|
|
require "abstract_unit"
|
2010-08-06 14:19:42 -04:00
|
|
|
|
|
|
|
class TestResponseTest < ActiveSupport::TestCase
|
|
|
|
def assert_response_code_range(range, predicate)
|
|
|
|
response = ActionDispatch::TestResponse.new
|
|
|
|
(0..599).each do |status|
|
|
|
|
response.status = status
|
|
|
|
assert_equal range.include?(status), response.send(predicate),
|
|
|
|
"ActionDispatch::TestResponse.new(#{status}).#{predicate}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test "helpers" do
|
2015-07-14 10:46:06 -04:00
|
|
|
assert_response_code_range 200..299, :successful?
|
|
|
|
assert_response_code_range [404], :not_found?
|
|
|
|
assert_response_code_range 300..399, :redirection?
|
2010-08-06 14:19:42 -04:00
|
|
|
assert_response_code_range 500..599, :server_error?
|
|
|
|
assert_response_code_range 400..499, :client_error?
|
|
|
|
end
|
2016-07-10 16:02:12 -04:00
|
|
|
|
|
|
|
test "response parsing" do
|
2016-08-06 12:54:50 -04:00
|
|
|
response = ActionDispatch::TestResponse.create(200, {}, "")
|
2016-07-10 16:02:12 -04:00
|
|
|
assert_equal response.body, response.parsed_body
|
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
response = ActionDispatch::TestResponse.create(200, { "Content-Type" => "application/json" }, '{ "foo": "fighters" }')
|
|
|
|
assert_equal({ "foo" => "fighters" }, response.parsed_body)
|
2016-07-10 16:02:12 -04:00
|
|
|
end
|
2010-08-06 14:19:42 -04:00
|
|
|
end
|