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:
parent
943efa30f5
commit
ba2190b3b6
2 changed files with 11 additions and 0 deletions
|
@ -231,6 +231,10 @@ module ActiveRecord
|
|||
false
|
||||
end
|
||||
|
||||
def forgetting_assignment
|
||||
dup
|
||||
end
|
||||
|
||||
def with_type(type)
|
||||
self.class.new(name, type)
|
||||
end
|
||||
|
|
|
@ -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")
|
||||
|
||||
|
|
Loading…
Reference in a new issue