aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2018-01-03 05:14:18 +0900
committerRyuta Kamizono <kamipo@gmail.com>2018-01-03 05:14:18 +0900
commita954e1e81711def521644050db9a08f073d0636c (patch)
treeeab81fb8832c5cf78b0e36ec962c2f71b26c02fa
parent921b877c2fd51cc0abdcf0ef6ca3528808047056 (diff)
parentba2190b3b6e506d7e5cede710594b22f9d937f39 (diff)
downloadrails-a954e1e81711def521644050db9a08f073d0636c.tar.gz
rails-a954e1e81711def521644050db9a08f073d0636c.tar.bz2
rails-a954e1e81711def521644050db9a08f073d0636c.zip
Merge pull request #29018 from willbryant/missing_attributes_after_save
fix the dirty tracking code's save hook overwriting missing attributeā€¦
-rw-r--r--activemodel/lib/active_model/attribute.rb4
-rw-r--r--activerecord/test/cases/dirty_test.rb7
2 files changed, 11 insertions, 0 deletions
diff --git a/activemodel/lib/active_model/attribute.rb b/activemodel/lib/active_model/attribute.rb
index b75ff80b31..27f3e38e31 100644
--- a/activemodel/lib/active_model/attribute.rb
+++ b/activemodel/lib/active_model/attribute.rb
@@ -233,6 +233,10 @@ module ActiveModel
false
end
+ def forgetting_assignment
+ dup
+ end
+
def with_type(type)
self.class.new(name, type)
end
diff --git a/activerecord/test/cases/dirty_test.rb b/activerecord/test/cases/dirty_test.rb
index a602f83d8c..d4408776d3 100644
--- a/activerecord/test/cases/dirty_test.rb
+++ b/activerecord/test/cases/dirty_test.rb
@@ -771,6 +771,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")