mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Re-add ActionController::ApiRendering
- Fixes bug #23142. - Bug was occurring only with ActionController::API, because `_process_options` wasn't being run for API requests, even though it was being run for normal app requests.
This commit is contained in:
parent
06397336b2
commit
77acc004ef
4 changed files with 39 additions and 1 deletions
|
@ -41,6 +41,10 @@ module ActionController
|
|||
autoload :UrlFor
|
||||
end
|
||||
|
||||
autoload_under "api" do
|
||||
autoload :ApiRendering
|
||||
end
|
||||
|
||||
autoload :TestCase, 'action_controller/test_case'
|
||||
autoload :TemplateAssertions, 'action_controller/test_case'
|
||||
|
||||
|
|
|
@ -112,7 +112,7 @@ module ActionController
|
|||
|
||||
UrlFor,
|
||||
Redirecting,
|
||||
Rendering,
|
||||
ApiRendering,
|
||||
Renderers::All,
|
||||
ConditionalGet,
|
||||
BasicImplicitRender,
|
||||
|
|
14
actionpack/lib/action_controller/api/api_rendering.rb
Normal file
14
actionpack/lib/action_controller/api/api_rendering.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
module ActionController
|
||||
module ApiRendering
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
include Rendering
|
||||
end
|
||||
|
||||
def render_to_body(options = {})
|
||||
_process_options(options)
|
||||
super
|
||||
end
|
||||
end
|
||||
end
|
|
@ -19,6 +19,14 @@ class RenderersApiController < ActionController::API
|
|||
def two
|
||||
render xml: Model.new
|
||||
end
|
||||
|
||||
def plain
|
||||
render plain: 'Hi from plain', status: 500
|
||||
end
|
||||
|
||||
def text
|
||||
render text: 'Hi from text', status: 500
|
||||
end
|
||||
end
|
||||
|
||||
class RenderersApiTest < ActionController::TestCase
|
||||
|
@ -35,4 +43,16 @@ class RenderersApiTest < ActionController::TestCase
|
|||
assert_response :success
|
||||
assert_equal({ a: 'b' }.to_xml, @response.body)
|
||||
end
|
||||
|
||||
def test_render_plain
|
||||
get :plain
|
||||
assert_response :internal_server_error
|
||||
assert_equal('Hi from plain', @response.body)
|
||||
end
|
||||
|
||||
def test_render_text
|
||||
get :text
|
||||
assert_response :internal_server_error
|
||||
assert_equal('Hi from text', @response.body)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue