-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Conversation
This removes an unnecessary conversion of the count of completed orders (which is always necessarily an integer!) into a decimal number.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @brchristian! 👏
There was a problem hiding this 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?
@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. |
@brchristian I'm more for adding the exacxt number that we expect so just leaving: expect(subject.order_count).to eq order_count |
@kennyadsl sounds good, I have added the spec to this PR! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @brchristian!
Description
This removes an unnecessary conversion of the count of completed orders (which is always necessarily an integer!) into a decimal number.
Checklist: