Skip to content
This repository
Browse code

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

…state:resolved]
  • Loading branch information...
commit 74436d2203eba186baebc1ddc82ff2202d0fc005 1 parent 6f20efd
Pratik lifo authored
7 actionpack/lib/action_view/template_finder.rb
@@ -24,7 +24,12 @@ def process_view_paths(*view_paths)
24 24 view_paths.flatten.compact.each do |dir|
25 25 next if @@processed_view_paths.has_key?(dir)
26 26 @@processed_view_paths[dir] = []
27   - Dir.glob("#{dir}/**/*/**").each do |file|
  27 +
  28 + #
  29 + # Dir.glob("#{dir}/**/*/**") reads all the directories in view path and templates inside those directories
  30 + # Dir.glob("#{dir}/**") reads templates residing at top level of view path
  31 + #
  32 + (Dir.glob("#{dir}/**/*/**") | Dir.glob("#{dir}/**")).each do |file|
28 33 unless File.directory?(file)
29 34 @@processed_view_paths[dir] << file.split(dir).last.sub(/^\//, '')
30 35
20 actionpack/test/controller/render_test.rb
@@ -23,6 +23,14 @@ def render_hello_world
23 23 def render_hello_world_with_forward_slash
24 24 render :template => "/test/hello_world"
25 25 end
  26 +
  27 + def render_template_in_top_directory
  28 + render :template => 'shared'
  29 + end
  30 +
  31 + def render_template_in_top_directory_with_slash
  32 + render :template => '/shared'
  33 + end
26 34
27 35 def render_hello_world_from_variable
28 36 @person = "david"
@@ -243,6 +251,18 @@ def test_render_with_forward_slash
243 251 get :render_hello_world_with_forward_slash
244 252 assert_template "test/hello_world"
245 253 end
  254 +
  255 + def test_render_in_top_directory
  256 + get :render_template_in_top_directory
  257 + assert_template "shared"
  258 + assert_equal "Elastica", @response.body
  259 + end
  260 +
  261 + def test_render_in_top_directory_with_slash
  262 + get :render_template_in_top_directory_with_slash
  263 + assert_template "shared"
  264 + assert_equal "Elastica", @response.body
  265 + end
246 266
247 267 def test_render_from_variable
248 268 get :render_hello_world_from_variable
1  actionpack/test/fixtures/shared.html.erb
... ... @@ -0,0 +1 @@
  1 +Elastica
5 actionpack/test/template/template_finder_test.rb
@@ -21,13 +21,14 @@ def test_should_cache_file_extension_properly
21 21 assert_equal ["builder", "erb", "rhtml", "rjs", "rxml", "mab"].sort,
22 22 ActionView::TemplateFinder.file_extension_cache[LOAD_PATH_ROOT].values.flatten.uniq.sort
23 23
24   - assert_equal Dir.glob("#{LOAD_PATH_ROOT}/**/*/*.{erb,rjs,rhtml,builder,rxml,mab}").size,
  24 + assert_equal (Dir.glob("#{LOAD_PATH_ROOT}/**/*/*.{erb,rjs,rhtml,builder,rxml,mab}") |
  25 + Dir.glob("#{LOAD_PATH_ROOT}/**.{erb,rjs,rhtml,builder,rxml,mab}")).size,
25 26 ActionView::TemplateFinder.file_extension_cache[LOAD_PATH_ROOT].keys.size
26 27 end
27 28
28 29 def test_should_cache_dir_content_properly
29 30 assert ActionView::TemplateFinder.processed_view_paths[LOAD_PATH_ROOT]
30   - assert_equal Dir.glob("#{LOAD_PATH_ROOT}/**/*/**").find_all {|f| !File.directory?(f) }.size,
  31 + assert_equal (Dir.glob("#{LOAD_PATH_ROOT}/**/*/**") | Dir.glob("#{LOAD_PATH_ROOT}/**")).find_all {|f| !File.directory?(f) }.size,
31 32 ActionView::TemplateFinder.processed_view_paths[LOAD_PATH_ROOT].size
32 33 end
33 34

0 comments on commit 74436d2

Please sign in to comment.
Something went wrong with that request. Please try again.