From 30fa377f330ca8a9543e7079ed6f90a7ca42668d Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Tue, 1 Apr 2008 07:39:04 +0000 Subject: [PATCH] Ruby 1.9 compat: encoding and multibyte test fixes git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9194 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_controller/layout.rb | 42 ++++++++++---------- actionpack/test/controller/request_test.rb | 6 ++- actionpack/test/template/text_helper_test.rb | 8 ++-- 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/actionpack/lib/action_controller/layout.rb b/actionpack/lib/action_controller/layout.rb index e1853ad131..5484add3b5 100644 --- a/actionpack/lib/action_controller/layout.rb +++ b/actionpack/lib/action_controller/layout.rb @@ -65,15 +65,15 @@ class << self # == Automatic layout assignment # # If there is a template in app/views/layouts/ with the same name as the current controller then it will be automatically - # set as that controller's layout unless explicitly told otherwise. Say you have a WeblogController, for example. If a template named + # set as that controller's layout unless explicitly told otherwise. Say you have a WeblogController, for example. If a template named # app/views/layouts/weblog.erb or app/views/layouts/weblog.builder exists then it will be automatically set as # the layout for your WeblogController. You can create a layout with the name application.erb or application.builder - # and this will be set as the default controller if there is no layout with the same name as the current controller and there is + # and this will be set as the default controller if there is no layout with the same name as the current controller and there is # no layout explicitly assigned with the +layout+ method. Nested controllers use the same folder structure for automatic layout. # assignment. So an Admin::WeblogController will look for a template named app/views/layouts/admin/weblog.erb. # Setting a layout explicitly will always override the automatic behaviour for the controller where the layout is set. # Explicitly setting the layout in a parent class, though, will not override the child class's layout assignment if the child - # class has a layout with the same name. + # class has a layout with the same name. # # == Inheritance for layouts # @@ -113,7 +113,7 @@ class << self # logged_in? ? "writer_layout" : "reader_layout" # end # - # Now when a new request for the index action is processed, the layout will vary depending on whether the person accessing + # Now when a new request for the index action is processed, the layout will vary depending on whether the person accessing # is logged in or not. # # If you want to use an inline method, such as a proc, do something like this: @@ -132,24 +132,24 @@ class << self # == Conditional layouts # # If you have a layout that by default is applied to all the actions of a controller, you still have the option of rendering - # a given action or set of actions without a layout, or restricting a layout to only a single action or a set of actions. The + # a given action or set of actions without a layout, or restricting a layout to only a single action or a set of actions. The # :only and :except options can be passed to the layout call. For example: # # class WeblogController < ActionController::Base # layout "weblog_standard", :except => :rss - # + # # # ... # # end # - # This will assign "weblog_standard" as the WeblogController's layout except for the +rss+ action, which will not wrap a layout + # This will assign "weblog_standard" as the WeblogController's layout except for the +rss+ action, which will not wrap a layout # around the rendered view. # - # Both the :only and :except condition can accept an arbitrary number of method references, so + # Both the :only and :except condition can accept an arbitrary number of method references, so # #:except => [ :rss, :text_only ] is valid, as is :except => :rss. # # == Using a different layout in the action render call - # + # # If most of your actions use the same layout, it makes perfect sense to define a controller-wide layout as described above. # Sometimes you'll have exceptions where one action wants to use a different layout than the rest of the controller. # You can do this by passing a :layout option to the render call. For example: @@ -176,21 +176,19 @@ def layout(template_name, conditions = {}, auto = false) def layout_conditions #:nodoc: @layout_conditions ||= read_inheritable_attribute("layout_conditions") end - + def default_layout(format) #:nodoc: - layout = read_inheritable_attribute("layout") + layout = read_inheritable_attribute("layout") return layout unless read_inheritable_attribute("auto_layout") @default_layout ||= {} @default_layout[format] ||= default_layout_with_format(format, layout) @default_layout[format] end - + def layout_list #:nodoc: - view_paths.collect do |path| - Dir["#{path}/layouts/**/*"] - end.flatten + Array(view_paths).sum([]) { |path| Dir["#{path}/layouts/**/*"] } end - + private def inherited_with_layout(child) inherited_without_layout(child) @@ -207,7 +205,7 @@ def add_layout_conditions(conditions) def normalize_conditions(conditions) conditions.inject({}) {|hash, (key, value)| hash.merge(key => [value].flatten.map {|action| action.to_s})} end - + def default_layout_with_format(format, layout) list = layout_list if list.grep(%r{layouts/#{layout}\.#{format}(\.[a-z][0-9a-z]*)+$}).empty? @@ -229,7 +227,7 @@ def active_layout(passed_layout = nil) when Symbol then send!(layout) when Proc then layout.call(self) end - + # Explicitly passed layout names with slashes are looked up relative to the template root, # but auto-discovered layouts derived from a nested controller will contain a slash, though be relative # to the 'layouts' directory so we have to check the file system to infer which case the layout name came from. @@ -245,7 +243,7 @@ def active_layout(passed_layout = nil) protected def render_with_a_layout(options = nil, extra_options = {}, &block) #:nodoc: template_with_options = options.is_a?(Hash) - + if apply_layout?(template_with_options, options) && (layout = pick_layout(template_with_options, options)) assert_existence_of_template_file(layout) @@ -272,7 +270,7 @@ def apply_layout?(template_with_options, options) end def candidate_for_layout?(options) - (options.has_key?(:layout) && options[:layout] != false) || + (options.has_key?(:layout) && options[:layout] != false) || options.values_at(:text, :xml, :json, :file, :inline, :partial, :nothing).compact.empty? && !template_exempt_from_layout?(options[:template] || default_template_name(options[:action])) end @@ -298,7 +296,7 @@ def action_has_layout? when only = conditions[:only] only.include?(action_name) when except = conditions[:except] - !except.include?(action_name) + !except.include?(action_name) else true end @@ -306,7 +304,7 @@ def action_has_layout? true end end - + def layout_directory?(layout_name) @template.finder.find_template_extension_from_handler(File.join('layouts', layout_name)) end diff --git a/actionpack/test/controller/request_test.rb b/actionpack/test/controller/request_test.rb index 4d645f56e0..6916e13417 100644 --- a/actionpack/test/controller/request_test.rb +++ b/actionpack/test/controller/request_test.rb @@ -835,8 +835,10 @@ def test_mixed_files assert_equal 'bar', params['foo'] # Ruby CGI doesn't handle multipart/mixed for us. - assert_kind_of String, params['files'] - assert_equal 19756, params['files'].size + files = params['files'] + assert_kind_of String, files + files.force_encoding('ASCII-8BIT') if files.respond_to?(:force_encoding) + assert_equal 19756, files.size end private diff --git a/actionpack/test/template/text_helper_test.rb b/actionpack/test/template/text_helper_test.rb index 0cd83334d5..7d92bce4bd 100644 --- a/actionpack/test/template/text_helper_test.rb +++ b/actionpack/test/template/text_helper_test.rb @@ -136,16 +136,16 @@ def test_excerpt_with_regex if RUBY_VERSION < '1.9' def test_excerpt_with_utf8 with_kcode('u') do - assert_equal("...fficiency could not be...", excerpt("That's why efficiency could not be helped", 'could', 8)) + assert_equal("...\357\254\203ciency could not be...", excerpt("That's why e\357\254\203ciency could not be helped", 'could', 8)) end with_kcode('none') do - assert_equal("...\203ciency could not be...", excerpt("That's why efficiency could not be helped", 'could', 8)) + assert_equal("...\203ciency could not be...", excerpt("That's why e\357\254\203ciency could not be helped", 'could', 8)) end end else def test_excerpt_with_utf8 - assert_equal("...fficiency could not be...".force_encoding('UTF-8'), excerpt("That's why efficiency could not be helped".force_encoding('UTF-8'), 'could', 8)) - assert_equal("...\203ciency could not be...", excerpt("That's why efficiency could not be helped", 'could', 8)) + assert_equal("...\357\254\203ciency could not be...".force_encoding('UTF-8'), excerpt("That's why e\357\254\203ciency could not be helped".force_encoding('UTF-8'), 'could', 8)) + assert_equal("...\203ciency could not be...", excerpt("That's why e\357\254\203ciency could not be helped", 'could', 8)) end end -- GitLab