diff options
author | Sean Griffin <sean@thoughtbot.com> | 2014-12-08 12:45:21 -0700 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2014-12-08 12:48:24 -0700 |
commit | 7daeb98c769a3968a2ccf48ff593909bf1a9d7b0 (patch) | |
tree | 3f33df0a5f05b369b73f6a4680d9cfa06f21fe9d /actionview/test/actionpack/abstract | |
parent | 4ed60af60d8b0ce6696f03d2d77916713c39af12 (diff) | |
download | rails-7daeb98c769a3968a2ccf48ff593909bf1a9d7b0.tar.gz rails-7daeb98c769a3968a2ccf48ff593909bf1a9d7b0.tar.bz2 rails-7daeb98c769a3968a2ccf48ff593909bf1a9d7b0.zip |
Don't error when `attributes` is called on a frozen AR model
`freeze` will ultimately end up freezing the `AttributeSet`, which in
turn freezes its `@attributes` hash. However, we actually insert a
special object to lazily instantiate the values of the hash on demand.
When it does need to actually instantiate all of them for iteration (the
only case is `ActiveRecord::Base#attributes`, which calls
`AttributeSet#to_h`), it will set an instance variable as a performance
optimization
Since it's just an optimization for subsequent calls, and that method
being called at all is a very uncommon case, we can just leave the ivar
alone if we're frozen, as opposed to coming up with some overly
complicated mechanism for freezing which allows us to continue to modify
ourselves.
Fixes #17960
Diffstat (limited to 'actionview/test/actionpack/abstract')
0 files changed, 0 insertions, 0 deletions