Permalink
Browse files

Use #grep to filter priority zones when a regexp is given

  • Loading branch information...
1 parent 953e19e commit b4051edf841c8a6780df9af7afa9892bfd811c79 @carlosantoniodasilva carlosantoniodasilva committed Feb 21, 2013
View
2 actionpack/lib/action_view/helpers/form_options_helper.rb
@@ -565,7 +565,7 @@ def time_zone_options_for_select(selected = nil, priority_zones = nil, model = :
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)
View
6 actionpack/test/template/form_options_helper_test.rb
@@ -1086,11 +1086,13 @@ def test_time_zone_select_with_priority_zones
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>" +

0 comments on commit b4051ed

Please sign in to comment.