mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Use #grep to filter priority zones when a regexp is given
This commit is contained in:
parent
953e19ecd9
commit
b4051edf84
2 changed files with 5 additions and 3 deletions
|
@ -565,7 +565,7 @@ module ActionView
|
||||||
|
|
||||||
if priority_zones
|
if priority_zones
|
||||||
if priority_zones.is_a?(Regexp)
|
if priority_zones.is_a?(Regexp)
|
||||||
priority_zones = zones.select { |z| z =~ priority_zones }
|
priority_zones = zones.grep(priority_zones)
|
||||||
end
|
end
|
||||||
|
|
||||||
zone_options.safe_concat options_for_select(convert_zones[priority_zones], selected)
|
zone_options.safe_concat options_for_select(convert_zones[priority_zones], selected)
|
||||||
|
|
|
@ -1086,11 +1086,13 @@ class FormOptionsHelperTest < ActionView::TestCase
|
||||||
|
|
||||||
def test_time_zone_select_with_priority_zones_as_regexp
|
def test_time_zone_select_with_priority_zones_as_regexp
|
||||||
@firm = Firm.new("D")
|
@firm = Firm.new("D")
|
||||||
|
|
||||||
|
priority_zones = /A|D/
|
||||||
@fake_timezones.each_with_index do |tz, i|
|
@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
|
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]\">" +
|
assert_dom_equal "<select id=\"firm_time_zone\" name=\"firm[time_zone]\">" +
|
||||||
"<option value=\"A\">A</option>\n" +
|
"<option value=\"A\">A</option>\n" +
|
||||||
"<option value=\"D\" selected=\"selected\">D</option>" +
|
"<option value=\"D\" selected=\"selected\">D</option>" +
|
||||||
|
|
Loading…
Reference in a new issue