aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/test/template/resolver_patterns_test.rb
diff options
context:
space:
mode:
authorGodfrey Chan <godfreykfc@gmail.com>2016-03-01 00:58:40 -0800
committerGodfrey Chan <godfreykfc@gmail.com>2016-03-01 01:04:26 -0800
commitd150f59f114dc2d362b9d8f96df88ca4fea09dc4 (patch)
tree7c5cc94d9f599dfc3a692f060dabfb024028300d /actionview/test/template/resolver_patterns_test.rb
parent75097933e26e5147f666f485d41b38967c76311c (diff)
downloadrails-d150f59f114dc2d362b9d8f96df88ca4fea09dc4.tar.gz
rails-d150f59f114dc2d362b9d8f96df88ca4fea09dc4.tar.bz2
rails-d150f59f114dc2d362b9d8f96df88ca4fea09dc4.zip
Support `:any` variants lookup in `PathResolver`
`OptimizedFileSystemResolver` (which most Rails apps use), but did not implement the feature on the more generic `PathResolver`, which is often used in tests etc. Fixes #23881
Diffstat (limited to 'actionview/test/template/resolver_patterns_test.rb')
-rw-r--r--actionview/test/template/resolver_patterns_test.rb19
1 files changed, 15 insertions, 4 deletions
diff --git a/actionview/test/template/resolver_patterns_test.rb b/actionview/test/template/resolver_patterns_test.rb
index 575eb9bd28..1a091bd692 100644
--- a/actionview/test/template/resolver_patterns_test.rb
+++ b/actionview/test/template/resolver_patterns_test.rb
@@ -3,17 +3,17 @@ require 'abstract_unit'
class ResolverPatternsTest < ActiveSupport::TestCase
def setup
path = File.expand_path("../../fixtures/", __FILE__)
- pattern = ":prefix/{:formats/,}:action{.:formats,}{.:handlers,}"
+ pattern = ":prefix/{:formats/,}:action{.:formats,}{+:variants,}{.:handlers,}"
@resolver = ActionView::FileSystemResolver.new(path, pattern)
end
def test_should_return_empty_list_for_unknown_path
- templates = @resolver.find_all("unknown", "custom_pattern", false, {:locale => [], :formats => [:html], :handlers => [:erb]})
+ templates = @resolver.find_all("unknown", "custom_pattern", false, {locale: [], formats: [:html], variants: [], handlers: [:erb]})
assert_equal [], templates, "expected an empty list of templates"
end
def test_should_return_template_for_declared_path
- templates = @resolver.find_all("path", "custom_pattern", false, {:locale => [], :formats => [:html], :handlers => [:erb]})
+ templates = @resolver.find_all("path", "custom_pattern", false, {locale: [], formats: [:html], variants: [], handlers: [:erb]})
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
@@ -21,11 +21,22 @@ class ResolverPatternsTest < ActiveSupport::TestCase
end
def test_should_return_all_templates_when_ambiguous_pattern
- templates = @resolver.find_all("another", "custom_pattern", false, {:locale => [], :formats => [:html], :handlers => [:erb]})
+ templates = @resolver.find_all("another", "custom_pattern", false, {locale: [], formats: [:html], variants: [], handlers: [:erb]})
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
+
+ def test_should_return_all_variants_for_any
+ templates = @resolver.find_all("hello_world", "test", false, {locale: [], formats: [:html, :text], variants: :any, handlers: [:erb]})
+ 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
end