mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #29018 from willbryant/missing_attributes_after_save
fix the dirty tracking code's save hook overwriting missing attribute…
This commit is contained in:
commit
a954e1e817
2 changed files with 11 additions and 0 deletions
|
@ -233,6 +233,10 @@ module ActiveModel
|
|||
false
|
||||
end
|
||||
|
||||
def forgetting_assignment
|
||||
dup
|
||||
end
|
||||
|
||||
def with_type(type)
|
||||
self.class.new(name, type)
|
||||
end
|
||||
|
|
|
@ -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")
|
||||
|
||||
|
|
Loading…
Reference in a new issue