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

Fix module/class nesting in calculator/* #2312

Merged
merged 1 commit into from
Nov 23, 2017

Conversation

cbrunsdon
Copy link
Contributor

Spree::Calculator is a class (that inherits from Spree::Base), but in
these definitions we don't clarify it as such.

max = preferred_max_items.to_i
quantity.times do |i|
# check max value to avoid divide by 0 errors
if (max == 0 && i == 0) || (max > 0) && (i % max == 0)

Choose a reason for hiding this comment

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

Use max.zero? instead of max == 0.
Use i.zero? instead of i == 0.
Use (i % max).zero? instead of i % max == 0.


return BigDecimal.new(0) if items_count == 0
return BigDecimal.new(0) if items_count == 0

Choose a reason for hiding this comment

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

Use items_count.zero? instead of items_count == 0.

@@ -1,58 +1,60 @@
require_dependency 'spree/calculator'
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this require make the change unnecessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Its not require_dependency'd everywhere its defined/used.

I'd say we fix the definitions to be consistent and not have to worry about it.

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.

I also prefer require_dependency over re-defining the same classes several times (and with that potential errors in future changes)

@cbrunsdon
Copy link
Contributor Author

Okay, I don't personally agree with the require_dependency over keeping the class definitions the same, but I'll switch it. Are we okay with me leaving them broken out so its clear Calculator is a class and not a module?

Since our class declarations are so busted, we need to ensure this is
lodaed first.
@cbrunsdon cbrunsdon force-pushed the fix_calculator_definitions branch from dfbf5d5 to 8215101 Compare November 8, 2017 02:45
@jhawthorn jhawthorn merged commit a44b358 into solidusio:master Nov 23, 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