aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2018-04-27 05:05:58 +0900
committerRyuta Kamizono <kamipo@gmail.com>2018-04-27 05:14:08 +0900
commit9e72e8e3949919f038ab584e4a42cd0502b1bc07 (patch)
treee2ae85a938a499caa97d3c6efe8e6a8b28c1aa5b
parent0f9fc2b1e6d8ba1817f3df59eafe3d4e0d1e584e (diff)
downloadrails-9e72e8e3949919f038ab584e4a42cd0502b1bc07.tar.gz
rails-9e72e8e3949919f038ab584e4a42cd0502b1bc07.tar.bz2
rails-9e72e8e3949919f038ab584e4a42cd0502b1bc07.zip
Add test case that assigning belongs_to on destroyed object raises frozen error
This is to ensure that the behavior has not changed before and after #31575.
-rw-r--r--activerecord/test/cases/associations/belongs_to_associations_test.rb7
1 files changed, 7 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/belongs_to_associations_test.rb b/activerecord/test/cases/associations/belongs_to_associations_test.rb
index 6b4f826766..a85b56ac4b 100644
--- a/activerecord/test/cases/associations/belongs_to_associations_test.rb
+++ b/activerecord/test/cases/associations/belongs_to_associations_test.rb
@@ -37,6 +37,13 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase
assert_equal companies(:first_firm).name, firm.name
end
+ def test_assigning_belongs_to_on_destroyed_object
+ client = Client.create!(name: "Client")
+ client.destroy!
+ assert_raise(frozen_error_class) { client.firm = nil }
+ assert_raise(frozen_error_class) { client.firm = Firm.new(name: "Firm") }
+ end
+
def test_missing_attribute_error_is_raised_when_no_foreign_key_attribute
assert_raises(ActiveModel::MissingAttributeError) { Client.select(:id).first.firm }
end