Permalink
Browse files

Fixed render :template for templates in top level of view path. [#54

…state:resolved]
  • Loading branch information...
1 parent 6f20efd commit 74436d2203eba186baebc1ddc82ff2202d0fc005 @lifo lifo committed May 1, 2008
View
7 actionpack/lib/action_view/template_finder.rb
@@ -24,7 +24,12 @@ def process_view_paths(*view_paths)
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(/^\//, '')
View
20 actionpack/test/controller/render_test.rb
@@ -23,6 +23,14 @@ def render_hello_world
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 @@ def test_render_with_forward_slash
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
View
1 actionpack/test/fixtures/shared.html.erb
@@ -0,0 +1 @@
+Elastica
View
5 actionpack/test/template/template_finder_test.rb
@@ -21,13 +21,14 @@ def test_should_cache_file_extension_properly
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

0 comments on commit 74436d2

Please sign in to comment.