Skip to content

Commit

Permalink
TimeZone requires preloading before #freeze
Browse files Browse the repository at this point in the history
'Can't modify frozen object' when calling #freeze after instantiation
  • Loading branch information
jfelchner committed Jul 31, 2011
1 parent 553d9ea commit 12ad541
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions activesupport/lib/active_support/values/time_zone.rb
Expand Up @@ -289,6 +289,12 @@ def now
Time.now.utc.in_time_zone(self)
end

# Preload information prior to freezing
def freeze
tzinfo; utc_offset;
super
end

# Return the current date in this time zone.
def today
tzinfo.now.to_date
Expand Down
17 changes: 17 additions & 0 deletions activesupport/test/time_zone_test.rb
Expand Up @@ -294,6 +294,23 @@ def test_new
assert_equal ActiveSupport::TimeZone["Central Time (US & Canada)"], ActiveSupport::TimeZone.new("Central Time (US & Canada)")
end

def test_freeze
@tz = ActiveSupport::TimeZone.new("Arizona")
@tz.freeze

assert @tz.frozen?
end

def test_freeze_preloads_instance_variables
@tz = ActiveSupport::TimeZone.new('Alaska')

assert_nothing_raised do
@tz.freeze
@tz.utc_offset
@tz.tzinfo
end
end

def test_us_zones
assert ActiveSupport::TimeZone.us_zones.include?(ActiveSupport::TimeZone["Hawaii"])
assert !ActiveSupport::TimeZone.us_zones.include?(ActiveSupport::TimeZone["Kuala Lumpur"])
Expand Down

0 comments on commit 12ad541

Please sign in to comment.