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:
commit
6b246e9f22
2 changed files with 9 additions and 4 deletions
|
@ -225,10 +225,7 @@ 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
|
||||
object.public_send(attribute)[key] = value
|
||||
end
|
||||
|
||||
def self.prepare(object, attribute)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue