-
-
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
Fix class/module nesting #2098
Fix class/module nesting #2098
Conversation
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
return true | ||
else | ||
add_error(:number_of_days, Spree.t('return_item_time_period_ineligible')) | ||
return false |
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.
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 |
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.
Redundant return detected.
return true | ||
else | ||
add_error(:rma_required, Spree.t('return_item_rma_ineligible')) | ||
return false |
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.
Redundant return detected.
class RMARequired < Spree::ReturnItem::EligibilityValidator::BaseValidator | ||
def eligible_for_return? | ||
if @return_item.return_authorization.present? | ||
return true |
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.
Redundant return detected.
return true | ||
else | ||
add_error(:order_not_completed, Spree.t('return_item_order_not_completed')) | ||
return false |
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.
Redundant return detected.
class OrderCompleted < Spree::ReturnItem::EligibilityValidator::BaseValidator | ||
def eligible_for_return? | ||
if @return_item.inventory_unit.order.completed? | ||
return true |
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.
Redundant return detected.
add_error(:inventory_unit_reimbursed, Spree.t('return_item_inventory_unit_reimbursed')) | ||
return false | ||
else | ||
return true |
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.
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 |
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.
Redundant return detected.
return true | ||
else | ||
add_error(:inventory_unit_shipped, Spree.t('return_item_inventory_unit_ineligible')) | ||
return false |
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.
Redundant return detected.
class InventoryShipped < Spree::ReturnItem::EligibilityValidator::BaseValidator | ||
def eligible_for_return? | ||
if @return_item.inventory_unit.shipped? | ||
return true |
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.
Redundant return detected.
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 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)
Ahh, I guess require_dependency is what the autoloader uses to do these things. But yea, I'm happy explicitly spelling it out. |
😆 |
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.
Much clearer, thank you!
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.