1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #17975 from merongivian/add_test_for_search_field

Fix options overwritten by super
This commit is contained in:
Rafael Mendonça França 2014-12-09 13:02:35 -02:00
commit 5c7b5dc741
3 changed files with 15 additions and 11 deletions

View file

@ -3,20 +3,18 @@ module ActionView
module Tags # :nodoc: module Tags # :nodoc:
class SearchField < TextField # :nodoc: class SearchField < TextField # :nodoc:
def render def render
options = @options.stringify_keys super do |options|
if options["autosave"]
if options["autosave"] if options["autosave"] == true
if options["autosave"] == true options["autosave"] = request.host.split(".").reverse.join(".")
options["autosave"] = request.host.split(".").reverse.join(".") end
options["results"] ||= 10
end end
options["results"] ||= 10
end
if options["onsearch"] if options["onsearch"]
options["incremental"] = true unless options.has_key?("incremental") options["incremental"] = true unless options.has_key?("incremental")
end
end end
super
end end
end end
end end

View file

@ -11,6 +11,7 @@ module ActionView
options["size"] = options["maxlength"] unless options.key?("size") options["size"] = options["maxlength"] unless options.key?("size")
options["type"] ||= field_type options["type"] ||= field_type
options["value"] = options.fetch("value") { value_before_type_cast(object) } unless field_type == "file" options["value"] = options.fetch("value") { value_before_type_cast(object) } unless field_type == "file"
yield options if block_given?
add_default_name_and_id(options) add_default_name_and_id(options)
tag("input", options) tag("input", options)
end end

View file

@ -928,6 +928,11 @@ class FormHelperTest < ActionView::TestCase
assert_dom_equal(expected, search_field("contact", "notes_query")) assert_dom_equal(expected, search_field("contact", "notes_query"))
end end
def test_search_field_with_onsearch_value
expected = %{<input onsearch="true" type="search" name="contact[notes_query]" id="contact_notes_query" incremental="true" />}
assert_dom_equal(expected, search_field("contact", "notes_query", onsearch: true))
end
def test_telephone_field def test_telephone_field
expected = %{<input id="user_cell" name="user[cell]" type="tel" />} expected = %{<input id="user_cell" name="user[cell]" type="tel" />}
assert_dom_equal(expected, telephone_field("user", "cell")) assert_dom_equal(expected, telephone_field("user", "cell"))