File tree Expand file tree Collapse file tree 3 files changed +38
-0
lines changed
lib/action_controller/metal Expand file tree Collapse file tree 3 files changed +38
-0
lines changed Original file line number Diff line number Diff line change
1
+ * Raise ` AbstractController::DoubleRenderError ` if ` head ` is called after rendering.
2
+
3
+ After this change, invoking ` head ` will lead to an error if response body is already set:
4
+
5
+ ``` ruby
6
+ class PostController < ApplicationController
7
+ def index
8
+ render locals: {}
9
+ head :ok
10
+ end
11
+ end
12
+ ```
13
+
14
+ * Iaroslav Kurbatov *
15
+
1
16
* The Cookie Serializer can now serialize an Active Support SafeBuffer when using message pack.
2
17
3
18
Such code would previously produce an error if an application was using messagepack as its cookie serializer.
Original file line number Diff line number Diff line change @@ -25,6 +25,8 @@ def head(status, options = nil)
25
25
raise ArgumentError , "#{ status . inspect } is not a valid value for `status`."
26
26
end
27
27
28
+ raise ::AbstractController ::DoubleRenderError if response_body
29
+
28
30
status ||= :ok
29
31
30
32
if options
Original file line number Diff line number Diff line change @@ -49,6 +49,13 @@ def index
49
49
end
50
50
end
51
51
52
+ class DoubleRenderWithHeadController < ActionController ::Base
53
+ def index
54
+ render plain : "hello"
55
+ head :bad_request
56
+ end
57
+ end
58
+
52
59
class ChildRenderController < BlankRenderController
53
60
append_view_path ActionView ::FixtureResolver . new ( "render/child_render/overridden_with_own_view_paths_appended.html.erb" => "child content" )
54
61
prepend_view_path ActionView ::FixtureResolver . new ( "render/child_render/overridden_with_own_view_paths_prepended.html.erb" => "child content" )
@@ -83,6 +90,20 @@ class RenderTest < Rack::TestCase
83
90
end
84
91
end
85
92
end
93
+
94
+ test "using head after rendering raises an exception" do
95
+ with_routing do |set |
96
+ set . draw do
97
+ ActionDispatch . deprecator . silence do
98
+ get ":controller" , action : "index"
99
+ end
100
+ end
101
+
102
+ assert_raises ( AbstractController ::DoubleRenderError ) do
103
+ get "/render/double_render_with_head" , headers : { "action_dispatch.show_exceptions" => :none }
104
+ end
105
+ end
106
+ end
86
107
end
87
108
88
109
class TestOnlyRenderPublicActions < Rack ::TestCase
You can’t perform that action at this time.
0 commit comments