aboutsummaryrefslogtreecommitdiffstats
path: root/actionview
diff options
context:
space:
mode:
authorChristoph <christoph@mixxt.net>2015-11-05 11:20:00 +0100
committerAndrew White <andrew.white@unboxedconsulting.com>2015-11-10 12:28:47 +0000
commit60dabb156f2aa2c22bb2862145f80c64ba12cea5 (patch)
treec47d5e6786951a542ce78158ce43c69260cd961b /actionview
parent8d7f0a66c623aa294039032e9e928e88cf3db956 (diff)
downloadrails-60dabb156f2aa2c22bb2862145f80c64ba12cea5.tar.gz
rails-60dabb156f2aa2c22bb2862145f80c64ba12cea5.tar.bz2
rails-60dabb156f2aa2c22bb2862145f80c64ba12cea5.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
Diffstat (limited to 'actionview')
-rw-r--r--actionview/CHANGELOG.md5
-rw-r--r--actionview/lib/action_view/helpers/tags/week_field.rb2
-rw-r--r--actionview/test/template/form_helper_test.rb14
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"))