Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
acdbc6ae
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,发现更多精彩内容 >>
提交
acdbc6ae
编写于
4月 05, 2011
作者:
X
Xavier Noria
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
renames response_from_page_or_rjs -> response_from_page, and extracts the RJS in it
上级
86d6cdd7
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
6 addition
and
59 deletion
+6
-59
actionpack/lib/action_dispatch/testing/assertions/selector.rb
...onpack/lib/action_dispatch/testing/assertions/selector.rb
+5
-58
actionpack/lib/action_view/test_case.rb
actionpack/lib/action_view/test_case.rb
+1
-1
未找到文件。
actionpack/lib/action_dispatch/testing/assertions/selector.rb
浏览文件 @
acdbc6ae
...
...
@@ -80,7 +80,7 @@ def css_select(*args)
return
matches
else
root
=
response_from_page
_or_rjs
root
=
response_from_page
end
case
arg
...
...
@@ -204,7 +204,7 @@ def assert_select(*args, &block)
root
.
children
.
concat
@selected
else
# Otherwise just operate on the response document.
root
=
response_from_page
_or_rjs
root
=
response_from_page
end
# First or second argument is the selector: string and we pass
...
...
@@ -425,62 +425,9 @@ def assert_select_email(&block)
end
protected
RJS_PATTERN_HTML
=
"
\"
((
\\\\\"
|[^
\"
])*)
\"
"
RJS_ANY_ID
=
"
\"
([^
\"
])*
\"
"
RJS_STATEMENTS
=
{
:chained_replace
=>
"
\\
$
\\
(
#{
RJS_ANY_ID
}
\\
)
\\
.replace
\\
(
#{
RJS_PATTERN_HTML
}
\\
)"
,
:chained_replace_html
=>
"
\\
$
\\
(
#{
RJS_ANY_ID
}
\\
)
\\
.update
\\
(
#{
RJS_PATTERN_HTML
}
\\
)"
,
:replace_html
=>
"Element
\\
.update
\\
(
#{
RJS_ANY_ID
}
,
#{
RJS_PATTERN_HTML
}
\\
)"
,
:replace
=>
"Element
\\
.replace
\\
(
#{
RJS_ANY_ID
}
,
#{
RJS_PATTERN_HTML
}
\\
)"
,
:redirect
=>
"window.location.href =
#{
RJS_ANY_ID
}
"
}
[
:remove
,
:show
,
:hide
,
:toggle
].
each
do
|
action
|
RJS_STATEMENTS
[
action
]
=
"Element
\\
.
#{
action
}
\\
(
#{
RJS_ANY_ID
}
\\
)"
end
RJS_INSERTIONS
=
[
"top"
,
"bottom"
,
"before"
,
"after"
]
RJS_INSERTIONS
.
each
do
|
insertion
|
RJS_STATEMENTS
[
"insert_
#{
insertion
}
"
.
to_sym
]
=
"Element.insert
\\
(
#{
RJS_ANY_ID
}
,
\\
{
#{
insertion
}
:
#{
RJS_PATTERN_HTML
}
\\
}
\\
)"
end
RJS_STATEMENTS
[
:insert_html
]
=
"Element.insert
\\
(
#{
RJS_ANY_ID
}
,
\\
{ (
#{
RJS_INSERTIONS
.
join
(
'|'
)
}
):
#{
RJS_PATTERN_HTML
}
\\
}
\\
)"
RJS_STATEMENTS
[
:any
]
=
Regexp
.
new
(
"(
#{
RJS_STATEMENTS
.
values
.
join
(
'|'
)
}
)"
)
RJS_PATTERN_UNICODE_ESCAPED_CHAR
=
/\\u([0-9a-zA-Z]{4})/
# +assert_select+ and +css_select+ call this to obtain the content in the HTML
# page, or from all the RJS statements, depending on the type of response.
def
response_from_page_or_rjs
()
content_type
=
@response
.
content_type
if
content_type
&&
Mime
::
JS
=~
content_type
body
=
@response
.
body
.
dup
root
=
HTML
::
Node
.
new
(
nil
)
while
true
next
if
body
.
sub!
(
RJS_STATEMENTS
[
:any
])
do
|
match
|
html
=
unescape_rjs
(
match
)
matches
=
HTML
::
Document
.
new
(
html
).
root
.
children
.
select
{
|
n
|
n
.
tag?
}
root
.
children
.
concat
matches
""
end
break
end
root
else
html_document
.
root
end
end
# Unescapes a RJS string.
def
unescape_rjs
(
rjs_string
)
# RJS encodes double quotes and line breaks.
unescaped
=
rjs_string
.
gsub
(
'\"'
,
'"'
)
unescaped
.
gsub!
(
/\\\//
,
'/'
)
unescaped
.
gsub!
(
'\n'
,
"
\n
"
)
unescaped
.
gsub!
(
'\076'
,
'>'
)
unescaped
.
gsub!
(
'\074'
,
'<'
)
# RJS encodes non-ascii characters.
unescaped
.
gsub!
(
RJS_PATTERN_UNICODE_ESCAPED_CHAR
)
{
|
u
|
[
$1
.
hex
].
pack
(
'U*'
)}
unescaped
# +assert_select+ and +css_select+ call this to obtain the content in the HTML page.
def
response_from_page
html_document
.
root
end
end
end
...
...
actionpack/lib/action_view/test_case.rb
浏览文件 @
acdbc6ae
...
...
@@ -121,7 +121,7 @@ def locals
# Support the selector assertions
#
# Need to experiment if this priority is the best one: rendered => output_buffer
def
response_from_page
_or_rjs
def
response_from_page
HTML
::
Document
.
new
(
@rendered
.
blank?
?
@output_buffer
:
@rendered
).
root
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录