From e4e62fbdc63374f9475d6768a2b4c3b3747d6362 Mon Sep 17 00:00:00 2001 From: alpaca-tc Date: Thu, 5 Nov 2020 20:52:27 +0900 Subject: [PATCH] ActiveModel::Model can be frozen again --- activemodel/lib/active_model/attributes.rb | 2 +- activemodel/test/cases/attributes_test.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/activemodel/lib/active_model/attributes.rb b/activemodel/lib/active_model/attributes.rb index 91441858f6..de94b1cf3b 100644 --- a/activemodel/lib/active_model/attributes.rb +++ b/activemodel/lib/active_model/attributes.rb @@ -115,7 +115,7 @@ module ActiveModel end def freeze - @attributes = @attributes.clone.freeze + @attributes = @attributes.clone.freeze unless frozen? super end diff --git a/activemodel/test/cases/attributes_test.rb b/activemodel/test/cases/attributes_test.rb index dd4922fe44..5e3ceda468 100644 --- a/activemodel/test/cases/attributes_test.rb +++ b/activemodel/test/cases/attributes_test.rb @@ -129,5 +129,11 @@ module ActiveModel assert data.frozen? assert_raise(FrozenError) { data.integer_field = 1 } end + + test "attributes can be frozen again" do + data = ModelForAttributesTest.new + data.freeze + assert_nothing_raised { data.freeze } + end end end