aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/dirty_test.rb
diff options
context:
space:
mode:
authorWill Bryant <will.bryant@gmail.com>2017-05-09 22:04:22 +1200
committerWill Bryant <will.bryant@gmail.com>2017-05-10 11:23:33 +1200
commitba2190b3b6e506d7e5cede710594b22f9d937f39 (patch)
tree6cb03039d9a5bea65099248e9a49040cf6fc797a /activerecord/test/cases/dirty_test.rb
parent943efa30f5475f51fe90df5f85703d191dbd7d6e (diff)
downloadrails-ba2190b3b6e506d7e5cede710594b22f9d937f39.tar.gz
rails-ba2190b3b6e506d7e5cede710594b22f9d937f39.tar.bz2
rails-ba2190b3b6e506d7e5cede710594b22f9d937f39.zip
fix the dirty tracking code's save hook overwriting missing attributes with initialized-to-nil attributes. fixes #29017.
Diffstat (limited to 'activerecord/test/cases/dirty_test.rb')
-rw-r--r--activerecord/test/cases/dirty_test.rb7
1 files changed, 7 insertions, 0 deletions
diff --git a/activerecord/test/cases/dirty_test.rb b/activerecord/test/cases/dirty_test.rb
index 721861975a..1fc78f8d32 100644
--- a/activerecord/test/cases/dirty_test.rb
+++ b/activerecord/test/cases/dirty_test.rb
@@ -775,6 +775,13 @@ class DirtyTest < ActiveRecord::TestCase
assert person.changed?
end
+ test "attributes not selected are still missing after save" do
+ person = Person.select(:id).first
+ assert_raises(ActiveModel::MissingAttributeError) { person.first_name }
+ assert person.save # calls forget_attribute_assignments
+ assert_raises(ActiveModel::MissingAttributeError) { person.first_name }
+ end
+
test "saved_change_to_attribute? returns whether a change occurred in the last save" do
person = Person.create!(first_name: "Sean")