-
-
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 default address dependency #2686
Conversation
@@ -10,13 +10,14 @@ module Spree | |||
let(:simulate) { false } | |||
let!(:default_refund_reason) { Spree::RefundReason.find_or_create_by!(name: Spree::RefundReason::RETURN_PROCESSING_REASON, mutable: false) } | |||
let(:creditable) { DummyCreditable.new(amount: 99.99) } | |||
let(:created_by_user) { create(:user, email: 'user@email.com') } |
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.
Layout/ExtraSpacing: Unnecessary spacing detected.
@@ -12,10 +12,10 @@ module Spree | |||
let!(:default_refund_reason) { Spree::RefundReason.find_or_create_by!(name: Spree::RefundReason::RETURN_PROCESSING_REASON, mutable: false) } | |||
|
|||
let!(:primary_credit_type) { create(:primary_credit_type) } | |||
let!(:created_by_user) { create(:user, email: Spree::StoreCredit::DEFAULT_CREATED_BY_EMAIL) } | |||
let(:created_by_user) { create(:user, email: 'user@email.com') } |
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.
Layout/ExtraSpacing: Unnecessary spacing detected.
4659aa4
to
4a33f3a
Compare
Yes I did. |
My main concern about this is that we're changing the public API for some of these key methods. Could we user |
I see your point. I've removed the default user constant in this PR - what do you think about rather than using |
Yeah. That's what I was thinking. |
I'll make that change, thanks! |
Without a user with email address equal to 'spree@example.com', when a reimbursement is created a Spree::StoreCredit is not. This spec illustrates this behaviour.
Previously, reimbursement helpers did not take a parameter for the creator of the reimbursement. Instead, they relied on a hard-coded dependency on a user in the database existing with the email address 'spree@example.com'.
4a33f3a
to
ebf0f66
Compare
@@ -4,17 +4,33 @@ class Spree::ReimbursementType::StoreCredit < Spree::ReimbursementType | |||
extend Spree::ReimbursementType::ReimbursementHelpers | |||
|
|||
class << self | |||
def reimburse(reimbursement, return_items, simulate) | |||
def reimburse(reimbursement, return_items, simulate, creator=nil) |
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.
Layout/SpaceAroundEqualsInParameterDefault: Surrounding space missing in default value assignment.
@@ -5,9 +5,13 @@ class ReimbursementType::Credit < Spree::ReimbursementType | |||
extend Spree::ReimbursementType::ReimbursementHelpers | |||
|
|||
class << self | |||
def reimburse(reimbursement, return_items, simulate) | |||
def reimburse(reimbursement, return_items, simulate, creator=nil) |
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.
Layout/SpaceAroundEqualsInParameterDefault: Surrounding space missing in default value assignment.
end | ||
|
||
# Actually perform the reimbursement | ||
def perform(reimbursement) | ||
execute(reimbursement, false) | ||
def perform(reimbursement, creator=nil) |
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.
Layout/SpaceAroundEqualsInParameterDefault: Surrounding space missing in default value assignment.
@@ -11,22 +11,30 @@ class << self | |||
# - #description | |||
# - #display_amount | |||
# so they can be displayed in the Admin UI appropriately. | |||
def simulate(reimbursement) | |||
execute(reimbursement, true) | |||
def simulate(reimbursement, creator=nil) |
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.
Layout/SpaceAroundEqualsInParameterDefault: Surrounding space missing in default value assignment.
@@ -140,10 +148,14 @@ def all_exchanges? | |||
# | |||
# @api public | |||
# @return [void] | |||
def return_all | |||
def return_all(creator=nil) |
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.
Layout/SpaceAroundEqualsInParameterDefault: Surrounding space missing in default value assignment.
@@ -116,12 +120,16 @@ def perform! | |||
end | |||
end | |||
|
|||
def simulate | |||
def simulate(creator=nil) |
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.
Layout/SpaceAroundEqualsInParameterDefault: Surrounding space missing in default value assignment.
@@ -98,12 +98,16 @@ def unpaid_amount | |||
total - paid_amount | |||
end | |||
|
|||
def perform! | |||
def perform!(creator=nil) |
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.
Layout/SpaceAroundEqualsInParameterDefault: Surrounding space missing in default value assignment.
@@ -83,13 +83,17 @@ def cancel_unit(inventory_unit, reason: Spree::UnitCancel::DEFAULT_REASON, whodu | |||
# @api public | |||
# @param [Array<InventoryUnit>] inventory_units the inventory units to be reimbursed | |||
# @return [Reimbursement] the reimbursement for inventory being canceled | |||
def reimburse_units(inventory_units) | |||
def reimburse_units(inventory_units, creator=nil) |
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.
Layout/SpaceAroundEqualsInParameterDefault: Surrounding space missing in default value assignment.
68961a4
to
6a274ae
Compare
I have run this locally and it passes for me with the same seed, with |
I am getting the same deprecation errors locally, which are considered failures on CI |
Ah I didn't realize that, thanks John! Will fix. |
Reimbursements only work if there is a user with the email address 'spree@example.com', or if you explicitly pass the creator when creating a reimbursement. This commit adds to the testing set-up for this spec by mocking a signed in admin creating the reimbursement, who can be passed as the creator.
6a274ae
to
f7cd81e
Compare
Fixed. Thanks for the feedback! |
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.
This is not blocked anymore, right?
@kennyadsl you are correct, thanks! |
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.
Like the change, despite the many changes. I think we can improve this by using named arguments.
@@ -83,13 +83,17 @@ def cancel_unit(inventory_unit, reason: Spree::UnitCancel::DEFAULT_REASON, whodu | |||
# @api public | |||
# @param [Array<InventoryUnit>] inventory_units the inventory units to be reimbursed | |||
# @return [Reimbursement] the reimbursement for inventory being canceled | |||
def reimburse_units(inventory_units) | |||
def reimburse_units(inventory_units, creator = nil) |
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.
Could we use a named argument here?
def reimburse_units(inventory_units, creator: nil)
@@ -98,12 +98,16 @@ def unpaid_amount | |||
total - paid_amount | |||
end | |||
|
|||
def perform! | |||
def perform!(creator = nil) |
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.
A named parameter would help the self-documentation of this method.
@@ -13,7 +13,7 @@ class ReimbursementsController < ResourceController | |||
rescue_from Spree::Core::GatewayError, with: :spree_core_gateway_error | |||
|
|||
def perform | |||
@reimbursement.perform! | |||
@reimbursement.perform!(try_spree_current_user) |
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.
A named argument would explain the purpose of this argument:
@reimbursement.perform!(creator: try_spree_current_user)
@@ -57,7 +57,7 @@ def load_stock_locations | |||
end | |||
|
|||
def load_simulated_refunds | |||
@reimbursement_objects = @reimbursement.simulate | |||
@reimbursement_objects = @reimbursement.simulate(try_spree_current_user) |
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.
Here as well
@reimbursement.simulate(creator: try_spree_current_user)
@@ -116,12 +120,16 @@ def perform! | |||
end | |||
end | |||
|
|||
def simulate | |||
def simulate(creator = nil) |
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.
Ditto: Named argument
@gevann is this something you're still working on? |
@jacobherrington I've opened #2802 to complete this one, I think we can close this. |
This PR is blocked on #2687.
This PR aims to resolve #2645 by eliminating a hard-coded dependency on a user in the database with the email address
'spree@example.com'
. In order to achieve this, the user that creates the reimbursement has to be passed down the call chain from the backend. Since the call chain for reimbursements is particularly long, this PR has many changes in it, however they are all aimed at ensuring that when aSpree::StoreCredit
is eventually created by a reimbursement, that it has as the creator without having to rely on specific email addresses existing.