Skip to content

Commit

Permalink
fix: Ensure that validation specs work for ActiveModel without Active…
Browse files Browse the repository at this point in the history
…Record (#1580)

* Ensure that ActiveRecord is not addressed unless it is defined

* Move test for serialized type outside block
  • Loading branch information
stonefield authored Dec 1, 2023
1 parent 7e069cf commit 5d60245
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/shoulda/matchers/rails_shim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 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
Expand Down

0 comments on commit 5d60245

Please sign in to comment.