aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2013-03-31 15:46:48 -0700
committerCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2013-03-31 15:46:48 -0700
commit0a16cf19c2e2a2ba5cdb6ca849b60751f6cb52ed (patch)
tree194be28e7ac78b53f8544872e57c7a6a47160ca0 /actionpack
parent31216ec84b6988683c0c60e1ff08163a75d27680 (diff)
parent53d68bd964af17484898c5cd5e21a8ce9c359143 (diff)
downloadrails-0a16cf19c2e2a2ba5cdb6ca849b60751f6cb52ed.tar.gz
rails-0a16cf19c2e2a2ba5cdb6ca849b60751f6cb52ed.tar.bz2
rails-0a16cf19c2e2a2ba5cdb6ca849b60751f6cb52ed.zip
Merge pull request #9680 from bdmac/time-zone-options-revert-grep-to-select
Revert grep to select since they are not the same
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_view/helpers/form_options_helper.rb2
-rw-r--r--actionpack/test/template/form_options_helper_test.rb25
2 files changed, 23 insertions, 4 deletions
diff --git a/actionpack/lib/action_view/helpers/form_options_helper.rb b/actionpack/lib/action_view/helpers/form_options_helper.rb
index 8368e3de43..7e65ebb4e4 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.grep(priority_zones)
+ priority_zones = zones.select { |z| z =~ 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 29d63d9653..0b45d01593 100644
--- a/actionpack/test/template/form_options_helper_test.rb
+++ b/actionpack/test/template/form_options_helper_test.rb
@@ -1095,12 +1095,11 @@ 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|
- priority_zones.stubs(:===).with(tz).returns(i.zero? || i == 3)
+ tz.stubs(:=~).returns(i.zero? || i == 3)
end
- html = time_zone_select("firm", "time_zone", priority_zones)
+ html = time_zone_select("firm", "time_zone", /A|D/)
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>" +
@@ -1111,6 +1110,26 @@ class FormOptionsHelperTest < ActionView::TestCase
"</select>",
html
end
+
+ def test_time_zone_select_with_priority_zones_as_regexp_using_grep_finds_no_zones
+ @firm = Firm.new("D")
+
+ priority_zones = /A|D/
+ @fake_timezones.each_with_index do |tz, i|
+ priority_zones.stubs(:===).with(tz).raises(Exception)
+ end
+
+ html = time_zone_select("firm", "time_zone", priority_zones)
+ assert_dom_equal "<select id=\"firm_time_zone\" name=\"firm[time_zone]\">" +
+ "<option value=\"\" disabled=\"disabled\">-------------</option>\n" +
+ "<option value=\"A\">A</option>\n" +
+ "<option value=\"B\">B</option>\n" +
+ "<option value=\"C\">C</option>\n" +
+ "<option value=\"D\" selected=\"selected\">D</option>\n" +
+ "<option value=\"E\">E</option>" +
+ "</select>",
+ html
+ end
def test_time_zone_select_with_default_time_zone_and_nil_value
@firm = Firm.new()