mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Refactor suggestions into all_template_paths
This commit is contained in:
parent
6029b065d0
commit
6d11711042
3 changed files with 18 additions and 7 deletions
|
@ -93,16 +93,16 @@ module ActionView
|
||||||
def corrections
|
def corrections
|
||||||
path = @error.path
|
path = @error.path
|
||||||
prefixes = @error.prefixes
|
prefixes = @error.prefixes
|
||||||
candidates = @error.paths.flat_map(&:template_paths_for_suggestions).uniq
|
candidates = @error.paths.flat_map(&:all_template_paths).uniq
|
||||||
|
|
||||||
# Group by possible prefixes
|
# Group by possible prefixes
|
||||||
files_by_dir = candidates.group_by do |x|
|
files_by_dir = candidates.group_by do |x|
|
||||||
File.dirname(x)
|
File.dirname(x)
|
||||||
end.transform_values do |files|
|
end.transform_values do |files|
|
||||||
files.map do |file|
|
files.map do |file|
|
||||||
# Remove template extensions
|
# Remove directory
|
||||||
File.basename(file).split(".", 2)[0]
|
File.basename(file)
|
||||||
end.uniq
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# No suggestions if there's an exact match, but wrong details
|
# No suggestions if there's an exact match, but wrong details
|
||||||
|
|
|
@ -160,7 +160,7 @@ module ActionView
|
||||||
@cache.cache_query(query) { find_template_paths(File.join(@path, query)) }
|
@cache.cache_query(query) { find_template_paths(File.join(@path, query)) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def template_paths_for_suggestions # :nodoc:
|
def all_template_paths # :nodoc:
|
||||||
# Not implemented by default
|
# Not implemented by default
|
||||||
[]
|
[]
|
||||||
end
|
end
|
||||||
|
@ -343,8 +343,13 @@ module ActionView
|
||||||
end
|
end
|
||||||
alias :== :eql?
|
alias :== :eql?
|
||||||
|
|
||||||
def template_paths_for_suggestions # :nodoc:
|
def all_template_paths # :nodoc:
|
||||||
Dir.glob("**/*", base: path)
|
paths = Dir.glob("**/*", base: @path)
|
||||||
|
paths.reject do |filename|
|
||||||
|
File.directory?(File.join(@path, filename))
|
||||||
|
end.map do |filename|
|
||||||
|
filename.gsub(/\.[^\/]*\z/, "")
|
||||||
|
end.uniq
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -635,6 +635,12 @@ module RenderTestCases
|
||||||
e = assert_raises(ActionView::MissingTemplate) { @view.render(partial: "test/partail") }
|
e = assert_raises(ActionView::MissingTemplate) { @view.render(partial: "test/partail") }
|
||||||
assert_match %r{Did you mean\? test/_partial\n *test/_partialhtml}, e.message
|
assert_match %r{Did you mean\? test/_partial\n *test/_partialhtml}, e.message
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_spellcheck_doesnt_list_directories
|
||||||
|
e = assert_raises(ActionView::MissingTemplate) { @view.render(partial: "test/directory") }
|
||||||
|
assert_match %r{Did you mean\?}, e.message
|
||||||
|
assert_no_match %r{Did you mean\? test/_directory\n}, e.message # test/hello is a directory
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_render_partial_wrong_details_no_spellcheck
|
def test_render_partial_wrong_details_no_spellcheck
|
||||||
|
|
Loading…
Reference in a new issue