diff options
author | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2013-02-21 13:31:13 -0300 |
---|---|---|
committer | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2013-02-21 13:32:34 -0300 |
commit | b4051edf841c8a6780df9af7afa9892bfd811c79 (patch) | |
tree | 722072eb4c5263bfb53bd9e7e6edd6e362209af0 /actionpack | |
parent | 953e19ecd97bad0d849f46a45cff01a057b6f9d6 (diff) | |
download | rails-b4051edf841c8a6780df9af7afa9892bfd811c79.tar.gz rails-b4051edf841c8a6780df9af7afa9892bfd811c79.tar.bz2 rails-b4051edf841c8a6780df9af7afa9892bfd811c79.zip |
Use #grep to filter priority zones when a regexp is given
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_view/helpers/form_options_helper.rb | 2 | ||||
-rw-r--r-- | actionpack/test/template/form_options_helper_test.rb | 6 |
2 files changed, 5 insertions, 3 deletions
diff --git a/actionpack/lib/action_view/helpers/form_options_helper.rb b/actionpack/lib/action_view/helpers/form_options_helper.rb index c7edf3dd7e..377819a80c 100644 --- a/actionpack/lib/action_view/helpers/form_options_helper.rb +++ b/actionpack/lib/action_view/helpers/form_options_helper.rb @@ -565,7 +565,7 @@ module ActionView if priority_zones if priority_zones.is_a?(Regexp) - priority_zones = zones.select { |z| z =~ priority_zones } + priority_zones = zones.grep(priority_zones) end zone_options.safe_concat options_for_select(convert_zones[priority_zones], selected) diff --git a/actionpack/test/template/form_options_helper_test.rb b/actionpack/test/template/form_options_helper_test.rb index b68bb159fe..04cdd068c8 100644 --- a/actionpack/test/template/form_options_helper_test.rb +++ b/actionpack/test/template/form_options_helper_test.rb @@ -1086,11 +1086,13 @@ class FormOptionsHelperTest < ActionView::TestCase def test_time_zone_select_with_priority_zones_as_regexp @firm = Firm.new("D") + + priority_zones = /A|D/ @fake_timezones.each_with_index do |tz, i| - tz.stubs(:=~).returns(i.zero? || i == 3) + priority_zones.stubs(:===).with(tz).returns(i.zero? || i == 3) end - html = time_zone_select("firm", "time_zone", /A|D/) + html = time_zone_select("firm", "time_zone", priority_zones) assert_dom_equal "<select id=\"firm_time_zone\" name=\"firm[time_zone]\">" + "<option value=\"A\">A</option>\n" + "<option value=\"D\" selected=\"selected\">D</option>" + |