Skip to content

Commit

Permalink
Preload to_datetime before freezing a TimeWithZone instance
Browse files Browse the repository at this point in the history
(cherry picked from commit 6560448)
  • Loading branch information
Adam Rice authored and pixeltrix committed Feb 22, 2017
1 parent d2cb7f5 commit 01738e5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions activesupport/CHANGELOG.md
@@ -1,3 +1,8 @@
* Cache `ActiveSupport::TimeWithZone#to_datetime` before freezing.

*Adam Rice*


## Rails 5.0.1 (December 21, 2016) ##

* No changes.
Expand Down
3 changes: 2 additions & 1 deletion activesupport/lib/active_support/time_with_zone.rb
Expand Up @@ -428,7 +428,8 @@ def blank?
end

def freeze
period; utc; time # preload instance variables before freezing
# preload instance variables before freezing
period; utc; time; to_datetime
super
end

Expand Down
1 change: 1 addition & 0 deletions activesupport/test/core_ext/time_with_zone_test.rb
Expand Up @@ -503,6 +503,7 @@ def test_freeze_preloads_instance_variables
assert_nothing_raised do
@twz.period
@twz.time
@twz.to_datetime
end
end

Expand Down

0 comments on commit 01738e5

Please sign in to comment.