diff options
author | Sean Griffin <sean@thoughtbot.com> | 2014-12-22 14:55:58 -0700 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2014-12-22 14:55:58 -0700 |
commit | 18ae0656f527e790bdc827fe68e3f2edd541b3a4 (patch) | |
tree | 954a7fd17c2f88a322f7f9b4efac0eeb3b1d76ba /activerecord/test/cases | |
parent | 849274316dc136135c50895e898e294904fec7a2 (diff) | |
download | rails-18ae0656f527e790bdc827fe68e3f2edd541b3a4.tar.gz rails-18ae0656f527e790bdc827fe68e3f2edd541b3a4.tar.bz2 rails-18ae0656f527e790bdc827fe68e3f2edd541b3a4.zip |
Don't calculate all in-place changes to determine if attribute_changed?
Calling `changed_attributes` will ultimately check if every mutable
attribute has changed in place. Since this gets called whenever an
attribute is assigned, it's extremely slow. Instead, we can avoid this
calculation until we actually need it.
Fixes #18029
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/dirty_test.rb | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/activerecord/test/cases/dirty_test.rb b/activerecord/test/cases/dirty_test.rb index eb9b1a2d74..1eaff5e293 100644 --- a/activerecord/test/cases/dirty_test.rb +++ b/activerecord/test/cases/dirty_test.rb @@ -698,6 +698,21 @@ class DirtyTest < ActiveRecord::TestCase assert binary.changed? end + test "attribute_changed? doesn't compute in-place changes for unrelated attributes" do + test_type_class = Class.new(ActiveRecord::Type::Value) do + define_method(:changed_in_place?) do |*| + raise + end + end + klass = Class.new(ActiveRecord::Base) do + self.table_name = 'people' + attribute :foo, test_type_class.new + end + + model = klass.new(first_name: "Jim") + assert model.first_name_changed? + end + private def with_partial_writes(klass, on = true) old = klass.partial_writes? |