aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorgbuesing <gbuesing@gmail.com>2008-10-19 22:33:26 -0500
committergbuesing <gbuesing@gmail.com>2008-10-19 22:33:26 -0500
commitc79f1d281f1932d4203c7b5b5c793e370ed63838 (patch)
tree94323897b40b2a4f49600a7694a9447c2df263e4 /activesupport
parent93e1bff82a531c957bad91ea67e01b4793ccc51f (diff)
downloadrails-c79f1d281f1932d4203c7b5b5c793e370ed63838.tar.gz
rails-c79f1d281f1932d4203c7b5b5c793e370ed63838.tar.bz2
rails-c79f1d281f1932d4203c7b5b5c793e370ed63838.zip
TimeWithZone#freeze: preload instance variables so that we can actually freeze
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/CHANGELOG2
-rw-r--r--activesupport/lib/active_support/time_with_zone.rb4
-rw-r--r--activesupport/test/core_ext/time_with_zone_test.rb13
3 files changed, 17 insertions, 2 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG
index 68b1b66e13..803f95d90e 100644
--- a/activesupport/CHANGELOG
+++ b/activesupport/CHANGELOG
@@ -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]
diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb
index b7b8807c6d..a02cd81f72 100644
--- a/activesupport/lib/active_support/time_with_zone.rb
+++ b/activesupport/lib/active_support/time_with_zone.rb
@@ -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
diff --git a/activesupport/test/core_ext/time_with_zone_test.rb b/activesupport/test/core_ext/time_with_zone_test.rb
index 72b540efe0..774fd57ee6 100644
--- a/activesupport/test/core_ext/time_with_zone_test.rb
+++ b/activesupport/test/core_ext/time_with_zone_test.rb
@@ -385,6 +385,19 @@ class TimeWithZoneTest < Test::Unit::TestCase
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