-
-
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 part 2 #2802
Remove default address dependency part 2 #2802
Conversation
def perform! | ||
def perform!(created_by: nil) | ||
unless created_by | ||
created_by = Spree.user_class.where(email: '[email protected]').first |
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.
Use find_by
instead of where.first
.
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.
Done and squashed changes into 3f33fa199e889251c517a60c4ac98be958248b4c
8afe61d
to
381a522
Compare
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 like the consistency change from whodunnit
to created_by
. I don't really love the Spree.user_class.find_by(email: '[email protected]')
calls as I suspect nearly all production stores do not have that user but since it is within the deprecation call I think it's a good middle ground until it can be removed after the deprecation.
Thanks!
Without a user with email address equal to '[email protected]', 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 '[email protected]'.
Reimbursements only work if there is a user with the email address '[email protected]', 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.
This is done to keep the code language uniform, since at the end we are setting the store credit attribute (association with user) named created_by: https://github.com/solidusio/solidus/blob/826d9288684cf8f275bf04ac144b9b0ee84da1b6/core/app/models/spree/store_credit.rb#L24
whodunnit was basically doing the same thing. It's better to have the same argument name for every method that is using it.
This applies only to some deprecated blocks and does not change the new, working logic. This means that if those methods were used by some store or extension, they will now don't have the creator set instead of having a specific user that could even be not present in the database, causing the creator to be nil anyway.
381a522
to
05b6354
Compare
@ericsaupe @gmacdougall I've addressed the concern we talked about in the core team meeting. This should be fine now! |
Continuation of #2686
Closes #2930
This PR continues the work of @gevann removing hard-coded dependency of having a specific user in the database to perform a set of operations related to reimbursements.
@tvdeyen this basically seconds your comments on that PR, let me know if it's enough!
I've also deprecated
whodunnit
argument from some methods in favor of a more consistentcreated_by
.