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
|
||||
path = @error.path
|
||||
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
|
||||
files_by_dir = candidates.group_by do |x|
|
||||
File.dirname(x)
|
||||
end.transform_values do |files|
|
||||
files.map do |file|
|
||||
# Remove template extensions
|
||||
File.basename(file).split(".", 2)[0]
|
||||
end.uniq
|
||||
# Remove directory
|
||||
File.basename(file)
|
||||
end
|
||||
end
|
||||
|
||||
# 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)) }
|
||||
end
|
||||
|
||||
def template_paths_for_suggestions # :nodoc:
|
||||
def all_template_paths # :nodoc:
|
||||
# Not implemented by default
|
||||
[]
|
||||
end
|
||||
|
@ -343,8 +343,13 @@ module ActionView
|
|||
end
|
||||
alias :== :eql?
|
||||
|
||||
def template_paths_for_suggestions # :nodoc:
|
||||
Dir.glob("**/*", base: path)
|
||||
def all_template_paths # :nodoc:
|
||||
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
|
||||
|
||||
|
|
|
@ -635,6 +635,12 @@ module RenderTestCases
|
|||
e = assert_raises(ActionView::MissingTemplate) { @view.render(partial: "test/partail") }
|
||||
assert_match %r{Did you mean\? test/_partial\n *test/_partialhtml}, e.message
|
||||
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
|
||||
|
||||
def test_render_partial_wrong_details_no_spellcheck
|
||||
|
|
Loading…
Reference in a new issue