Fix deprecation of active payment methods #4414
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR #3837 added a rake task to deactivate payment method records that are
no longer valid because of removing a payment method class.
The task iterates over all payment method records and tries to
constantize from its polymorphic type column. When that process returns
a
NameError
, it assumes that the class is no longer present andproceeds to deactivate the record.
Before this commit,
ActiveSupport::Dependencies.constantize
was used.However, the method was removed on Rails 7 [1], so our code raised a
NoMethodError
. AsNoMethodError
is a subclass ofNameError
[2],the deactivation logic was called for every record.
As Rails recommends, we update the code to use
String#constantize
instead.
[1] - https://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#activesupport-dependencies-private-api-has-been-deleted
[2] - https://ruby-doc.org/core-3.1.0/NoMethodError.html
This fixes CI on master.
cc @luca-landa.