diff options
author | Christoph <christoph@mixxt.net> | 2015-11-05 11:20:00 +0100 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2015-11-11 07:08:20 +0100 |
commit | 9ccb341fbf1ae1bb46a0f638bf35a4bcffe06297 (patch) | |
tree | b44af5165fe4f6255e70abc1cc672adfdd1bc83f | |
parent | cff8b4951fd337075bd6079fa1a679428312baad (diff) | |
download | rails-9ccb341fbf1ae1bb46a0f638bf35a4bcffe06297.tar.gz rails-9ccb341fbf1ae1bb46a0f638bf35a4bcffe06297.tar.bz2 rails-9ccb341fbf1ae1bb46a0f638bf35a4bcffe06297.zip |
Fix week_field returning invalid value
According to the W3 spec[1] the value should use a 1-based index
and not a 0-based index for the week number.
[1]: http://www.w3.org/TR/html-markup/datatypes.html#form.data.week
-rw-r--r-- | actionview/CHANGELOG.md | 5 | ||||
-rw-r--r-- | actionview/lib/action_view/helpers/tags/week_field.rb | 2 | ||||
-rw-r--r-- | actionview/test/template/form_helper_test.rb | 14 |
3 files changed, 16 insertions, 5 deletions
diff --git a/actionview/CHANGELOG.md b/actionview/CHANGELOG.md index bb1103b173..023067632b 100644 --- a/actionview/CHANGELOG.md +++ b/actionview/CHANGELOG.md @@ -1,3 +1,8 @@ +* Generate `week_field` input values using a 1-based index and not a 0-based index + as per the W3 spec: http://www.w3.org/TR/html-markup/datatypes.html#form.data.week + + *Christoph Geschwind* + * Allow `host` option in `javascript_include_tag` and `stylesheet_link_tag` helpers *Grzegorz Witek* diff --git a/actionview/lib/action_view/helpers/tags/week_field.rb b/actionview/lib/action_view/helpers/tags/week_field.rb index 5b3d0494e9..835d1667d7 100644 --- a/actionview/lib/action_view/helpers/tags/week_field.rb +++ b/actionview/lib/action_view/helpers/tags/week_field.rb @@ -5,7 +5,7 @@ module ActionView private def format_date(value) - value.try(:strftime, "%Y-W%W") + value.try(:strftime, "%Y-W%V") end end end diff --git a/actionview/test/template/form_helper_test.rb b/actionview/test/template/form_helper_test.rb index e540bf27d9..1f7ff3ca7c 100644 --- a/actionview/test/template/form_helper_test.rb +++ b/actionview/test/template/form_helper_test.rb @@ -1281,7 +1281,7 @@ class FormHelperTest < ActionView::TestCase end def test_week_field - expected = %{<input id="post_written_on" name="post[written_on]" type="week" value="2004-W24" />} + expected = %{<input id="post_written_on" name="post[written_on]" type="week" value="2004-W25" />} assert_dom_equal(expected, week_field("post", "written_on")) end @@ -1292,13 +1292,13 @@ class FormHelperTest < ActionView::TestCase end def test_week_field_with_datetime_value - expected = %{<input id="post_written_on" name="post[written_on]" type="week" value="2004-W24" />} + expected = %{<input id="post_written_on" name="post[written_on]" type="week" value="2004-W25" />} @post.written_on = DateTime.new(2004, 6, 15, 1, 2, 3) assert_dom_equal(expected, week_field("post", "written_on")) end def test_week_field_with_extra_attrs - expected = %{<input id="post_written_on" step="2" max="2010-W51" min="2000-W06" name="post[written_on]" type="week" value="2004-W24" />} + expected = %{<input id="post_written_on" step="2" max="2010-W51" min="2000-W06" name="post[written_on]" type="week" value="2004-W25" />} @post.written_on = DateTime.new(2004, 6, 15, 1, 2, 3) min_value = DateTime.new(2000, 2, 13) max_value = DateTime.new(2010, 12, 23) @@ -1308,13 +1308,19 @@ class FormHelperTest < ActionView::TestCase def test_week_field_with_timewithzone_value previous_time_zone, Time.zone = Time.zone, 'UTC' - expected = %{<input id="post_written_on" name="post[written_on]" type="week" value="2004-W24" />} + expected = %{<input id="post_written_on" name="post[written_on]" type="week" value="2004-W25" />} @post.written_on = Time.zone.parse('2004-06-15 15:30:45') assert_dom_equal(expected, week_field("post", "written_on")) ensure Time.zone = previous_time_zone end + def test_week_field_week_number_base + expected = %{<input id="post_written_on" name="post[written_on]" type="week" value="2015-W01" />} + @post.written_on = DateTime.new(2015, 1, 1, 1, 2, 3) + assert_dom_equal(expected, week_field("post", "written_on")) + end + def test_url_field expected = %{<input id="user_homepage" name="user[homepage]" type="url" />} assert_dom_equal(expected, url_field("user", "homepage")) |