2017-07-24 16:20:53 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
require "abstract_unit"
|
|
|
|
require "active_support/core_ext/hash/conversions"
|
2015-12-06 17:49:52 -05:00
|
|
|
|
2016-05-31 11:21:30 -04:00
|
|
|
class MetalRenderingController < ActionController::Metal
|
|
|
|
include AbstractController::Rendering
|
|
|
|
include ActionController::Rendering
|
|
|
|
include ActionController::Renderers
|
|
|
|
end
|
|
|
|
|
2015-12-06 17:49:52 -05:00
|
|
|
class MetalRenderingJsonController < MetalRenderingController
|
|
|
|
class Model
|
|
|
|
def to_json(options = {})
|
2016-08-06 12:54:50 -04:00
|
|
|
{ a: "b" }.to_json(options)
|
2015-12-06 17:49:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def to_xml(options = {})
|
2016-08-06 12:54:50 -04:00
|
|
|
{ a: "b" }.to_xml(options)
|
2015-12-06 17:49:52 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
use_renderers :json
|
|
|
|
|
|
|
|
def one
|
|
|
|
render json: Model.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def two
|
|
|
|
render xml: Model.new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class RenderersMetalTest < ActionController::TestCase
|
|
|
|
tests MetalRenderingJsonController
|
|
|
|
|
|
|
|
def test_render_json
|
|
|
|
get :one
|
|
|
|
assert_response :success
|
2016-08-06 12:54:50 -04:00
|
|
|
assert_equal({ a: "b" }.to_json, @response.body)
|
2019-04-17 02:37:16 -04:00
|
|
|
assert_equal "application/json", @response.media_type
|
2015-12-06 17:49:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_render_xml
|
|
|
|
get :two
|
|
|
|
assert_response :success
|
|
|
|
assert_equal(" ", @response.body)
|
2019-04-17 02:37:16 -04:00
|
|
|
assert_equal "text/plain", @response.media_type
|
2015-12-06 17:49:52 -05:00
|
|
|
end
|
|
|
|
end
|