Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

TimeWithZone#freeze: preload instance variables so that we can actual…

…ly freeze
  • Loading branch information...
commit 3f3e3eba892486597ded527f8773cc36bea5c1d8 1 parent 75b017c
@gbuesing gbuesing authored
View
5 activesupport/CHANGELOG
@@ -1,3 +1,8 @@
+*Edge*
+
+* TimeWithZone#freeze: preload instance variables so that we can actually freeze [Geoff Buesing]
+
+
*2.1.1 (September 4th, 2008)*
* 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
View
6 activesupport/lib/active_support/time_with_zone.rb
@@ -252,10 +252,10 @@ def is_a?(klass)
klass == ::Time || super
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
13 activesupport/test/core_ext/time_with_zone_test.rb
@@ -341,6 +341,19 @@ def test_marshal_dump_and_load_with_tzinfo_identifier
assert_equal @twz.inspect, mtime.inspect
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
Please sign in to comment.
Something went wrong with that request. Please try again.