Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
ddd5ceab
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
ddd5ceab
编写于
7月 25, 2019
作者:
R
Rafael Mendonça França
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Merge pull request #36576 from mtsmfm/mtsmfm/fix-fixture-resolver
Support :any variants for ActionView::FixtureResolver
上级
c9863690
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
47 addition
and
13 deletion
+47
-13
actionview/lib/action_view/testing/resolvers.rb
actionview/lib/action_view/testing/resolvers.rb
+25
-13
actionview/test/template/testing/fixture_resolver_test.rb
actionview/test/template/testing/fixture_resolver_test.rb
+22
-0
未找到文件。
actionview/lib/action_view/testing/resolvers.rb
浏览文件 @
ddd5ceab
...
...
@@ -7,10 +7,15 @@ module ActionView #:nodoc:
# file system. This is used internally by Rails' own test suite, and is
# useful for testing extensions that have no way of knowing what the file
# system will look like at runtime.
class
FixtureResolver
<
Path
Resolver
class
FixtureResolver
<
OptimizedFileSystem
Resolver
def
initialize
(
hash
=
{},
pattern
=
nil
)
super
(
pattern
)
super
(
""
)
if
pattern
ActiveSupport
::
Deprecation
.
warn
"Specifying a custom path for
#{
self
.
class
}
is deprecated. Implement a custom Resolver subclass instead."
@pattern
=
pattern
end
@hash
=
hash
@path
=
""
end
def
data
...
...
@@ -24,25 +29,32 @@ def to_s
private
def
query
(
path
,
exts
,
_
,
locals
,
cache
:)
query
=
+
""
EXTENSIONS
.
each
do
|
ext
,
prefix
|
query
<<
"("
<<
exts
[
ext
].
map
{
|
e
|
e
&&
Regexp
.
escape
(
"
#{
prefix
}#{
e
}
"
)
}.
join
(
"|"
)
<<
"|)"
end
query
=
/^(
#{
Regexp
.
escape
(
path
)
}
)
#{
query
}
$/
regex
=
build_regex
(
path
,
exts
)
templates
=
[]
@hash
.
each
do
|
_path
,
source
|
next
unless
query
.
match?
(
_path
)
@hash
.
select
do
|
_path
,
_
|
(
"/"
+
_path
).
match?
(
regex
)
end
.
map
do
|
_path
,
source
|
handler
,
format
,
variant
=
extract_handler_and_format_and_variant
(
_path
)
templates
<<
Template
.
new
(
source
,
_path
,
handler
,
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
end
templates
.
sort_by
{
|
t
|
-
t
.
identifier
.
match
(
/^
#{
query
}
$/
).
captures
.
reject
(
&
:blank?
).
size
}
end
end
...
...
actionview/test/template/testing/fixture_resolver_test.rb
浏览文件 @
ddd5ceab
...
...
@@ -27,4 +27,26 @@ def test_should_match_templates_with_variants
assert_equal
:html
,
templates
.
first
.
format
assert_equal
"variant"
,
templates
.
first
.
variant
end
def
test_should_match_locales
resolver
=
ActionView
::
FixtureResolver
.
new
(
"arbitrary/path.erb"
=>
"this text"
,
"arbitrary/path.fr.erb"
=>
"ce texte"
)
en
=
resolver
.
find_all
(
"path"
,
"arbitrary"
,
false
,
locale:
[
:en
],
formats:
[
:html
],
variants:
[],
handlers:
[
:erb
])
fr
=
resolver
.
find_all
(
"path"
,
"arbitrary"
,
false
,
locale:
[
:fr
],
formats:
[
:html
],
variants:
[],
handlers:
[
:erb
])
assert_equal
1
,
en
.
size
assert_equal
2
,
fr
.
size
assert_equal
"this text"
,
en
[
0
].
source
assert_equal
"ce texte"
,
fr
[
0
].
source
assert_equal
"this text"
,
fr
[
1
].
source
end
def
test_should_return_all_variants_for_any
resolver
=
ActionView
::
FixtureResolver
.
new
(
"arbitrary/path.html.erb"
=>
"this html"
,
"arbitrary/path.html+varient.erb"
=>
"this text"
)
templates
=
resolver
.
find_all
(
"path"
,
"arbitrary"
,
false
,
locale:
[],
formats:
[
:html
],
variants:
[],
handlers:
[
:erb
])
assert_equal
1
,
templates
.
size
,
"expected one template"
assert_equal
"this html"
,
templates
.
first
.
source
templates
=
resolver
.
find_all
(
"path"
,
"arbitrary"
,
false
,
locale:
[],
formats:
[
:html
],
variants: :any
,
handlers:
[
:erb
])
assert_equal
2
,
templates
.
size
,
"expected all templates"
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录