Skip to content

Commit 3f3e3eb

Browse files
committed
TimeWithZone#freeze: preload instance variables so that we can actually freeze
1 parent 75b017c commit 3f3e3eb

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

activesupport/CHANGELOG

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
*Edge*
2+
3+
* TimeWithZone#freeze: preload instance variables so that we can actually freeze [Geoff Buesing]
4+
5+
16
*2.1.1 (September 4th, 2008)*
27

38
* Fix Ruby's Time marshaling bug in pre-1.9 versions of Ruby: utc instances are now correctly unmarshaled with a utc zone instead of the system local zone [#900 state:resolved]:activesupport/CHANGELOG

activesupport/lib/active_support/time_with_zone.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,10 @@ def is_a?(klass)
252252
klass == ::Time || super
253253
end
254254
alias_method :kind_of?, :is_a?
255-
256-
# Neuter freeze because freezing can cause problems with lazy loading of attributes.
255+
257256
def freeze
258-
self
257+
period; utc; time # preload instance variables before freezing
258+
super
259259
end
260260

261261
def marshal_dump

activesupport/test/core_ext/time_with_zone_test.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,19 @@ def test_marshal_dump_and_load_with_tzinfo_identifier
341341
assert_equal @twz.inspect, mtime.inspect
342342
end
343343
end
344+
345+
def test_freeze
346+
@twz.freeze
347+
assert @twz.frozen?
348+
end
349+
350+
def test_freeze_preloads_instance_variables
351+
@twz.freeze
352+
assert_nothing_raised do
353+
@twz.period
354+
@twz.time
355+
end
356+
end
344357

345358
uses_mocha 'TestDatePartValueMethods' do
346359
def test_method_missing_with_non_time_return_value

0 commit comments

Comments
 (0)