From 9e72e8e3949919f038ab584e4a42cd0502b1bc07 Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Fri, 27 Apr 2018 05:05:58 +0900 Subject: 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. --- .../test/cases/associations/belongs_to_associations_test.rb | 7 +++++++ 1 file changed, 7 insertions(+) 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 -- cgit v1.2.3