aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/test/template/form_options_helper_test.rb
diff options
context:
space:
mode:
authorneumayr <neumayr@users.noreply.github.com>2017-11-09 17:37:06 +0100
committerneumayr <neumayr@users.noreply.github.com>2017-11-09 17:37:06 +0100
commitead4776b82f838ee0630770d1852e8b02ac0f923 (patch)
treecc6416978ff0091d726d978d0b1fb8477108cd60 /actionview/test/template/form_options_helper_test.rb
parent0c2cb880e34c943275758ca6a6ff84afa7a29fba (diff)
downloadrails-ead4776b82f838ee0630770d1852e8b02ac0f923.tar.gz
rails-ead4776b82f838ee0630770d1852e8b02ac0f923.tar.bz2
rails-ead4776b82f838ee0630770d1852e8b02ac0f923.zip
Fix field_error_proc wrap form select optgroup and divider option tag
### Summary The [`:field_error_proc`](https://github.com/rails/rails/blob/master/actionview/lib/action_view/base.rb#L145) is responsible for decorating input tags that refer to attributes with errors. This default build-in rails feature wrap invalid form elements with additional markup: `<div class="field_with_errors">[…]</div>`. * Fix for `field_error_proc` wraps form select `optgroup` * Fix for `field_error_proc` wraps form select divider `option` * Add tests for uncovered elements with errors [Fixes #31088] #### Test coverage * `test_select_grouped_options_with_errors` * `test_time_zone_select_with_priority_zones_and_errors` #### Extend test coverage * `test_collection_select_with_errors` * `test_label_with_errors` * `test_check_box_with_errors` * `test_check_boxes_with_errors` * `test_radio_button_with_errors` * `test_radio_buttons_with_errors` * `test_collection_check_boxes_with_errors` * `test_collection_radio_buttons_with_errors`
Diffstat (limited to 'actionview/test/template/form_options_helper_test.rb')
-rw-r--r--actionview/test/template/form_options_helper_test.rb19
1 files changed, 19 insertions, 0 deletions
diff --git a/actionview/test/template/form_options_helper_test.rb b/actionview/test/template/form_options_helper_test.rb
index a66db2f3dc..f0eed1e290 100644
--- a/actionview/test/template/form_options_helper_test.rb
+++ b/actionview/test/template/form_options_helper_test.rb
@@ -1251,6 +1251,25 @@ class FormOptionsHelperTest < ActionView::TestCase
html
end
+ def test_time_zone_select_with_priority_zones_and_errors
+ @firm = Firm.new("D")
+ @firm.extend ActiveModel::Validations
+ @firm.errors[:time_zone] << "invalid"
+ zones = [ ActiveSupport::TimeZone.new("A"), ActiveSupport::TimeZone.new("D") ]
+ html = time_zone_select("firm", "time_zone", zones)
+ assert_dom_equal "<div class=\"field_with_errors\">" \
+ "<select id=\"firm_time_zone\" name=\"firm[time_zone]\">" \
+ "<option value=\"A\">A</option>\n" \
+ "<option value=\"D\" selected=\"selected\">D</option>" \
+ "<option value=\"\" disabled=\"disabled\">-------------</option>\n" \
+ "<option value=\"B\">B</option>\n" \
+ "<option value=\"C\">C</option>\n" \
+ "<option value=\"E\">E</option>" \
+ "</select>" \
+ "</div>",
+ html
+ end
+
def test_time_zone_select_with_default_time_zone_and_nil_value
@firm = Firm.new()
@firm.time_zone = nil