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

Remove unnecessary decimal conversion #3124

Merged
merged 2 commits into from
Mar 9, 2019

Conversation

brchristian
Copy link
Contributor

Description
This removes an unnecessary conversion of the count of completed orders (which is always necessarily an integer!) into a decimal number.

Checklist:

  • I have followed Pull Request guidelines
  • I have added a detailed description into each commit message
  • I have updated Guides and README accordingly to this change (if needed)
  • I have added tests to cover this change (if needed)

This removes an unnecessary conversion of the count of completed orders (which is always necessarily an integer!) into a decimal number.
brchristian added a commit to brchristian/solidus that referenced this pull request Feb 27, 2019
In the backend `User#index` action, we use the [`display_lifetime_value`](https://github.com/solidusio/solidus/blob/master/core/app/models/concerns/spree/user_reporting.rb#L8-L10) helper to get the total value of all _completed_ orders. However, we display the count of _all_ orders, which is inconsistent.

This commit changes this behavior and uses the existing [`order_count`](https://github.com/solidusio/solidus/blob/master/core/app/models/concerns/spree/user_reporting.rb#L12-L14) helper.

Note that one strange aspect of the current `order_count` helper is that it converts the count to a decimal unnecessarily, which will appear strangely, (e.g., `1.0`) in the backend view. This is fixed in a separate PR by solidusio#3124.
@brchristian brchristian mentioned this pull request Feb 27, 2019
4 tasks
Copy link
Contributor

@aitbw aitbw left a comment

Choose a reason for hiding this comment

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

Thanks @brchristian! 👏

Copy link
Member

@kennyadsl kennyadsl left a comment

Choose a reason for hiding this comment

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

Thanks @brchristian, we should probably update related specs as well, right?

@brchristian
Copy link
Contributor Author

@kennyadsl That’s a good idea! I’m surprised that current didn’t fail, actually.

What if we change from something like this:

expect(subject.order_count).to eq BigDecimal(order_count)

to something like this:

expect(subject.order_count).to eq subject.orders.complete.count

If that seems reasonable to you, I can add a commit to this PR.

@kennyadsl
Copy link
Member

@brchristian I'm more for adding the exacxt number that we expect so just leaving:

expect(subject.order_count).to eq order_count

@brchristian
Copy link
Contributor Author

@kennyadsl sounds good, I have added the spec to this PR!

Copy link
Contributor

@jacobherrington jacobherrington left a comment

Choose a reason for hiding this comment

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

Thanks @brchristian!

@jacobherrington jacobherrington merged commit 9600a2c into solidusio:master Mar 9, 2019
@brchristian brchristian deleted the patch-4 branch March 9, 2019 17:27
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