From cc3e738d89cc5a433473559c3f70e98c08f646de Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Mon, 7 Nov 2011 16:24:54 +0900 Subject: Fix AC::Metal#response_body= to store same value on Ruby 1.8 and 1.9 This was because String#respond_to?(:each) differs in 1.8 and 1.9 --- actionpack/lib/action_controller/metal.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/actionpack/lib/action_controller/metal.rb b/actionpack/lib/action_controller/metal.rb index 0133b2ecbc..125dbf6bb5 100644 --- a/actionpack/lib/action_controller/metal.rb +++ b/actionpack/lib/action_controller/metal.rb @@ -182,7 +182,13 @@ module ActionController end def response_body=(val) - body = val.nil? ? nil : (val.respond_to?(:each) ? val : [val]) + body = if val.is_a?(String) + [val] + elsif val.nil? || val.respond_to?(:each) + val + else + [val] + end super body end -- cgit v1.2.3 From be7ab83b647c1ebb619b88854d310497075ea58f Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Thu, 10 Nov 2011 10:54:56 +0900 Subject: A test case to ensure that AC::Metal#response_body= always wraps the given value in an Array in both Ruby 1.8 and 1.9 (refs #3581) --- actionpack/test/controller/new_base/bare_metal_test.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/actionpack/test/controller/new_base/bare_metal_test.rb b/actionpack/test/controller/new_base/bare_metal_test.rb index 3ca29f1bcf..c424dcbd8d 100644 --- a/actionpack/test/controller/new_base/bare_metal_test.rb +++ b/actionpack/test/controller/new_base/bare_metal_test.rb @@ -23,6 +23,12 @@ module BareMetalTest assert_equal "Hello world", string end + + test "response_body value is wrapped in an array when the value is a String" do + controller = BareController.new + controller.index + assert_equal ["Hello world"], controller.response_body + end end class HeadController < ActionController::Metal -- cgit v1.2.3