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

Use order instead of sort_by when getting available payment methods #1802

Merged
merged 2 commits into from
Mar 29, 2017

Conversation

luukveenis
Copy link

@luukveenis luukveenis commented Mar 27, 2017

The original implementation of Spree::PaymentMethod.available used .select which would turn the ActiveRecord::Relation object into an array and meant we had to use sort_by here.

In #1540 available was deprecated in favour of available_to_users and available_to_admin, each of which returns an ActiveRecord::Relation object. That means we can use order 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 of eql, since the latter won't do type conversions and the spec will fail because we get an ActiveRecord::Relation instead of an Array.

The original implementation of `Spree::PaymentMethod.available` used
`.select` which would turn the ActiveRecord::Relation into an array and
meant we had to use `sort_by`.

In solidusio#1540 `available` was deprecated in favour of `available_to_users`
and `available_to_admin`, each of which returns an
ActiveRecord::Relation object. That means we can use `order` to do the
sorting in SQL, which also allows users to chain more scopes onto the
return value if they wish.
Copy link
Contributor

@jhawthorn jhawthorn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. We will probably want to add a changelog entry.

Copy link
Member

@tvdeyen tvdeyen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@jordan-brough jordan-brough merged commit e12ea8b into solidusio:master Mar 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants