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

refactor #determine_order_user helper method #590

Merged
merged 1 commit into from
Dec 17, 2015

Conversation

gvaughn
Copy link
Contributor

@gvaughn gvaughn commented Dec 16, 2015

There's no behavior change to this. It allows subclasses to easily override how to determine the user.

Bonobos has a particular use case where one of our employees is guiding a customer through the creation of an order (and potentially user account too). We don't want the employee to be automatically found as current_api_user and this is a clean way to provide that hook.

@jhawthorn
Copy link
Contributor

Seems fine to me 👍

Does it make sense to pass in parameters to determine_order_user? order_params is already available on the controller class. Seems like it would be simpler to use that directly.

@gvaughn
Copy link
Contributor Author

gvaughn commented Dec 16, 2015

@jhawthorn Yeah, I wasn't sure about the parameters parameter. I noticed that order_params and normalize_params performs some logic, so maybe it's just premature optimization to avoid running those multiple times. I'm open to changing this if you believe it would make the code clearer to read.

@magnusvk
Copy link
Contributor

If we intend to allow for overriding this we should mark the method as // @api public so we know not to change it without deprecation warnings. Otherwise 👍 on this.

@gvaughn
Copy link
Contributor Author

gvaughn commented Dec 16, 2015

Thanks @magnusvk I wasn't aware of that convention. The comment is added now.

@magnusvk
Copy link
Contributor

👍 from me. @jhawthorn are you ok with leaving the parameters as an argument or would you prefer that being pulled out?

@jhawthorn
Copy link
Contributor

Yes, I would prefer it changed. If we're concerned about the time it takes to calculate order_params (I am not) we can memoize the method itself at a later date.

@gvaughn
Copy link
Contributor Author

gvaughn commented Dec 16, 2015

@jhawthorn Updated per your request

@jhawthorn
Copy link
Contributor

Great 👍

@@ -116,6 +109,15 @@ def normalize_params
params[:order][:bill_address_attributes] = params[:order].delete(:bill_address) if params[:order][:bill_address].present?
end

# @api public
def determine_order_user
if order_params[:user_id]
Copy link
Contributor

Choose a reason for hiding this comment

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

I tend to add #present? incase the param is an empty string like if order_params[:user_id] = ''.

There's no behavior change to this. It allows subclasses
to easily override how to determine the user.
@gvaughn
Copy link
Contributor Author

gvaughn commented Dec 17, 2015

@BenMorganIO I added the #present? call

@magnusvk Would you have time this morning to merge this?

@magnusvk
Copy link
Contributor

👍

magnusvk added a commit that referenced this pull request Dec 17, 2015
refactor #determine_order_user helper method
@magnusvk magnusvk merged commit ed358ad into solidusio:master Dec 17, 2015
@gvaughn gvaughn deleted the determine_order_user_hook branch December 17, 2015 19:00
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.

4 participants