Permalink
Browse files

Merge pull request #9330 from bdmac/time_zone_select_dup

Fix time_zone_options_for_select to not mutate TimeZones array
  • Loading branch information...
2 parents 862e751 + 5c73f0d commit c3f1b1d3cdb837a24d66b80deda39cfe23856724 @pixeltrix pixeltrix committed Feb 20, 2013
@@ -1,5 +1,13 @@
## Rails 4.0.0 (unreleased) ##
+* Fix `time_zone_options_for_select` to call `dup` on the returned TimeZone array.
+
+ Previously if you supplied :priority_zones options to `time_zone_options_for_select`
+ the memoized ActiveSupport::TimeZone.all array would be mutated. Calling
+ `dup` prevents mutation of the main TimeZones array.
+
+ *Brian McManus*
+
* Remove support for parsing YAML parameters from request.
*Aaron Patterson*
@@ -560,7 +560,7 @@ def grouped_options_for_select(grouped_options, selected_key = nil, options = {}
def time_zone_options_for_select(selected = nil, priority_zones = nil, model = ::ActiveSupport::TimeZone)
zone_options = "".html_safe
- zones = model.all
+ zones = model.all.dup
convert_zones = lambda { |list| list.map { |z| [ z.to_s, z.name ] } }
if priority_zones
@@ -416,6 +416,13 @@ def test_time_zone_options_with_unselected_priority_zones
"<option value=\"D\">D</option>",
opts
end
+
+ def test_time_zone_options_with_priority_zones_does_not_mutate_time_zones
+ original_zones = ActiveSupport::TimeZone.all.dup
+ zones = [ ActiveSupport::TimeZone.new( "B" ), ActiveSupport::TimeZone.new( "E" ) ]
+ opts = time_zone_options_for_select( nil, zones )
+ assert_equal original_zones, ActiveSupport::TimeZone.all
+ end
def test_time_zone_options_returns_html_safe_string
assert time_zone_options_for_select.html_safe?

0 comments on commit c3f1b1d

Please sign in to comment.