Skip to content

Commit

Permalink
TimeWithZone#freeze: preload instance variables so that we can actual…
Browse files Browse the repository at this point in the history
…ly freeze
  • Loading branch information
gbuesing committed Oct 20, 2008
1 parent 75b017c commit 3f3e3eb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
5 changes: 5 additions & 0 deletions activesupport/CHANGELOG
Original file line number Original file line Diff line number Diff line change
@@ -1,3 +1,8 @@
*Edge*

* TimeWithZone#freeze: preload instance variables so that we can actually freeze [Geoff Buesing]


*2.1.1 (September 4th, 2008)* *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 * 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
Expand Down
6 changes: 3 additions & 3 deletions activesupport/lib/active_support/time_with_zone.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -252,10 +252,10 @@ def is_a?(klass)
klass == ::Time || super klass == ::Time || super
end end
alias_method :kind_of?, :is_a? alias_method :kind_of?, :is_a?


# Neuter freeze because freezing can cause problems with lazy loading of attributes.
def freeze def freeze
self period; utc; time # preload instance variables before freezing
super
end end


def marshal_dump def marshal_dump
Expand Down
13 changes: 13 additions & 0 deletions activesupport/test/core_ext/time_with_zone_test.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -341,6 +341,19 @@ def test_marshal_dump_and_load_with_tzinfo_identifier
assert_equal @twz.inspect, mtime.inspect assert_equal @twz.inspect, mtime.inspect
end end
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 uses_mocha 'TestDatePartValueMethods' do
def test_method_missing_with_non_time_return_value def test_method_missing_with_non_time_return_value
Expand Down

0 comments on commit 3f3e3eb

Please sign in to comment.