-
-
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
Add Comparable to Spree::Money #1682
Add Comparable to Spree::Money #1682
Conversation
@@ -268,4 +268,32 @@ | |||
end | |||
end | |||
end | |||
|
|||
describe "<=>" do |
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.
I thought about also adding tests for <
, >
, .between?
, and .sort
as those also get included with Comparable
but I didn't want to get into the habit of testing another module. Any thoughts?
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.
What about testing that Comparable
is included? This way, if we remove that module, we'll be sure that some test will fail.
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.
Yes to testing that Comparable
is included 👍
No need to test a well tested module from Rubys standard lib
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.
Makes sense to me, I'll include that.
"Can't compare #{self.currency} with #{other.currency}" | ||
) | ||
end | ||
self.money <=> other.money |
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.
I'm not sure which one is better here but in the rest of the file to read attributes we used @money
instead of self.money
. Is there any reason to change this here? (I think it also applies to self.currency -> @currency
). If they are equivalent we should probably be more consistent.
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.
@money
would work as this is a attr_reader
, won't work for @currency
, though, as this is a delegate to money
👍 for being consistent on @money
and currency
usage.
🤔 thinking to enable Rubocops "redundant self" checks...
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.
Will fix.
@@ -268,4 +268,32 @@ | |||
end | |||
end | |||
end | |||
|
|||
describe "<=>" do |
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.
What about testing that Comparable
is included? This way, if we remove that module, we'll be sure that some test will fail.
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.
Only little nits, nothing that would hold us back from merging
@@ -268,4 +268,32 @@ | |||
end | |||
end | |||
end | |||
|
|||
describe "<=>" do |
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.
Yes to testing that Comparable
is included 👍
No need to test a well tested module from Rubys standard lib
"Can't compare #{self.currency} with #{other.currency}" | ||
) | ||
end | ||
self.money <=> other.money |
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.
@money
would work as this is a attr_reader
, won't work for @currency
, though, as this is a delegate to money
👍 for being consistent on @money
and currency
usage.
🤔 thinking to enable Rubocops "redundant self" checks...
238626b
to
5ad8d6d
Compare
@kennyadsl @tvdeyen fixed the |
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.
Great!
This could use a changelog entry
This commit includes Comparable and implements `<=>`. Including Comparable also gives us some basic comparison methods like `<`, `>`, `.between?`, and `sort`. We need to add an additional currency comparison because `::Money` will automatically try to convert the second currency in order to be able to compare it with the first. We don't want this to happen so we're going to explicitly raise an error.
5ad8d6d
to
943b2c5
Compare
@jhawthorn changelog entry added. |
Fixes #1650