Skip to content

Commit

Permalink
Fix default value for attributes breaking in Rails 7.2
Browse files Browse the repository at this point in the history
  • Loading branch information
theodorton committed May 28, 2024
1 parent f44250d commit 1a14441
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -619,11 +619,17 @@ def expected_default_value
end

def actual_default_value
attribute_schema = model.attributes_to_define_after_schema_loads[attribute_name.to_s]
attribute_schema = model.respond_to?(:_default_attributes) ? model._default_attributes[attribute_name.to_s] : model.attributes_to_define_after_schema_loads[attribute_name.to_s]

if Kernel.const_defined?('ActiveModel::Attribute::UserProvidedDefault') && attribute_schema.is_a?(::ActiveModel::Attribute::UserProvidedDefault)
attribute_schema = attribute_schema.marshal_dump
end

value = case attribute_schema
in [_, { default: default_value } ]
default_value
in [_, default_value, *]
default_value
in [_, default_value]
default_value
end
Expand Down

0 comments on commit 1a14441

Please sign in to comment.