Skip to content

Commit 6b246e9

Browse files
authored
Merge pull request rails#45645 from fatkodima/fix-store-dirty
Updating the `ActiveRecord::Store` and changing it back should not mark accessor as changed
2 parents f4418db + d492520 commit 6b246e9

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

activerecord/lib/active_record/store.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,7 @@ def self.read(object, attribute, key)
225225

226226
def self.write(object, attribute, key, value)
227227
prepare(object, attribute)
228-
if value != read(object, attribute, key)
229-
object.public_send :"#{attribute}_will_change!"
230-
object.public_send(attribute)[key] = value
231-
end
228+
object.public_send(attribute)[key] = value
232229
end
233230

234231
def self.prepare(object, attribute)

activerecord/test/cases/store_test.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,14 @@ class StoreTest < ActiveRecord::TestCase
104104
assert_not @john.color_changed?
105105
end
106106

107+
test "updating the store and changing it back won't mark accessor as changed" do
108+
@john.color = "red"
109+
assert_equal "black", @john.color_was
110+
@john.color = "black"
111+
assert_not_predicate @john, :settings_changed?
112+
assert_not_predicate @john, :color_changed?
113+
end
114+
107115
test "updating the store populates the accessor changed array correctly" do
108116
@john.color = "red"
109117
assert_equal "black", @john.color_was

0 commit comments

Comments
 (0)