Skip to content

Commit

Permalink
ActionView::MissingTemplate for partials includes underscore.
Browse files Browse the repository at this point in the history
Missing partial folder/_partial instead of folder/partial.

Closes #13002.
  • Loading branch information
senny committed Dec 2, 2013
1 parent 2e296c8 commit 543ccf7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
6 changes: 6 additions & 0 deletions actionview/CHANGELOG.md
Original file line number Original file line Diff line number Diff line change
@@ -1,3 +1,9 @@
* `ActionView::MissingTemplate` includes underscore when raised for a partial.

Fixes #13002.

*Yves Senn*

* Use `set_backtrace` instead of instance variable `@backtrace` in ActionView exceptions * Use `set_backtrace` instead of instance variable `@backtrace` in ActionView exceptions


*Shimpei Makimoto* *Shimpei Makimoto*
Expand Down
3 changes: 3 additions & 0 deletions actionview/lib/action_view/template/error.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ def initialize(paths, path, prefixes, partial, details, *)
'template' 'template'
end end


if partial && path.present?
path = path.sub(%r{([^/]+)$}, "_\\1")
end
searched_paths = prefixes.map { |prefix| [prefix, path].join("/") } searched_paths = prefixes.map { |prefix| [prefix, path].join("/") }


out = "Missing #{template_type} #{searched_paths.join(", ")} with #{details.inspect}. Searched in:\n" out = "Missing #{template_type} #{searched_paths.join(", ")} with #{details.inspect}. Searched in:\n"
Expand Down
4 changes: 2 additions & 2 deletions actionview/test/template/lookup_context_test.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -249,15 +249,15 @@ def setup
e = assert_raise ActionView::MissingTemplate do e = assert_raise ActionView::MissingTemplate do
@lookup_context.find("foo", %w(parent child), true) @lookup_context.find("foo", %w(parent child), true)
end end
assert_match %r{Missing partial parent/foo, child/foo with .* Searched in:\n \* "/Path/to/views"\n}, e.message assert_match %r{Missing partial parent/_foo, child/_foo with .* Searched in:\n \* "/Path/to/views"\n}, e.message
end end


test "if a single prefix is passed as a string and the lookup fails, MissingTemplate accepts it" do test "if a single prefix is passed as a string and the lookup fails, MissingTemplate accepts it" do
e = assert_raise ActionView::MissingTemplate do e = assert_raise ActionView::MissingTemplate do
details = {:handlers=>[], :formats=>[], :locale=>[]} details = {:handlers=>[], :formats=>[], :locale=>[]}
@lookup_context.view_paths.find("foo", "parent", true, details) @lookup_context.view_paths.find("foo", "parent", true, details)
end end
assert_match %r{Missing partial parent/foo with .* Searched in:\n \* "/Path/to/views"\n}, e.message assert_match %r{Missing partial parent/_foo with .* Searched in:\n \* "/Path/to/views"\n}, e.message
end end


end end
4 changes: 2 additions & 2 deletions actionview/test/template/render_test.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def test_render_partial_use_last_prepended_format_for_partials_with_the_same_nam


def test_render_template_with_a_missing_partial_of_another_format def test_render_template_with_a_missing_partial_of_another_format
@view.lookup_context.formats = [:html] @view.lookup_context.formats = [:html]
assert_raise ActionView::Template::Error, "Missing partial /missing with {:locale=>[:en], :formats=>[:json], :handlers=>[:erb, :builder]}" do assert_raise ActionView::Template::Error, "Missing partial /_missing with {:locale=>[:en], :formats=>[:json], :handlers=>[:erb, :builder]}" do
@view.render(:template => "with_format", :formats => [:json]) @view.render(:template => "with_format", :formats => [:json])
end end
end end
Expand Down Expand Up @@ -444,7 +444,7 @@ def test_render_layout_with_a_nested_render_layout_call_using_block_with_render_


def test_render_partial_with_layout_raises_descriptive_error def test_render_partial_with_layout_raises_descriptive_error
e = assert_raises(ActionView::MissingTemplate) { @view.render(partial: 'test/partial', layout: true) } e = assert_raises(ActionView::MissingTemplate) { @view.render(partial: 'test/partial', layout: true) }
assert_match "Missing partial /true with", e.message assert_match "Missing partial /_true with", e.message
end end


def test_render_with_nested_layout def test_render_with_nested_layout
Expand Down

0 comments on commit 543ccf7

Please sign in to comment.