diff options
author | Jorge Bejar <jorge@wyeworks.com> | 2015-06-02 17:12:50 -0300 |
---|---|---|
committer | Santiago Pastorino <santiago@wyeworks.com> | 2015-06-11 16:54:17 -0300 |
commit | 6c165773117dc7e60f5bb4762e58c7c522d69fcc (patch) | |
tree | c3c3ed07ec0acf5fb1d420dc7f97a40cf6086bce /actionpack | |
parent | 8d3e6e5f4d97aa8f2b8b8dde949a1b79b50276d1 (diff) | |
download | rails-6c165773117dc7e60f5bb4762e58c7c522d69fcc.tar.gz rails-6c165773117dc7e60f5bb4762e58c7c522d69fcc.tar.bz2 rails-6c165773117dc7e60f5bb4762e58c7c522d69fcc.zip |
Return 204 if render is not called in API controllers
Diffstat (limited to 'actionpack')
5 files changed, 31 insertions, 6 deletions
diff --git a/actionpack/lib/action_controller.rb b/actionpack/lib/action_controller.rb index f6bc5b951c..89fc4520d3 100644 --- a/actionpack/lib/action_controller.rb +++ b/actionpack/lib/action_controller.rb @@ -25,6 +25,7 @@ module ActionController autoload :Head autoload :Helpers autoload :HttpAuthentication + autoload :BasicImplicitRender autoload :ImplicitRender autoload :Instrumentation autoload :MimeResponds diff --git a/actionpack/lib/action_controller/api.rb b/actionpack/lib/action_controller/api.rb index b4583a073b..6fab19296d 100644 --- a/actionpack/lib/action_controller/api.rb +++ b/actionpack/lib/action_controller/api.rb @@ -114,6 +114,7 @@ module ActionController Renderers::All, ConditionalGet, RackDelegation, + BasicImplicitRender, StrongParameters, ForceSSL, diff --git a/actionpack/lib/action_controller/metal/basic_implicit_render.rb b/actionpack/lib/action_controller/metal/basic_implicit_render.rb new file mode 100644 index 0000000000..6c6f8381ff --- /dev/null +++ b/actionpack/lib/action_controller/metal/basic_implicit_render.rb @@ -0,0 +1,11 @@ +module ActionController + module BasicImplicitRender + def send_action(method, *args) + super.tap { default_render unless performed? } + end + + def default_render(*args) + head :no_content + end + end +end diff --git a/actionpack/lib/action_controller/metal/implicit_render.rb b/actionpack/lib/action_controller/metal/implicit_render.rb index 1573ea7099..d66b2214ce 100644 --- a/actionpack/lib/action_controller/metal/implicit_render.rb +++ b/actionpack/lib/action_controller/metal/implicit_render.rb @@ -1,17 +1,14 @@ module ActionController module ImplicitRender - def send_action(method, *args) - ret = super - default_render unless performed? - ret - end + + include BasicImplicitRender def default_render(*args) if template_exists?(action_name.to_s, _prefixes, variants: request.variant) render(*args) else logger.info "No template found for #{self.class.name}\##{action_name}, rendering head :no_content" if logger - head :no_content + super end end diff --git a/actionpack/test/controller/api/implicit_render_test.rb b/actionpack/test/controller/api/implicit_render_test.rb new file mode 100644 index 0000000000..26f9cd8f78 --- /dev/null +++ b/actionpack/test/controller/api/implicit_render_test.rb @@ -0,0 +1,15 @@ +require 'abstract_unit' + +class ImplicitRenderAPITestController < ActionController::API + def empty_action + end +end + +class ImplicitRenderAPITest < ActionController::TestCase + tests ImplicitRenderAPITestController + + def test_implicit_no_content_response + get :empty_action + assert_response :no_content + end +end |