1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

fix the dirty tracking code's save hook overwriting missing attributes with initialized-to-nil attributes. fixes #29017.

This commit is contained in:
Will Bryant 2017-05-09 22:04:22 +12:00
parent 943efa30f5
commit ba2190b3b6
2 changed files with 11 additions and 0 deletions

View file

@ -231,6 +231,10 @@ module ActiveRecord
false
end
def forgetting_assignment
dup
end
def with_type(type)
self.class.new(name, type)
end

View file

@ -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")