Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rails 7.2 compatibility #1632

Merged
merged 6 commits into from
Aug 15, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix default value for attributes breaking in Rails 7.2
  • Loading branch information
theodorton committed Aug 15, 2024
commit 0a4c834d1ce75769f9e90bc195e2ff2f1af5ec60
13 changes: 12 additions & 1 deletion lib/shoulda/matchers/active_record/define_enum_for_matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -655,11 +655,22 @@ def expected_default_value
end

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

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