From ea721d7027c16f64c47395546c67858060a273e3 Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Sun, 18 Jan 2015 13:43:31 -0700 Subject: Don't calculate in-place changes on attribute assignment When an attribute is assigned, we determine if it was already marked as changed so we can determine if we need to clear the changes, or mark it as changed. Since this only affects the `attributes_changed_by_setter` hash, in-place changes are irrelevant to this process. Since calculating in-place changes can be expensive, we can just skip it here. I also added a test for the only edge case I could think of that would be affected by this change. --- activerecord/test/cases/dirty_test.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'activerecord/test/cases/dirty_test.rb') diff --git a/activerecord/test/cases/dirty_test.rb b/activerecord/test/cases/dirty_test.rb index ae4a8aab2c..192ba6f7cd 100644 --- a/activerecord/test/cases/dirty_test.rb +++ b/activerecord/test/cases/dirty_test.rb @@ -721,6 +721,14 @@ class DirtyTest < ActiveRecord::TestCase assert record.save end + test "mutating and then assigning doesn't remove the change" do + pirate = Pirate.create!(catchphrase: "arrrr") + pirate.catchphrase << " matey!" + pirate.catchphrase = "arrrr matey!" + + assert pirate.catchphrase_changed?(from: "arrrr", to: "arrrr matey!") + end + private def with_partial_writes(klass, on = true) old = klass.partial_writes? -- cgit v1.2.3