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

Remove default address dependency #2686

Closed

Conversation

gevann
Copy link

@gevann gevann commented Apr 7, 2018

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 a Spree::StoreCredit is eventually created by a reimbursement, that it has as the creator without having to rely on specific email addresses existing.

@@ -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') }

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') }

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.

@gevann gevann force-pushed the remove-default-address-dependency branch 2 times, most recently from 4659aa4 to 4a33f3a Compare April 9, 2018 21:30
@gevann gevann changed the title Remove default address dependency Remove default address dependency [BLOCKED] Apr 9, 2018
@jhawthorn
Copy link
Contributor

This PR is blocked on #2685.

Do you mean #2687?

@gevann
Copy link
Author

gevann commented Apr 10, 2018

Yes I did.

@gmacdougall
Copy link
Member

My main concern about this is that we're changing the public API for some of these key methods.

Could we user creator = nil as a default action, with deprecation warnings that maintain the current behaviour until the next major version release?

@gevann
Copy link
Author

gevann commented Apr 11, 2018

I see your point. I've removed the default user constant in this PR - what do you think about rather than using creator=nil that we use creator=<user> where <user> is the 'spree@example.com' user it used to be? That way nobody who wants the current behaviour will have to change anything but we can still remove that constant and stop depending on it?

@gmacdougall
Copy link
Member

Yeah. That's what I was thinking.

@gevann
Copy link
Author

gevann commented Apr 11, 2018

I'll make that change, thanks!

Graeme Nathan added 2 commits April 11, 2018 14:54
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'.
@gevann gevann force-pushed the remove-default-address-dependency branch from 4a33f3a to ebf0f66 Compare April 12, 2018 17:39
@@ -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)

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)

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)

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)

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)

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)

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)

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)

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.

@gevann gevann force-pushed the remove-default-address-dependency branch 2 times, most recently from 68961a4 to 6a274ae Compare April 12, 2018 20:30
@gevann
Copy link
Author

gevann commented Apr 12, 2018

I have run this locally and it passes for me with the same seed, with DB=postgres. Does anybody have any ideas of what I can poke in to here to replicate? Does this fail or pass for any of you?

@jhawthorn
Copy link
Contributor

I am getting the same deprecation errors locally, which are considered failures on CI

@gevann
Copy link
Author

gevann commented Apr 20, 2018

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.
@gevann gevann force-pushed the remove-default-address-dependency branch from 6a274ae to f7cd81e Compare April 20, 2018 22:18
@gevann
Copy link
Author

gevann commented Apr 20, 2018

Fixed. Thanks for the feedback!

Copy link
Member

@kennyadsl kennyadsl left a 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?

@gevann gevann changed the title Remove default address dependency [BLOCKED] Remove default address dependency May 16, 2018
@gevann
Copy link
Author

gevann commented May 16, 2018

@kennyadsl you are correct, thanks!

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.

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)
Copy link
Member

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)
Copy link
Member

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)
Copy link
Member

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)
Copy link
Member

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)
Copy link
Member

Choose a reason for hiding this comment

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

Ditto: Named argument

@jacobherrington
Copy link
Contributor

@gevann is this something you're still working on?

@kennyadsl
Copy link
Member

@jacobherrington I've opened #2802 to complete this one, I think we can close this.

@kennyadsl kennyadsl closed this Oct 1, 2018
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.

When a reimbursement is created, a store credit is not created only a store reimbursement credit.
7 participants