Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #11178 from JonRowe/fix_tags_picking_string_keys_f…

…rom_non_stringified_options_for_4-0-stable

Fetch value(s) from stringified options in tags that stringify options, based of 4-0-stable.
  • Loading branch information...
commit 35a289a8c0c30e55f64fd9fad44c3c2072c17a68 2 parents de20a6d + da38312
Rafael Mendonça França rafaelfranca authored
4 actionpack/CHANGELOG.md
View
@@ -1,5 +1,9 @@
## unreleased ##
+* Pick `DateField` `DateTimeField` and `ColorField` values from stringified options allowing use of symbol keys with helpers.
+
+ *Jon Rowe*
+
* Fix `Mime::Type.parse` when bad accepts header is looked up. Previously it
was setting `request.formats` with an array containing a `nil` value, which
raised an error when setting the controller formats.
2  actionpack/lib/action_view/helpers/tags/color_field.rb
View
@@ -4,7 +4,7 @@ module Tags # :nodoc:
class ColorField < TextField # :nodoc:
def render
options = @options.stringify_keys
- options["value"] = @options.fetch("value") { validate_color_string(value(object)) }
+ options["value"] = options.fetch("value") { validate_color_string(value(object)) }
@options = options
super
end
2  actionpack/lib/action_view/helpers/tags/datetime_field.rb
View
@@ -4,7 +4,7 @@ module Tags # :nodoc:
class DatetimeField < TextField # :nodoc:
def render
options = @options.stringify_keys
- options["value"] = @options.fetch("value") { format_date(value(object)) }
+ options["value"] = options.fetch("value") { format_date(value(object)) }
options["min"] = format_date(options["min"])
options["max"] = format_date(options["max"])
@options = options
17 actionpack/test/template/form_helper_test.rb
View
@@ -702,6 +702,11 @@ def test_color_field_with_invalid_hex_color_string
assert_dom_equal(expected, color_field("car", "color"))
end
+ def test_color_field_with_value_attr
+ expected = %{<input id="car_color" name="car[color]" type="color" value="#00FF00" />}
+ assert_dom_equal(expected, color_field("car", "color", value: "#00FF00"))
+ end
+
def test_search_field
expected = %{<input id="contact_notes_query" name="contact[notes_query]" type="search" />}
assert_dom_equal(expected, search_field("contact", "notes_query"))
@@ -732,6 +737,12 @@ def test_date_field_with_extra_attrs
assert_dom_equal(expected, date_field("post", "written_on", min: min_value, max: max_value, step: step))
end
+ def test_date_field_with_value_attr
+ expected = %{<input id="post_written_on" name="post[written_on]" type="date" value="2013-06-29" />}
+ value = Date.new(2013,6,29)
+ assert_dom_equal(expected, date_field("post", "written_on", value: value))
+ end
+
def test_date_field_with_timewithzone_value
previous_time_zone, Time.zone = Time.zone, 'UTC'
expected = %{<input id="post_written_on" name="post[written_on]" type="date" value="2004-06-15" />}
@@ -802,6 +813,12 @@ def test_datetime_field_with_extra_attrs
assert_dom_equal(expected, datetime_field("post", "written_on", min: min_value, max: max_value, step: step))
end
+ def test_datetime_field_with_value_attr
+ expected = %{<input id="post_written_on" name="post[written_on]" type="datetime" value="2013-06-29T13:37:00+00:00" />}
+ value = DateTime.new(2013,6,29,13,37)
+ assert_dom_equal(expected, datetime_field("post", "written_on", value: value))
+ end
+
def test_datetime_field_with_timewithzone_value
previous_time_zone, Time.zone = Time.zone, 'UTC'
expected = %{<input id="post_written_on" name="post[written_on]" type="datetime" value="2004-06-15T15:30:45.000+0000" />}
Please sign in to comment.
Something went wrong with that request. Please try again.