diff options
-rw-r--r-- | actionpack/lib/action_view/template_finder.rb | 7 | ||||
-rw-r--r-- | actionpack/test/controller/render_test.rb | 20 | ||||
-rw-r--r-- | actionpack/test/fixtures/shared.html.erb | 1 | ||||
-rw-r--r-- | actionpack/test/template/template_finder_test.rb | 5 |
4 files changed, 30 insertions, 3 deletions
diff --git a/actionpack/lib/action_view/template_finder.rb b/actionpack/lib/action_view/template_finder.rb index aaf34de538..83b7e27c09 100644 --- a/actionpack/lib/action_view/template_finder.rb +++ b/actionpack/lib/action_view/template_finder.rb @@ -24,7 +24,12 @@ module ActionView #:nodoc: view_paths.flatten.compact.each do |dir| next if @@processed_view_paths.has_key?(dir) @@processed_view_paths[dir] = [] - Dir.glob("#{dir}/**/*/**").each do |file| + + # + # Dir.glob("#{dir}/**/*/**") reads all the directories in view path and templates inside those directories + # Dir.glob("#{dir}/**") reads templates residing at top level of view path + # + (Dir.glob("#{dir}/**/*/**") | Dir.glob("#{dir}/**")).each do |file| unless File.directory?(file) @@processed_view_paths[dir] << file.split(dir).last.sub(/^\//, '') diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index 7491f16a84..066fa6acd4 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -23,6 +23,14 @@ class TestController < ActionController::Base def render_hello_world_with_forward_slash render :template => "/test/hello_world" end + + def render_template_in_top_directory + render :template => 'shared' + end + + def render_template_in_top_directory_with_slash + render :template => '/shared' + end def render_hello_world_from_variable @person = "david" @@ -243,6 +251,18 @@ class RenderTest < Test::Unit::TestCase get :render_hello_world_with_forward_slash assert_template "test/hello_world" end + + def test_render_in_top_directory + get :render_template_in_top_directory + assert_template "shared" + assert_equal "Elastica", @response.body + end + + def test_render_in_top_directory_with_slash + get :render_template_in_top_directory_with_slash + assert_template "shared" + assert_equal "Elastica", @response.body + end def test_render_from_variable get :render_hello_world_from_variable diff --git a/actionpack/test/fixtures/shared.html.erb b/actionpack/test/fixtures/shared.html.erb new file mode 100644 index 0000000000..af262fc9f8 --- /dev/null +++ b/actionpack/test/fixtures/shared.html.erb @@ -0,0 +1 @@ +Elastica
\ No newline at end of file diff --git a/actionpack/test/template/template_finder_test.rb b/actionpack/test/template/template_finder_test.rb index a162640de3..3d6baff5fb 100644 --- a/actionpack/test/template/template_finder_test.rb +++ b/actionpack/test/template/template_finder_test.rb @@ -21,13 +21,14 @@ class TemplateFinderTest < Test::Unit::TestCase assert_equal ["builder", "erb", "rhtml", "rjs", "rxml", "mab"].sort, ActionView::TemplateFinder.file_extension_cache[LOAD_PATH_ROOT].values.flatten.uniq.sort - assert_equal Dir.glob("#{LOAD_PATH_ROOT}/**/*/*.{erb,rjs,rhtml,builder,rxml,mab}").size, + assert_equal (Dir.glob("#{LOAD_PATH_ROOT}/**/*/*.{erb,rjs,rhtml,builder,rxml,mab}") | + Dir.glob("#{LOAD_PATH_ROOT}/**.{erb,rjs,rhtml,builder,rxml,mab}")).size, ActionView::TemplateFinder.file_extension_cache[LOAD_PATH_ROOT].keys.size end def test_should_cache_dir_content_properly assert ActionView::TemplateFinder.processed_view_paths[LOAD_PATH_ROOT] - assert_equal Dir.glob("#{LOAD_PATH_ROOT}/**/*/**").find_all {|f| !File.directory?(f) }.size, + assert_equal (Dir.glob("#{LOAD_PATH_ROOT}/**/*/**") | Dir.glob("#{LOAD_PATH_ROOT}/**")).find_all {|f| !File.directory?(f) }.size, ActionView::TemplateFinder.processed_view_paths[LOAD_PATH_ROOT].size end |