diff options
author | Jérémie Bonal <jeremie.bonal@gmail.com> | 2017-12-01 17:56:45 +0100 |
---|---|---|
committer | Jérémie Bonal <jeremie.bonal@gmail.com> | 2017-12-27 17:49:07 +0100 |
commit | 0d73056436329c21aa0cca972964e8df49670391 (patch) | |
tree | 95abb27fd0e77e56d566d8c1d715aa9b4f3c34ce /actionview/test | |
parent | b852ef2660dac36e348865b455fab7fbcc0d2a7f (diff) | |
download | rails-0d73056436329c21aa0cca972964e8df49670391.tar.gz rails-0d73056436329c21aa0cca972964e8df49670391.tar.bz2 rails-0d73056436329c21aa0cca972964e8df49670391.zip |
Allow the use of callable objects as group methods for grouped selects.
Replaced the uses of `group.send(...)` in `option_groups_from_collection_for_select`
by calls to `value_for_collection(group, ...)`, allowing the use of
procs, lambdas and other callable objects as parameters.
Diffstat (limited to 'actionview/test')
-rw-r--r-- | actionview/test/template/form_options_helper_test.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/actionview/test/template/form_options_helper_test.rb b/actionview/test/template/form_options_helper_test.rb index f0eed1e290..7dc5755df1 100644 --- a/actionview/test/template/form_options_helper_test.rb +++ b/actionview/test/template/form_options_helper_test.rb @@ -337,6 +337,22 @@ class FormOptionsHelperTest < ActionView::TestCase ) end + def test_option_groups_from_collection_for_select_with_callable_group_method + group_proc = Proc.new { |c| c.countries } + assert_dom_equal( + "<optgroup label=\"<Africa>\"><option value=\"<sa>\"><South Africa></option>\n<option value=\"so\">Somalia</option></optgroup><optgroup label=\"Europe\"><option value=\"dk\" selected=\"selected\">Denmark</option>\n<option value=\"ie\">Ireland</option></optgroup>", + option_groups_from_collection_for_select(dummy_continents, group_proc, "continent_name", "country_id", "country_name", "dk") + ) + end + + def test_option_groups_from_collection_for_select_with_callable_group_label_method + label_proc = Proc.new { |c| c.continent_name } + assert_dom_equal( + "<optgroup label=\"<Africa>\"><option value=\"<sa>\"><South Africa></option>\n<option value=\"so\">Somalia</option></optgroup><optgroup label=\"Europe\"><option value=\"dk\" selected=\"selected\">Denmark</option>\n<option value=\"ie\">Ireland</option></optgroup>", + option_groups_from_collection_for_select(dummy_continents, "countries", label_proc, "country_id", "country_name", "dk") + ) + end + def test_option_groups_from_collection_for_select_returns_html_safe_string assert option_groups_from_collection_for_select(dummy_continents, "countries", "continent_name", "country_id", "country_name", "dk").html_safe? end |