2017-07-23 11:36:41 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-06 12:50:17 -04:00
|
|
|
require "abstract_unit"
|
2011-03-19 00:13:59 -04:00
|
|
|
|
|
|
|
class ResolverPatternsTest < ActiveSupport::TestCase
|
|
|
|
def setup
|
2017-05-15 10:17:28 -04:00
|
|
|
path = File.expand_path("../fixtures", __dir__)
|
2016-03-01 03:58:40 -05:00
|
|
|
pattern = ":prefix/{:formats/,}:action{.:formats,}{+:variants,}{.:handlers,}"
|
2011-03-19 00:13:59 -04:00
|
|
|
@resolver = ActionView::FileSystemResolver.new(path, pattern)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_should_return_empty_list_for_unknown_path
|
2016-08-06 13:44:11 -04:00
|
|
|
templates = @resolver.find_all("unknown", "custom_pattern", false, locale: [], formats: [:html], variants: [], handlers: [:erb])
|
2011-03-19 00:13:59 -04:00
|
|
|
assert_equal [], templates, "expected an empty list of templates"
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_should_return_template_for_declared_path
|
2016-08-06 13:44:11 -04:00
|
|
|
templates = @resolver.find_all("path", "custom_pattern", false, locale: [], formats: [:html], variants: [], handlers: [:erb])
|
2011-03-19 00:13:59 -04:00
|
|
|
assert_equal 1, templates.size, "expected one template"
|
|
|
|
assert_equal "Hello custom patterns!", templates.first.source
|
|
|
|
assert_equal "custom_pattern/path", templates.first.virtual_path
|
|
|
|
assert_equal [:html], templates.first.formats
|
|
|
|
end
|
|
|
|
|
2013-09-05 01:13:57 -04:00
|
|
|
def test_should_return_all_templates_when_ambiguous_pattern
|
2016-08-06 13:44:11 -04:00
|
|
|
templates = @resolver.find_all("another", "custom_pattern", false, locale: [], formats: [:html], variants: [], handlers: [:erb])
|
2011-03-19 00:13:59 -04:00
|
|
|
assert_equal 2, templates.size, "expected two templates"
|
|
|
|
assert_equal "Another template!", templates[0].source
|
|
|
|
assert_equal "custom_pattern/another", templates[0].virtual_path
|
|
|
|
assert_equal "Hello custom patterns!", templates[1].source
|
|
|
|
assert_equal "custom_pattern/another", templates[1].virtual_path
|
|
|
|
end
|
2016-03-01 03:58:40 -05:00
|
|
|
|
|
|
|
def test_should_return_all_variants_for_any
|
2016-08-06 13:44:11 -04:00
|
|
|
templates = @resolver.find_all("hello_world", "test", false, locale: [], formats: [:html, :text], variants: :any, handlers: [:erb])
|
2016-03-01 03:58:40 -05:00
|
|
|
assert_equal 3, templates.size, "expected three templates"
|
|
|
|
assert_equal "Hello phone!", templates[0].source
|
|
|
|
assert_equal "test/hello_world", templates[0].virtual_path
|
|
|
|
assert_equal "Hello texty phone!", templates[1].source
|
|
|
|
assert_equal "test/hello_world", templates[1].virtual_path
|
|
|
|
assert_equal "Hello world!", templates[2].source
|
|
|
|
assert_equal "test/hello_world", templates[2].virtual_path
|
|
|
|
end
|
2011-03-19 00:13:59 -04:00
|
|
|
end
|