Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
09d884cd
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,发现更多精彩内容 >>
提交
09d884cd
编写于
3月 19, 2012
作者:
A
Andrew White
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #5503 from jeyb/leap_day_time_date_time_selector
Fixes issue #5222: DateTimeSelector builds invalid dates on leap days
上级
9c748f39
d2d2fc08
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
27 addition
and
13 deletion
+27
-13
actionpack/lib/action_view/helpers/date_helper.rb
actionpack/lib/action_view/helpers/date_helper.rb
+6
-6
actionpack/test/template/active_model_helper_test.rb
actionpack/test/template/active_model_helper_test.rb
+2
-2
actionpack/test/template/date_helper_test.rb
actionpack/test/template/date_helper_test.rb
+19
-5
未找到文件。
actionpack/lib/action_view/helpers/date_helper.rb
浏览文件 @
09d884cd
...
...
@@ -674,9 +674,9 @@ def select_datetime
@options
[
:discard_minute
]
||=
true
if
@options
[
:discard_hour
]
@options
[
:discard_second
]
||=
true
unless
@options
[
:include_seconds
]
&&
!
@options
[
:discard_minute
]
# If the day is hidden
and the month is visible, the day should be set to the 1st so all month choices are
#
valid (otherwise it could be 31 and February wouldn't be a valid date)
if
@datetime
&&
@options
[
:discard_day
]
&&
!
@options
[
:discard_month
]
# If the day is hidden
, the day should be set to the 1st so all month and year choices are valid. Otherwise,
#
February 31st or February 29th, 2011 can be selected, which are invalid.
if
@datetime
&&
@options
[
:discard_day
]
@datetime
=
@datetime
.
change
(
:day
=>
1
)
end
...
...
@@ -701,9 +701,9 @@ def select_date
@options
[
:discard_month
]
||=
true
unless
order
.
include?
(
:month
)
@options
[
:discard_day
]
||=
true
if
@options
[
:discard_month
]
||
!
order
.
include?
(
:day
)
# If the day is hidden
and the month is visible, the day should be set to the 1st so all month choices are
#
valid (otherwise it could be 31 and February wouldn't be a valid date)
if
@datetime
&&
@options
[
:discard_day
]
&&
!
@options
[
:discard_month
]
# If the day is hidden
, the day should be set to the 1st so all month and year choices are valid. Otherwise,
#
February 31st or February 29th, 2011 can be selected, which are invalid.
if
@datetime
&&
@options
[
:discard_day
]
@datetime
=
@datetime
.
change
(
:day
=>
1
)
end
...
...
actionpack/test/template/active_model_helper_test.rb
浏览文件 @
09d884cd
...
...
@@ -43,14 +43,14 @@ def test_text_field_with_errors
def
test_date_select_with_errors
assert_dom_equal
(
%(<div class="field_with_errors"><select id="post_updated_at_1i" name="post[updated_at(1i)]">\n<option selected="selected" value="2004">2004</option>\n<option value="2005">2005</option>\n</select>\n<input id="post_updated_at_2i" name="post[updated_at(2i)]" type="hidden" value="6" />\n<input id="post_updated_at_3i" name="post[updated_at(3i)]" type="hidden" value="1
5
" />\n</div>)
,
%(<div class="field_with_errors"><select id="post_updated_at_1i" name="post[updated_at(1i)]">\n<option selected="selected" value="2004">2004</option>\n<option value="2005">2005</option>\n</select>\n<input id="post_updated_at_2i" name="post[updated_at(2i)]" type="hidden" value="6" />\n<input id="post_updated_at_3i" name="post[updated_at(3i)]" type="hidden" value="1" />\n</div>)
,
date_select
(
"post"
,
"updated_at"
,
:discard_month
=>
true
,
:discard_day
=>
true
,
:start_year
=>
2004
,
:end_year
=>
2005
)
)
end
def
test_datetime_select_with_errors
assert_dom_equal
(
%(<div class="field_with_errors"><input id="post_updated_at_1i" name="post[updated_at(1i)]" type="hidden" value="2004" />\n<input id="post_updated_at_2i" name="post[updated_at(2i)]" type="hidden" value="6" />\n<input id="post_updated_at_3i" name="post[updated_at(3i)]" type="hidden" value="1
5
" />\n<select id="post_updated_at_4i" name="post[updated_at(4i)]">\n<option selected="selected" value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n</select>\n : <select id="post_updated_at_5i" name="post[updated_at(5i)]">\n<option selected="selected" value="00">00</option>\n</select>\n</div>)
,
%(<div class="field_with_errors"><input id="post_updated_at_1i" name="post[updated_at(1i)]" type="hidden" value="2004" />\n<input id="post_updated_at_2i" name="post[updated_at(2i)]" type="hidden" value="6" />\n<input id="post_updated_at_3i" name="post[updated_at(3i)]" type="hidden" value="1" />\n<select id="post_updated_at_4i" name="post[updated_at(4i)]">\n<option selected="selected" value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n</select>\n : <select id="post_updated_at_5i" name="post[updated_at(5i)]">\n<option selected="selected" value="00">00</option>\n</select>\n</div>)
,
datetime_select
(
"post"
,
"updated_at"
,
:discard_year
=>
true
,
:discard_month
=>
true
,
:discard_day
=>
true
,
:minute_step
=>
60
)
)
end
...
...
actionpack/test/template/date_helper_test.rb
浏览文件 @
09d884cd
...
...
@@ -711,7 +711,7 @@ def test_select_date_with_incomplete_order
# Since the order is incomplete nothing will be shown
expected
=
%(<input id="date_first_year" name="date[first][year]" type="hidden" value="2003" />\n)
expected
<<
%(<input id="date_first_month" name="date[first][month]" type="hidden" value="8" />\n)
expected
<<
%(<input id="date_first_day" name="date[first][day]" type="hidden" value="1
6
" />\n)
expected
<<
%(<input id="date_first_day" name="date[first][day]" type="hidden" value="1" />\n)
assert_dom_equal
expected
,
select_date
(
Time
.
mktime
(
2003
,
8
,
16
),
:start_year
=>
2003
,
:end_year
=>
2005
,
:prefix
=>
"date[first]"
,
:order
=>
[
:day
])
end
...
...
@@ -943,7 +943,7 @@ def test_select_date_with_separator_discard_month_and_day
expected
<<
"</select>
\n
"
expected
<<
%(<input type="hidden" id="date_first_month" name="date[first][month]" value="8" />\n)
expected
<<
%(<input type="hidden" id="date_first_day" name="date[first][day]" value="1
6
" />\n)
expected
<<
%(<input type="hidden" id="date_first_day" name="date[first][day]" value="1" />\n)
assert_dom_equal
expected
,
select_date
(
Time
.
mktime
(
2003
,
8
,
16
),
{
:date_separator
=>
" / "
,
:discard_month
=>
true
,
:discard_day
=>
true
,
:start_year
=>
2003
,
:end_year
=>
2005
,
:prefix
=>
"date[first]"
})
end
...
...
@@ -1396,6 +1396,20 @@ def test_date_select_without_day
assert_dom_equal
expected
,
date_select
(
"post"
,
"written_on"
,
:order
=>
[
:month
,
:year
])
end
def
test_date_select_without_day_and_month
@post
=
Post
.
new
@post
.
written_on
=
Date
.
new
(
2004
,
2
,
29
)
expected
=
"<input type=
\"
hidden
\"
id=
\"
post_written_on_2i
\"
name=
\"
post[written_on(2i)]
\"
value=
\"
2
\"
/>
\n
"
expected
<<
"<input type=
\"
hidden
\"
id=
\"
post_written_on_3i
\"
name=
\"
post[written_on(3i)]
\"
value=
\"
1
\"
/>
\n
"
expected
<<
%{<select id="post_written_on_1i" name="post[written_on(1i)]">\n}
expected
<<
%{<option value="1999">1999</option>\n<option value="2000">2000</option>\n<option value="2001">2001</option>\n<option value="2002">2002</option>\n<option value="2003">2003</option>\n<option value="2004" selected="selected">2004</option>\n<option value="2005">2005</option>\n<option value="2006">2006</option>\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n}
expected
<<
"</select>
\n
"
assert_dom_equal
expected
,
date_select
(
"post"
,
"written_on"
,
:order
=>
[
:year
])
end
def
test_date_select_without_day_with_separator
@post
=
Post
.
new
@post
.
written_on
=
Date
.
new
(
2004
,
6
,
15
)
...
...
@@ -2427,7 +2441,7 @@ def test_datetime_select_discard_month
1999
.
upto
(
2009
)
{
|
i
|
expected
<<
%(<option value="#{i}"#{' selected="selected"' if i == 2004}>#{i}</option>\n)
}
expected
<<
"</select>
\n
"
expected
<<
%{<input type="hidden" id="post_updated_at_2i" name="post[updated_at(2i)]" value="6" />\n}
expected
<<
%{<input type="hidden" id="post_updated_at_3i" name="post[updated_at(3i)]" value="1
5
" />\n}
expected
<<
%{<input type="hidden" id="post_updated_at_3i" name="post[updated_at(3i)]" value="1" />\n}
expected
<<
" — "
...
...
@@ -2448,7 +2462,7 @@ def test_datetime_select_discard_year_and_month
expected
=
%{<input type="hidden" id="post_updated_at_1i" name="post[updated_at(1i)]" value="2004" />\n}
expected
<<
%{<input type="hidden" id="post_updated_at_2i" name="post[updated_at(2i)]" value="6" />\n}
expected
<<
%{<input type="hidden" id="post_updated_at_3i" name="post[updated_at(3i)]" value="1
5
" />\n}
expected
<<
%{<input type="hidden" id="post_updated_at_3i" name="post[updated_at(3i)]" value="1" />\n}
expected
<<
%{<select id="post_updated_at_4i" name="post[updated_at(4i)]">\n}
0
.
upto
(
23
)
{
|
i
|
expected
<<
%(<option value="#{sprintf("%02d", i)}"#{' selected="selected"' if i == 15}>#{sprintf("%02d", i)}</option>\n)
}
...
...
@@ -2467,7 +2481,7 @@ def test_datetime_select_discard_year_and_month_with_disabled_html_option
expected
=
%{<input type="hidden" id="post_updated_at_1i" disabled="disabled" name="post[updated_at(1i)]" value="2004" />\n}
expected
<<
%{<input type="hidden" id="post_updated_at_2i" disabled="disabled" name="post[updated_at(2i)]" value="6" />\n}
expected
<<
%{<input type="hidden" id="post_updated_at_3i" disabled="disabled" name="post[updated_at(3i)]" value="1
5
" />\n}
expected
<<
%{<input type="hidden" id="post_updated_at_3i" disabled="disabled" name="post[updated_at(3i)]" value="1" />\n}
expected
<<
%{<select id="post_updated_at_4i" disabled="disabled" name="post[updated_at(4i)]">\n}
0
.
upto
(
23
)
{
|
i
|
expected
<<
%(<option value="#{sprintf("%02d", i)}"#{' selected="selected"' if i == 15}>#{sprintf("%02d", i)}</option>\n)
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录