From 30d49d001e9060d1898722dfa43b61b7daf90cd4 Mon Sep 17 00:00:00 2001 From: Burke Libbey Date: Fri, 6 May 2011 12:39:11 -0500 Subject: Made ActionView::MissingTemplate#initialize optionally accept a single string prefix to be converted to an array as in ActionView::PathSet#find_all. --- actionpack/lib/action_view/template/error.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/actionpack/lib/action_view/template/error.rb b/actionpack/lib/action_view/template/error.rb index e246646963..fa7a620daa 100644 --- a/actionpack/lib/action_view/template/error.rb +++ b/actionpack/lib/action_view/template/error.rb @@ -29,6 +29,7 @@ module ActionView def initialize(paths, path, prefixes, partial, details, *) @path = path + prefixes = [prefixes] if String === prefixes display_paths = paths.compact.map{ |p| p.to_s.inspect }.join(", ") template_type = if partial "partial" -- cgit v1.2.3 From 156039c4cf7f0e0ad697443b121b46d3fe57d801 Mon Sep 17 00:00:00 2001 From: Burke Libbey Date: Fri, 6 May 2011 14:02:31 -0500 Subject: Added a test for MissingTemplate change, and changed to use Array.wrap() as requested by josevalim. --- actionpack/lib/action_view/path_set.rb | 2 +- actionpack/lib/action_view/template/error.rb | 2 +- actionpack/test/template/lookup_context_test.rb | 9 +++++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/actionpack/lib/action_view/path_set.rb b/actionpack/lib/action_view/path_set.rb index 8b840a6463..1e38b82852 100644 --- a/actionpack/lib/action_view/path_set.rb +++ b/actionpack/lib/action_view/path_set.rb @@ -15,7 +15,7 @@ module ActionView #:nodoc: end def find_all(path, prefixes = [], *args) - prefixes = [prefixes] if String === prefixes + prefixes = Array.wrap(prefixes) if String === prefixes prefixes.each do |prefix| each do |resolver| templates = resolver.find_all(path, prefix, *args) diff --git a/actionpack/lib/action_view/template/error.rb b/actionpack/lib/action_view/template/error.rb index fa7a620daa..6eec0cc23d 100644 --- a/actionpack/lib/action_view/template/error.rb +++ b/actionpack/lib/action_view/template/error.rb @@ -29,7 +29,7 @@ module ActionView def initialize(paths, path, prefixes, partial, details, *) @path = path - prefixes = [prefixes] if String === prefixes + prefixes = Array.wrap(prefixes) if String === prefixes display_paths = paths.compact.map{ |p| p.to_s.inspect }.join(", ") template_type = if partial "partial" diff --git a/actionpack/test/template/lookup_context_test.rb b/actionpack/test/template/lookup_context_test.rb index 5fb1fdc044..94af97ee11 100644 --- a/actionpack/test/template/lookup_context_test.rb +++ b/actionpack/test/template/lookup_context_test.rb @@ -251,4 +251,13 @@ class TestMissingTemplate < ActiveSupport::TestCase end assert_match %r{Missing partial parent/foo, child/foo with .* Searched in:\n \* "/Path/to/views"\n}, e.message end + + test "if a single prefix is passed as a string and the lookup fails, MissingTemplate accepts it" do + e = assert_raise ActionView::MissingTemplate do + details = {:handlers=>[], :formats=>[], :locale=>[]} + @lookup_context.view_paths.find("foo", "parent", true, details) + end + assert_match %r{Missing partial parent/foo with .* Searched in:\n \* "/Path/to/views"\n}, e.message + end + end -- cgit v1.2.3 From 4c4d5c7e6c028c6a29701abb0f64231ff284a466 Mon Sep 17 00:00:00 2001 From: Burke Libbey Date: Fri, 6 May 2011 15:28:31 -0500 Subject: Remove redundant check for is_a?(String) --- actionpack/lib/action_view/path_set.rb | 2 +- actionpack/lib/action_view/template/error.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/actionpack/lib/action_view/path_set.rb b/actionpack/lib/action_view/path_set.rb index 1e38b82852..ea5b71bb03 100644 --- a/actionpack/lib/action_view/path_set.rb +++ b/actionpack/lib/action_view/path_set.rb @@ -15,7 +15,7 @@ module ActionView #:nodoc: end def find_all(path, prefixes = [], *args) - prefixes = Array.wrap(prefixes) if String === prefixes + prefixes = Array.wrap(prefixes) prefixes.each do |prefix| each do |resolver| templates = resolver.find_all(path, prefix, *args) diff --git a/actionpack/lib/action_view/template/error.rb b/actionpack/lib/action_view/template/error.rb index 6eec0cc23d..1ee05c8f6f 100644 --- a/actionpack/lib/action_view/template/error.rb +++ b/actionpack/lib/action_view/template/error.rb @@ -29,7 +29,7 @@ module ActionView def initialize(paths, path, prefixes, partial, details, *) @path = path - prefixes = Array.wrap(prefixes) if String === prefixes + prefixes = Array.wrap(prefixes) display_paths = paths.compact.map{ |p| p.to_s.inspect }.join(", ") template_type = if partial "partial" -- cgit v1.2.3 From 06671c37de93702323ee281aedc4023bb8d7cdb6 Mon Sep 17 00:00:00 2001 From: Burke Libbey Date: Sat, 7 May 2011 18:30:50 -0500 Subject: Added activesupport requires for Array.wrap in previously modified files --- actionpack/lib/action_view/path_set.rb | 2 ++ actionpack/lib/action_view/template/error.rb | 1 + 2 files changed, 3 insertions(+) diff --git a/actionpack/lib/action_view/path_set.rb b/actionpack/lib/action_view/path_set.rb index ea5b71bb03..54b9a6d39e 100644 --- a/actionpack/lib/action_view/path_set.rb +++ b/actionpack/lib/action_view/path_set.rb @@ -1,3 +1,5 @@ +require "active_support/core_ext/array/wrap" + module ActionView #:nodoc: # = Action View PathSet class PathSet < Array #:nodoc: diff --git a/actionpack/lib/action_view/template/error.rb b/actionpack/lib/action_view/template/error.rb index 1ee05c8f6f..d4448a7b33 100644 --- a/actionpack/lib/action_view/template/error.rb +++ b/actionpack/lib/action_view/template/error.rb @@ -1,3 +1,4 @@ +require "active_support/core_ext/array/wrap" require "active_support/core_ext/enumerable" module ActionView -- cgit v1.2.3