1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #45645 from fatkodima/fix-store-dirty

Updating the `ActiveRecord::Store` and changing it back should not mark accessor as changed
This commit is contained in:
Jean Boussier 2022-09-19 11:22:38 +02:00 committed by GitHub
commit 6b246e9f22
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 4 deletions

View file

@ -225,11 +225,8 @@ module ActiveRecord
def self.write(object, attribute, key, value)
prepare(object, attribute)
if value != read(object, attribute, key)
object.public_send :"#{attribute}_will_change!"
object.public_send(attribute)[key] = value
end
end
def self.prepare(object, attribute)
object.public_send :"#{attribute}=", {} unless object.send(attribute)

View file

@ -104,6 +104,14 @@ class StoreTest < ActiveRecord::TestCase
assert_not @john.color_changed?
end
test "updating the store and changing it back won't mark accessor as changed" do
@john.color = "red"
assert_equal "black", @john.color_was
@john.color = "black"
assert_not_predicate @john, :settings_changed?
assert_not_predicate @john, :color_changed?
end
test "updating the store populates the accessor changed array correctly" do
@john.color = "red"
assert_equal "black", @john.color_was