diff options
11 files changed, 63 insertions, 36 deletions
diff --git a/actionpack/lib/action_controller/abstract/renderer.rb b/actionpack/lib/action_controller/abstract/renderer.rb index 68c3b07b84..eb248652a8 100644 --- a/actionpack/lib/action_controller/abstract/renderer.rb +++ b/actionpack/lib/action_controller/abstract/renderer.rb @@ -17,7 +17,7 @@ module AbstractController end def render(options = {}) - self.response_body = render_to_string(options) + self.response_body = render_to_body(options) end # Raw rendering of a template. @@ -26,7 +26,7 @@ module AbstractController # @option _layout<String> The relative path to the layout template to use # # :api: plugin - def render_to_string(options = {}) + def render_to_body(options = {}) name = options[:_template_name] || action_name template = options[:_template] || view_paths.find_by_parts(name.to_s, formats, options[:_prefix]) @@ -55,4 +55,4 @@ module AbstractController end end end -end
\ No newline at end of file +end diff --git a/actionpack/lib/action_controller/base/responder.rb b/actionpack/lib/action_controller/base/responder.rb index 989f82444b..1aee980da6 100644 --- a/actionpack/lib/action_controller/base/responder.rb +++ b/actionpack/lib/action_controller/base/responder.rb @@ -5,18 +5,19 @@ module ActionController end private - def render_for_text(text = nil, append_response = false) #:nodoc: + def render_for_text(text) #:nodoc: @performed_render = true - if append_response - response.body ||= '' - response.body << text.to_s - else - response.body = case text - when Proc then text - when nil then " " # Safari doesn't pass the headers of the return if the response is zero length - else text.to_s + case text + when Proc + response.body = text + when nil + # Safari 2 doesn't pass response headers if the response is zero-length + if response.body_parts.empty? + response.body_parts << ' ' end + else + response.body_parts << text end end @@ -39,4 +40,4 @@ module ActionController end end end -end
\ No newline at end of file +end diff --git a/actionpack/lib/action_controller/new_base/base.rb b/actionpack/lib/action_controller/new_base/base.rb index 0400ddbf7a..08e7a1a0e7 100644 --- a/actionpack/lib/action_controller/new_base/base.rb +++ b/actionpack/lib/action_controller/new_base/base.rb @@ -42,7 +42,6 @@ module ActionController # :api: plugin def response_body=(body) - @_response["Content-Length"] = body.length @_response.body = body end @@ -58,4 +57,4 @@ module ActionController response.to_a end end -end
\ No newline at end of file +end diff --git a/actionpack/lib/action_controller/new_base/layouts.rb b/actionpack/lib/action_controller/new_base/layouts.rb index 149847c968..a8e0809ac6 100644 --- a/actionpack/lib/action_controller/new_base/layouts.rb +++ b/actionpack/lib/action_controller/new_base/layouts.rb @@ -9,7 +9,7 @@ module ActionController end end - def render_to_string(options) + def render_to_body(options) # render :text => ..., :layout => ... # or # render :anything_else @@ -34,4 +34,4 @@ module ActionController end end -end
\ No newline at end of file +end diff --git a/actionpack/lib/action_controller/new_base/renderer.rb b/actionpack/lib/action_controller/new_base/renderer.rb index 044c15f409..ed34c46aed 100644 --- a/actionpack/lib/action_controller/new_base/renderer.rb +++ b/actionpack/lib/action_controller/new_base/renderer.rb @@ -8,7 +8,7 @@ module ActionController end def render(action, options = {}) - # TODO: Move this into #render_to_string + # TODO: Move this into #render_to_body if action.is_a?(Hash) options, action = action, nil else @@ -17,10 +17,10 @@ module ActionController _process_options(options) - self.response_body = render_to_string(options) + self.response_body = render_to_body(options) end - def render_to_string(options) + def render_to_body(options) unless options.is_a?(Hash) options = {:action => options} end @@ -59,4 +59,4 @@ module ActionController end end end -end
\ No newline at end of file +end diff --git a/actionpack/lib/action_controller/testing/process.rb b/actionpack/lib/action_controller/testing/process.rb index 86e193efa9..7e2857614c 100644 --- a/actionpack/lib/action_controller/testing/process.rb +++ b/actionpack/lib/action_controller/testing/process.rb @@ -287,6 +287,7 @@ module ActionController #:nodoc: include TestResponseBehavior def recycle! + body_parts.clear headers.delete('ETag') headers.delete('Last-Modified') end diff --git a/actionpack/test/abstract_controller/abstract_controller_test.rb b/actionpack/test/abstract_controller/abstract_controller_test.rb index 6d33888821..8763ded57e 100644 --- a/actionpack/test/abstract_controller/abstract_controller_test.rb +++ b/actionpack/test/abstract_controller/abstract_controller_test.rb @@ -134,7 +134,7 @@ module AbstractController self.class.layout(formats) end - def render_to_string(options = {}) + def render_to_body(options = {}) options[:_layout] = options[:layout] || _layout super end @@ -223,4 +223,4 @@ module AbstractController end end -end
\ No newline at end of file +end diff --git a/actionpack/test/abstract_controller/layouts_test.rb b/actionpack/test/abstract_controller/layouts_test.rb index 5dd68ec28e..3d4570bfef 100644 --- a/actionpack/test/abstract_controller/layouts_test.rb +++ b/actionpack/test/abstract_controller/layouts_test.rb @@ -23,7 +23,7 @@ module AbstractControllerTests def controller_path() self.class.controller_path end - def render_to_string(options) + def render_to_body(options) options[:_layout] = _default_layout super end @@ -229,4 +229,4 @@ module AbstractControllerTests end end end -end
\ No newline at end of file +end diff --git a/activesupport/lib/active_support/core_ext/string/access.rb b/activesupport/lib/active_support/core_ext/string/access.rb index 7fb21fa4dd..e806b321f1 100644 --- a/activesupport/lib/active_support/core_ext/string/access.rb +++ b/activesupport/lib/active_support/core_ext/string/access.rb @@ -41,9 +41,15 @@ module ActiveSupport #:nodoc: # "hello".first(2) # => "he" # "hello".first(10) # => "hello" def first(limit = 1) - mb_chars[0..(limit - 1)].to_s + if limit == 0 + '' + elsif limit >= size + self + else + mb_chars[0...limit].to_s + end end - + # Returns the last character of the string or the last +limit+ characters. # # Examples: @@ -51,7 +57,13 @@ module ActiveSupport #:nodoc: # "hello".last(2) # => "lo" # "hello".last(10) # => "hello" def last(limit = 1) - (mb_chars[(-limit)..-1] || self).to_s + if limit == 0 + '' + elsif limit >= size + self + else + mb_chars[(-limit)..-1].to_s + end end end else @@ -69,11 +81,23 @@ module ActiveSupport #:nodoc: end def first(limit = 1) - self[0..(limit - 1)] + if limit == 0 + '' + elsif limit >= size + self + else + to(limit - 1) + end end def last(limit = 1) - from(-limit) || self + if limit == 0 + '' + elsif limit >= size + self + else + from(-limit) + end end end end diff --git a/activesupport/lib/active_support/new_callbacks.rb b/activesupport/lib/active_support/new_callbacks.rb index 2ac5339f07..356d70b650 100644 --- a/activesupport/lib/active_support/new_callbacks.rb +++ b/activesupport/lib/active_support/new_callbacks.rb @@ -116,12 +116,12 @@ module ActiveSupport end def normalize_options!(options) - options[:if] = Array(options[:if]) - options[:unless] = Array(options[:unless]) + options[:if] = Array.wrap(options[:if]) + options[:unless] = Array.wrap(options[:unless]) options[:per_key] ||= {} - options[:per_key][:if] = Array(options[:per_key][:if]) - options[:per_key][:unless] = Array(options[:per_key][:unless]) + options[:per_key][:if] = Array.wrap(options[:per_key][:if]) + options[:per_key][:unless] = Array.wrap(options[:per_key][:unless]) end def next_id @@ -246,11 +246,11 @@ module ActiveSupport conditions = [] unless options[:if].empty? - conditions << Array(_compile_filter(options[:if])) + conditions << Array.wrap(_compile_filter(options[:if])) end unless options[:unless].empty? - conditions << Array(_compile_filter(options[:unless])).map {|f| "!#{f}"} + conditions << Array.wrap(_compile_filter(options[:unless])).map {|f| "!#{f}"} end ["if #{conditions.flatten.join(" && ")}", "end"] diff --git a/activesupport/test/core_ext/string_ext_test.rb b/activesupport/test/core_ext/string_ext_test.rb index 6c9b7e7236..7d51e81feb 100644 --- a/activesupport/test/core_ext/string_ext_test.rb +++ b/activesupport/test/core_ext/string_ext_test.rb @@ -132,10 +132,12 @@ class StringInflectionsTest < Test::Unit::TestCase assert_equal "h", s.first assert_equal "he", s.first(2) + assert_equal "", s.first(0) assert_equal "o", s.last assert_equal "llo", s.last(3) assert_equal "hello", s.last(10) + assert_equal "", s.last(0) assert_equal 'x', 'x'.first assert_equal 'x', 'x'.first(4) |