Skip to content

Commit 3ee59ee

Browse files
committed
Fix can't modify frozen String error in AC::Rendering
1 parent c2b2a8c commit 3ee59ee

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

actionpack/lib/action_controller/metal/rendering.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def render(*args) #:nodoc:
4242
def render_to_string(*)
4343
result = super
4444
if result.respond_to?(:each)
45-
string = ""
45+
string = "".dup
4646
result.each { |r| string << r }
4747
string
4848
else

actionpack/test/controller/render_test.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,18 @@ def test_access_to_logger_in_view
606606
end
607607
end
608608

609+
class ActionControllerRenderTest < ActionController::TestCase
610+
class MinimalController < ActionController::Metal
611+
include AbstractController::Rendering
612+
include ActionController::Rendering
613+
end
614+
615+
def test_direct_render_to_string_with_body
616+
mc = MinimalController.new
617+
assert_equal "Hello world!", mc.render_to_string(body: ["Hello world!"])
618+
end
619+
end
620+
609621
class ActionControllerBaseRenderTest < ActionController::TestCase
610622
def test_direct_render_to_string
611623
ac = ActionController::Base.new()

0 commit comments

Comments
 (0)