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

Fix to not reuse spree_current_user as @user #131

Merged
merged 4 commits into from
Feb 1, 2019
Merged

Fix to not reuse spree_current_user as @user #131

merged 4 commits into from
Feb 1, 2019

Conversation

yono
Copy link
Contributor

@yono yono commented Nov 14, 2018

Original implementation @user ||= spree_current_user contaminates spree_current_user when failed to save @user.

It affects customized view like display spree_current_user.email.

So I fix to load new Spree::User instance.

@yono yono changed the title Don't reuse spree_current_user as @user Fix to not reuse spree_current_user as @user Nov 14, 2018
@yono yono closed this Dec 25, 2018
@yono yono deleted the improve_edit_user branch December 25, 2018 12:31
@jacobherrington
Copy link
Contributor

@yono Sorry we haven't had a chance to look at this, would you like to reopen it?

@yono yono restored the improve_edit_user branch December 26, 2018 06:33
@yono yono reopened this Dec 26, 2018
@yono
Copy link
Contributor Author

yono commented Dec 26, 2018

@jacobherrington

Thanks!
I'm sorry that my English isn't good.
Please let me know if you have any questions.

@spaghetticode
Copy link
Member

@yono 👏 thank you for this PR! Can you add a spec that verifies this fix? That would be great.

@yono
Copy link
Contributor Author

yono commented Jan 29, 2019

@spaghetticode Thank you for your review! I added a spec and rearranged specs.

@spaghetticode
Copy link
Member

@yono thank you for adding specs, I think that the code of this PR is now complete 🎉

One last thing, I think that commit messages for 3a420d and 2ddf9a should be improved. I think it's a good practice to explain why changes happen, otherwise future readers may struggle to find the reasoning behind these changes.

You can check our contributing guidelines for more details, there are a few links on how to write great commit messages.

Again, thank you for your time!

@yono
Copy link
Contributor Author

yono commented Jan 29, 2019

@spaghetticode I added body of commit message for 3353d58 and fad9001

Copy link
Member

@spaghetticode spaghetticode left a comment

Choose a reason for hiding this comment

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

@yono looks good to me thank you! 🎉 👍

@jacobherrington
Copy link
Contributor

@yono This looks good to me. One last thing, some changes have occurred in master, could you rebase with master?

yono added 4 commits January 31, 2019 23:56
Although `@user` and `spree_current_user` refer to the same record on the DB,
they must be kept two different Ruby objects in order to avoid annoyances when
the user update process fails.

For example, consider a custom user edit page that shows both the user email in
the header and the edit form allows email customization.

When submitting the form with an invalid email, this email will be redisplayed
both in the header and in the form.
When updating the user information, after `@user.save` succeeds, `spree_current_user`
information may be stale. For this reason the object must be reloaded in order
to get the updates from the DB.
Copy link
Contributor

@jacobherrington jacobherrington left a comment

Choose a reason for hiding this comment

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

Thanks @yono! 🖖

Copy link

@ericsaupe ericsaupe left a comment

Choose a reason for hiding this comment

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

Thanks!

@jacobherrington jacobherrington merged commit ddded44 into solidusio:master Feb 1, 2019
@yono yono deleted the improve_edit_user branch February 3, 2019 04:17
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