aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/dirty_test.rb
diff options
context:
space:
mode:
authorSean Griffin <sean@seantheprogrammer.com>2016-06-02 11:32:05 -0400
committerSean Griffin <sean@seantheprogrammer.com>2016-06-02 11:34:48 -0400
commitc587b636648394e33292ba8ba47d22bdad7446c3 (patch)
treedbd607c0e8ea3df407dc1dfd828843a863783e93 /activerecord/test/cases/dirty_test.rb
parentb604dd0b81c44c3b4605f31e8f4b914fa7686b1a (diff)
downloadrails-c587b636648394e33292ba8ba47d22bdad7446c3.tar.gz
rails-c587b636648394e33292ba8ba47d22bdad7446c3.tar.bz2
rails-c587b636648394e33292ba8ba47d22bdad7446c3.zip
Ensure that records with unselected fields can be updated
As part of refactoring mutation detection to be more performant, we introduced the concept of `original_value` to `Attribute`. This was not overridden in `Attribute::Uninitialized` however, so assigning ot an uninitialized value and calling `.changed?` would raise `NotImplementedError`. We are using a sentinel value rather than checking the result of `original_attribute.initialized?` in `changed?` because `original_value` might go through more than one node in the tree. Fixes #25228
Diffstat (limited to 'activerecord/test/cases/dirty_test.rb')
-rw-r--r--activerecord/test/cases/dirty_test.rb11
1 files changed, 11 insertions, 0 deletions
diff --git a/activerecord/test/cases/dirty_test.rb b/activerecord/test/cases/dirty_test.rb
index a3f8d26100..7ad9ff1f57 100644
--- a/activerecord/test/cases/dirty_test.rb
+++ b/activerecord/test/cases/dirty_test.rb
@@ -734,6 +734,17 @@ class DirtyTest < ActiveRecord::TestCase
assert_equal "arr", pirate.catchphrase
end
+ test "attributes assigned but not selected are dirty" do
+ person = Person.select(:id).first
+ refute person.changed?
+
+ person.first_name = "Sean"
+ assert person.changed?
+
+ person.first_name = nil
+ assert person.changed?
+ end
+
private
def with_partial_writes(klass, on = true)
old = klass.partial_writes?