Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
6e9af5c7
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,发现更多精彩内容 >>
提交
6e9af5c7
编写于
4月 10, 2014
作者:
R
Rafael Mendonça França
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #11656 from emre-basala/xml_mini_test
Add tests to ActiveSupport:XmlMini to_tag method
上级
85b48d2b
05d7cdec
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
58 addition
and
1 deletion
+58
-1
activesupport/test/xml_mini_test.rb
activesupport/test/xml_mini_test.rb
+58
-1
未找到文件。
activesupport/test/xml_mini_test.rb
浏览文件 @
6e9af5c7
require
'abstract_unit'
require
'abstract_unit'
require
'active_support/xml_mini'
require
'active_support/xml_mini'
require
'active_support/builder'
require
'active_support/builder'
require
'active_support/core_ext/array'
require
'active_support/core_ext/hash'
require
'active_support/core_ext/big_decimal'
module
XmlMiniTest
module
XmlMiniTest
class
RenameKeyTest
<
ActiveSupport
::
TestCase
class
RenameKeyTest
<
ActiveSupport
::
TestCase
...
@@ -88,6 +91,61 @@ def to_xml(options) options[:builder].yo(options[:root].to_s) end
...
@@ -88,6 +91,61 @@ def to_xml(options) options[:builder].yo(options[:root].to_s) end
assert_xml
"<b>Howdy</b>"
assert_xml
"<b>Howdy</b>"
end
end
test
"#to_tag should use the type value in the options hash"
do
@xml
.
to_tag
(
:b
,
"blue"
,
@options
.
merge
(
type:
'color'
))
assert_xml
(
"<b type=
\"
color
\"
>blue</b>"
)
end
test
"#to_tag accepts symbol types"
do
@xml
.
to_tag
(
:b
,
:name
,
@options
)
assert_xml
(
"<b type=
\"
symbol
\"
>name</b>"
)
end
test
"#to_tag accepts boolean types"
do
@xml
.
to_tag
(
:b
,
true
,
@options
)
assert_xml
(
"<b type=
\"
boolean
\"
>true</b>"
)
end
test
"#to_tag accepts float types"
do
@xml
.
to_tag
(
:b
,
3.14
,
@options
)
assert_xml
(
"<b type=
\"
float
\"
>3.14</b>"
)
end
test
"#to_tag accepts decimal types"
do
@xml
.
to_tag
(
:b
,
::
BigDecimal
.
new
(
"1.2"
),
@options
)
assert_xml
(
"<b type=
\"
decimal
\"
>1.2</b>"
)
end
test
"#to_tag accepts date types"
do
@xml
.
to_tag
(
:b
,
Date
.
new
(
2001
,
2
,
3
),
@options
)
assert_xml
(
"<b type=
\"
date
\"
>2001-02-03</b>"
)
end
test
"#to_tag accepts datetime types"
do
@xml
.
to_tag
(
:b
,
DateTime
.
new
(
2001
,
2
,
3
,
4
,
5
,
6
,
'+7'
),
@options
)
assert_xml
(
"<b type=
\"
dateTime
\"
>2001-02-03T04:05:06+07:00</b>"
)
end
test
"#to_tag accepts time types"
do
@xml
.
to_tag
(
:b
,
Time
.
new
(
1993
,
02
,
24
,
12
,
0
,
0
,
"+09:00"
),
@options
)
assert_xml
(
"<b type=
\"
dateTime
\"
>1993-02-24T12:00:00+09:00</b>"
)
end
test
"#to_tag accepts array types"
do
@xml
.
to_tag
(
:b
,
[
"first_name"
,
"last_name"
],
@options
)
assert_xml
(
"<b type=
\"
array
\"
><b>first_name</b><b>last_name</b></b>"
)
end
test
"#to_tag accepts hash types"
do
@xml
.
to_tag
(
:b
,
{
first_name:
"Bob"
,
last_name:
"Marley"
},
@options
)
assert_xml
(
"<b><first-name>Bob</first-name><last-name>Marley</last-name></b>"
)
end
test
"#to_tag should not add type when skip types option is set"
do
@xml
.
to_tag
(
:b
,
"Bob"
,
@options
.
merge
(
skip_types:
1
))
assert_xml
(
"<b>Bob</b>"
)
end
test
"#to_tag should dasherize the space when passed a string with spaces as a key"
do
test
"#to_tag should dasherize the space when passed a string with spaces as a key"
do
@xml
.
to_tag
(
"New York"
,
33
,
@options
)
@xml
.
to_tag
(
"New York"
,
33
,
@options
)
assert_xml
"<New---York type=
\"
integer
\"
>33</New---York>"
assert_xml
"<New---York type=
\"
integer
\"
>33</New---York>"
...
@@ -97,7 +155,6 @@ def to_xml(options) options[:builder].yo(options[:root].to_s) end
...
@@ -97,7 +155,6 @@ def to_xml(options) options[:builder].yo(options[:root].to_s) end
@xml
.
to_tag
(
:"New York"
,
33
,
@options
)
@xml
.
to_tag
(
:"New York"
,
33
,
@options
)
assert_xml
"<New---York type=
\"
integer
\"
>33</New---York>"
assert_xml
"<New---York type=
\"
integer
\"
>33</New---York>"
end
end
# TODO: test the remaining functions hidden in #to_tag.
end
end
class
WithBackendTest
<
ActiveSupport
::
TestCase
class
WithBackendTest
<
ActiveSupport
::
TestCase
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录