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 class/module nesting #2098

Merged
merged 2 commits into from
Jul 20, 2017

Conversation

cbrunsdon
Copy link
Contributor

We had some cases in solidus where we were unclearly nesting classes and modules inside other classes and modules.

This breaks out the unclear definitions into what they should be.

Clarke Brunsdon added 2 commits July 18, 2017 16:44
Previously it was unclear when these were evaluated that
Spree::ReturnItem is actually an active record class (inherited from
Spree::Base). This makes it clear that we're actually nesting a class in
a module in a class in a module.
Spree::Reimbursement::Credit is a class nested in a class, which isn't
clear from the declaration. Spree::Reimbursement is an active record
model that inherits from Spree::Base
@cbrunsdon cbrunsdon changed the title Fix class module nesting Fix class/module nesting Jul 18, 2017
return true
else
add_error(:number_of_days, Spree.t('return_item_time_period_ineligible'))
return false

Choose a reason for hiding this comment

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

Redundant return detected.

class TimeSincePurchase < Spree::ReturnItem::EligibilityValidator::BaseValidator
def eligible_for_return?
if (@return_item.inventory_unit.order.completed_at + Spree::Config[:return_eligibility_number_of_days].days) > Time.current
return true

Choose a reason for hiding this comment

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

Redundant return detected.

return true
else
add_error(:rma_required, Spree.t('return_item_rma_ineligible'))
return false

Choose a reason for hiding this comment

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

Redundant return detected.

class RMARequired < Spree::ReturnItem::EligibilityValidator::BaseValidator
def eligible_for_return?
if @return_item.return_authorization.present?
return true

Choose a reason for hiding this comment

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

Redundant return detected.

return true
else
add_error(:order_not_completed, Spree.t('return_item_order_not_completed'))
return false

Choose a reason for hiding this comment

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

Redundant return detected.

class OrderCompleted < Spree::ReturnItem::EligibilityValidator::BaseValidator
def eligible_for_return?
if @return_item.inventory_unit.order.completed?
return true

Choose a reason for hiding this comment

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

Redundant return detected.

add_error(:inventory_unit_reimbursed, Spree.t('return_item_inventory_unit_reimbursed'))
return false
else
return true

Choose a reason for hiding this comment

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

Redundant return detected.

def eligible_for_return?
if @return_item.inventory_unit.return_items.reimbursed.valid.any?
add_error(:inventory_unit_reimbursed, Spree.t('return_item_inventory_unit_reimbursed'))
return false

Choose a reason for hiding this comment

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

Redundant return detected.

return true
else
add_error(:inventory_unit_shipped, Spree.t('return_item_inventory_unit_ineligible'))
return false

Choose a reason for hiding this comment

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

Redundant return detected.

class InventoryShipped < Spree::ReturnItem::EligibilityValidator::BaseValidator
def eligible_for_return?
if @return_item.inventory_unit.shipped?
return true

Choose a reason for hiding this comment

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

Redundant return detected.

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.

👍 I think this might also fix some confusion yard had with these classes.

Alternatively, I think require_dependency would let us make sure Reimbursement is loaded before these classes are defined (but this is just as good IMO)

@cbrunsdon
Copy link
Contributor Author

Ahh, I guess require_dependency is what the autoloader uses to do these things. But yea, I'm happy explicitly spelling it out.

@bbuchalter
Copy link
Contributor

bbuchalter commented Jul 19, 2017

a class in a module in a class in a module

😆

Copy link
Contributor

@mamhoff mamhoff left a comment

Choose a reason for hiding this comment

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

Much clearer, thank you!

@jhawthorn jhawthorn merged commit 6d09888 into solidusio:master Jul 20, 2017
@kennyadsl kennyadsl mentioned this pull request Feb 15, 2019
7 tasks
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.

6 participants