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