diff --git a/actionview/lib/action_view/template/resolver.rb b/actionview/lib/action_view/template/resolver.rb index 2a5aaba883..cc3d8bb072 100644 --- a/actionview/lib/action_view/template/resolver.rb +++ b/actionview/lib/action_view/template/resolver.rb @@ -204,9 +204,13 @@ module ActionView end end + def source_for_template(template) + Template::Sources::File.new(template) + end + def build_unbound_template(template, virtual_path) handler, format, variant = extract_handler_and_format_and_variant(template) - source = Template::Sources::File.new(template) + source = source_for_template(template) UnboundTemplate.new( source, @@ -316,14 +320,22 @@ module ActionView end private - def find_template_paths_from_details(path, details) + def find_candidate_template_paths(path) # Instead of checking for every possible path, as our other globs would # do, scan the directory for files with the right prefix. query = "#{escape_entry(File.join(@path, path))}*" + Dir[query].reject do |filename| + File.directory?(filename) + end + end + + def find_template_paths_from_details(path, details) + candidates = find_candidate_template_paths(path) + regex = build_regex(path, details) - Dir[query].uniq.reject do |filename| + candidates.uniq.reject do |filename| # This regex match does double duty of finding only files which match # details (instead of just matching the prefix) and also filtering for # case-insensitive file systems. diff --git a/actionview/lib/action_view/testing/resolvers.rb b/actionview/lib/action_view/testing/resolvers.rb index 03eac29bb4..df73d34d77 100644 --- a/actionview/lib/action_view/testing/resolvers.rb +++ b/actionview/lib/action_view/testing/resolvers.rb @@ -27,34 +27,17 @@ module ActionView #:nodoc: end private - def query(path, exts, _, locals, cache:) - regex = build_regex(path, exts) - - @hash.select do |_path, _| - ("/" + _path).match?(regex) - end.map do |_path, source| - handler, format, variant = extract_handler_and_format_and_variant(_path) - - Template.new(source, _path, handler, - virtual_path: path.virtual, - format: format, - variant: variant, - locals: locals - ) - end.sort_by do |t| - match = ("/" + t.identifier).match(regex) - EXTENSIONS.keys.reverse.map do |ext| - if ext == :variants && exts[ext] == :any - match[ext].nil? ? 0 : 1 - elsif match[ext].nil? - exts[ext].length - else - found = match[ext].to_sym - exts[ext].index(found) - end - end + def find_candidate_template_paths(path) + @hash.keys.select do |fixture| + fixture.start_with?(path.virtual) + end.map do |fixture| + "/#{fixture}" end end + + def source_for_template(template) + @hash[template[1..template.size]] + end end class NullResolver < PathResolver