diff options
author | Joshua Peek <josh@joshpeek.com> | 2008-08-13 19:15:35 -0500 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2008-08-13 19:15:35 -0500 |
commit | 3b9324e62f770f1a0a457f7ad5fe6a3287ecae1f (patch) | |
tree | 649553b482c831ec58817b41d0fb18a995a3df66 | |
parent | 04248c62086b188ae354ed90ae40c832b79fd19c (diff) | |
download | rails-3b9324e62f770f1a0a457f7ad5fe6a3287ecae1f.tar.gz rails-3b9324e62f770f1a0a457f7ad5fe6a3287ecae1f.tar.bz2 rails-3b9324e62f770f1a0a457f7ad5fe6a3287ecae1f.zip |
Fix rendering partials at the top level [#795 state:resolved]
-rw-r--r-- | actionpack/lib/action_view/partials.rb | 2 | ||||
-rw-r--r-- | actionpack/test/fixtures/_top_level_partial.html.erb | 1 | ||||
-rw-r--r-- | actionpack/test/fixtures/_top_level_partial_only.erb | 1 | ||||
-rw-r--r-- | actionpack/test/template/render_test.rb | 18 |
4 files changed, 21 insertions, 1 deletions
diff --git a/actionpack/lib/action_view/partials.rb b/actionpack/lib/action_view/partials.rb index eb74d4a4c7..894b88534c 100644 --- a/actionpack/lib/action_view/partials.rb +++ b/actionpack/lib/action_view/partials.rb @@ -146,7 +146,7 @@ module ActionView def find_partial_path(partial_path) if partial_path.include?('/') - "#{File.dirname(partial_path)}/_#{File.basename(partial_path)}" + File.join(File.dirname(partial_path), "_#{File.basename(partial_path)}") elsif respond_to?(:controller) "#{controller.class.controller_path}/_#{partial_path}" else diff --git a/actionpack/test/fixtures/_top_level_partial.html.erb b/actionpack/test/fixtures/_top_level_partial.html.erb new file mode 100644 index 0000000000..0b1c2e46e0 --- /dev/null +++ b/actionpack/test/fixtures/_top_level_partial.html.erb @@ -0,0 +1 @@ +top level partial html
\ No newline at end of file diff --git a/actionpack/test/fixtures/_top_level_partial_only.erb b/actionpack/test/fixtures/_top_level_partial_only.erb new file mode 100644 index 0000000000..44f25b61d0 --- /dev/null +++ b/actionpack/test/fixtures/_top_level_partial_only.erb @@ -0,0 +1 @@ +top level partial
\ No newline at end of file diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb index c37bac95f1..31cfdce531 100644 --- a/actionpack/test/template/render_test.rb +++ b/actionpack/test/template/render_test.rb @@ -19,6 +19,10 @@ class ViewRenderTest < Test::Unit::TestCase assert_equal "Hello world!", @view.render("test/hello_world") end + def test_render_file_at_top_level + assert_equal 'Elastica', @view.render('/shared') + end + def test_render_file_with_full_path template_path = File.join(File.dirname(__FILE__), '../fixtures/test/hello_world.erb') assert_equal "Hello world!", @view.render(:file => template_path) @@ -47,6 +51,20 @@ class ViewRenderTest < Test::Unit::TestCase assert_equal "only partial", @view.render(:partial => "test/partial_only") end + def test_render_partial_with_format + assert_equal 'partial html', @view.render(:partial => 'test/partial') + end + + def test_render_partial_at_top_level + # file fixtures/_top_level_partial_only.erb (not fixtures/test) + assert_equal 'top level partial', @view.render(:partial => '/top_level_partial_only') + end + + def test_render_partial_with_format_at_top_level + # file fixtures/_top_level_partial.html.erb (not fixtures/test, with format extension) + assert_equal 'top level partial html', @view.render(:partial => '/top_level_partial') + end + def test_render_partial_with_locals assert_equal "5", @view.render(:partial => "test/counter", :locals => { :counter_counter => 5 }) end |