TimeWithZone#freeze: preload instance variables so that we can actually freeze

This commit is contained in:
gbuesing 2008-10-19 22:33:26 -05:00
parent 93e1bff82a
commit c79f1d281f
3 changed files with 17 additions and 2 deletions

View File

@ -1,5 +1,7 @@
*Edge*
* TimeWithZone#freeze: preload instance variables so that we can actually freeze [Geoff Buesing]
* Fix Brasilia timezone #1180 [Marcus Derencius, Kane]
* Time#advance recognizes fractional days and weeks. Deprecate Durations of fractional months and years #970 [Tom Lea]

View File

@ -277,9 +277,9 @@ module ActiveSupport
end
alias_method :kind_of?, :is_a?
# Neuter freeze because freezing can cause problems with lazy loading of attributes.
def freeze
self
period; utc; time # preload instance variables before freezing
super
end
def marshal_dump

View File

@ -386,6 +386,19 @@ class TimeWithZoneTest < Test::Unit::TestCase
end
end
def test_freeze
@twz.freeze
assert @twz.frozen?
end
def test_freeze_preloads_instance_variables
@twz.freeze
assert_nothing_raised do
@twz.period
@twz.time
end
end
uses_mocha 'TestDatePartValueMethods' do
def test_method_missing_with_non_time_return_value
silence_warnings do # silence warnings raised by tzinfo gem