Use order
instead of sort_by
when getting available payment methods
#1802
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.
The original implementation of
Spree::PaymentMethod.available
used.select
which would turn the ActiveRecord::Relation object into an array and meant we had to usesort_by
here.In #1540
available
was deprecated in favour ofavailable_to_users
andavailable_to_admin
, each of which returns an ActiveRecord::Relation object. That means we can useorder
to do the sorting in SQL, which also allows users to chain more scopes onto the return value if they wish.Note: I had to change the spec to use
eq
instead ofeql
, since the latter won't do type conversions and the spec will fail because we get an ActiveRecord::Relation instead of an Array.