public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Fixed render :template for templates in top level of view path. [#54 
state:resolved]
lifo (author)
Thu May 01 02:21:46 -0700 2008
commit  74436d2203eba186baebc1ddc82ff2202d0fc005
tree    e5a8b5297edec740d5121275d19af7805a32bae0
parent  6f20efdaf733db26fbf337da73121983785064d5
...
24
25
26
27
 
 
 
 
 
 
28
29
30
...
24
25
26
 
27
28
29
30
31
32
33
34
35
0
@@ -24,7 +24,12 @@ module ActionView #:nodoc:
0
         view_paths.flatten.compact.each do |dir|
0
           next if @@processed_view_paths.has_key?(dir)
0
           @@processed_view_paths[dir] = []
0
-          Dir.glob("#{dir}/**/*/**").each do |file|
0
+          
0
+          # 
0
+          # Dir.glob("#{dir}/**/*/**") reads all the directories in view path and templates inside those directories
0
+          # Dir.glob("#{dir}/**") reads templates residing at top level of view path
0
+          # 
0
+          (Dir.glob("#{dir}/**/*/**") | Dir.glob("#{dir}/**")).each do |file|
0
             unless File.directory?(file)
0
               @@processed_view_paths[dir] << file.split(dir).last.sub(/^\//, '')
0
 
...
23
24
25
 
 
 
 
 
 
 
 
26
27
28
...
243
244
245
 
 
 
 
 
 
 
 
 
 
 
 
246
247
248
...
23
24
25
26
27
28
29
30
31
32
33
34
35
36
...
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
0
@@ -23,6 +23,14 @@ class TestController < ActionController::Base
0
   def render_hello_world_with_forward_slash
0
     render :template => "/test/hello_world"
0
   end
0
+  
0
+  def render_template_in_top_directory
0
+    render :template => 'shared'
0
+  end
0
+  
0
+  def render_template_in_top_directory_with_slash
0
+    render :template => '/shared'
0
+  end
0
 
0
   def render_hello_world_from_variable
0
     @person = "david"
0
@@ -243,6 +251,18 @@ class RenderTest < Test::Unit::TestCase
0
     get :render_hello_world_with_forward_slash
0
     assert_template "test/hello_world"
0
   end
0
+  
0
+  def test_render_in_top_directory
0
+    get :render_template_in_top_directory
0
+    assert_template "shared"
0
+    assert_equal "Elastica", @response.body
0
+  end
0
+  
0
+  def test_render_in_top_directory_with_slash
0
+    get :render_template_in_top_directory_with_slash
0
+    assert_template "shared"
0
+    assert_equal "Elastica", @response.body
0
+  end
0
 
0
   def test_render_from_variable
0
     get :render_hello_world_from_variable
...
21
22
23
24
 
 
25
26
27
28
29
30
 
31
32
33
...
21
22
23
 
24
25
26
27
28
29
30
 
31
32
33
34
0
@@ -21,13 +21,14 @@ class TemplateFinderTest < Test::Unit::TestCase
0
     assert_equal ["builder", "erb", "rhtml", "rjs", "rxml", "mab"].sort,
0
                  ActionView::TemplateFinder.file_extension_cache[LOAD_PATH_ROOT].values.flatten.uniq.sort
0
 
0
-    assert_equal Dir.glob("#{LOAD_PATH_ROOT}/**/*/*.{erb,rjs,rhtml,builder,rxml,mab}").size,
0
+    assert_equal (Dir.glob("#{LOAD_PATH_ROOT}/**/*/*.{erb,rjs,rhtml,builder,rxml,mab}") |
0
+                  Dir.glob("#{LOAD_PATH_ROOT}/**.{erb,rjs,rhtml,builder,rxml,mab}")).size,
0
                  ActionView::TemplateFinder.file_extension_cache[LOAD_PATH_ROOT].keys.size
0
   end
0
 
0
   def test_should_cache_dir_content_properly
0
     assert ActionView::TemplateFinder.processed_view_paths[LOAD_PATH_ROOT]
0
-    assert_equal Dir.glob("#{LOAD_PATH_ROOT}/**/*/**").find_all {|f| !File.directory?(f) }.size,
0
+    assert_equal (Dir.glob("#{LOAD_PATH_ROOT}/**/*/**") | Dir.glob("#{LOAD_PATH_ROOT}/**")).find_all {|f| !File.directory?(f) }.size,
0
                ActionView::TemplateFinder.processed_view_paths[LOAD_PATH_ROOT].size
0
   end
0
 

Comments