From 8a4c61ebabf9751b096df86b1cca0ef159bb2d0a Mon Sep 17 00:00:00 2001 From: Knut Stenmark Date: Thu, 9 Nov 2023 15:25:40 +0100 Subject: [PATCH 1/2] Ensure that ActiveRecord is not addressed unless it is defined --- lib/shoulda/matchers/rails_shim.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/shoulda/matchers/rails_shim.rb b/lib/shoulda/matchers/rails_shim.rb index 5c903d4e5..17fc92a5d 100644 --- a/lib/shoulda/matchers/rails_shim.rb +++ b/lib/shoulda/matchers/rails_shim.rb @@ -62,7 +62,7 @@ def generate_validation_message( def serialized_attributes_for(model) attribute_types_for(model). inject({}) do |hash, (attribute_name, attribute_type)| - if attribute_type.is_a?(::ActiveRecord::Type::Serialized) + if Object.const_defined?('ActiveRecord::Type::Serialized') && attribute_type.is_a?(::ActiveRecord::Type::Serialized) hash.merge(attribute_name => attribute_type.coder) else hash From e8091a013046381ffd41e5c3ea47f502a2856232 Mon Sep 17 00:00:00 2001 From: Knut Stenmark Date: Sun, 12 Nov 2023 12:21:21 +0100 Subject: [PATCH 2/2] Move test for serialized type outside block --- lib/shoulda/matchers/rails_shim.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/shoulda/matchers/rails_shim.rb b/lib/shoulda/matchers/rails_shim.rb index 17fc92a5d..c752e831f 100644 --- a/lib/shoulda/matchers/rails_shim.rb +++ b/lib/shoulda/matchers/rails_shim.rb @@ -60,9 +60,10 @@ def generate_validation_message( end def serialized_attributes_for(model) + type_serialized_defined = Object.const_defined?('ActiveRecord::Type::Serialized') attribute_types_for(model). inject({}) do |hash, (attribute_name, attribute_type)| - if Object.const_defined?('ActiveRecord::Type::Serialized') && attribute_type.is_a?(::ActiveRecord::Type::Serialized) + if type_serialized_defined && attribute_type.is_a?(::ActiveRecord::Type::Serialized) hash.merge(attribute_name => attribute_type.coder) else hash