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 return value of #add_provider_to_user on User instance #224

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mtomov
Copy link

@mtomov mtomov commented Feb 26, 2020

Hi, thank you for the great library! Using it with ease. Just noticed a small bug on the return value of #add_provider_to_user here:

https://github.com/Sorcery/sorcery/blob/master/lib/sorcery/model/submodules/external.rb#L99-L100

  • Before, the method would return an instance of Authentication,
    instead of the original intention to return an instance of the
    current user.

  • Arguably returning the the instance of the current user is not very useful,
    as it's already known 🤷‍♂, but at least it matches the current
    example here:

    if (@user = add_provider_to_user(provider))
    redirect_to 'bla', notice: 'Success!'
    else
    redirect_to 'blu', alert: 'Failed!'
    end

Copy link
Contributor

@mladenilic mladenilic left a comment

Choose a reason for hiding this comment

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

Hi @mtomov , thanks for the PR.

Can you please link the example you are referring to? As you said, it makes more sense to return the authentication instance.

lib/sorcery/model/submodules/external.rb Outdated Show resolved Hide resolved
@mtomov mtomov force-pushed the fix-add_provider_to_user-return-value branch from 3aefbaa to ac9fd85 Compare February 27, 2020 23:59
@mtomov
Copy link
Author

mtomov commented Feb 28, 2020

Thanks @mladenilic for looking over. I guess indeed you're right that there's only one place referring to the return value of the method being user instead of authentication:

if (@user = add_provider_to_user(provider))
redirect_to 'bla', notice: 'Success!'
else
redirect_to 'blu', alert: 'Failed!'
end

Happy to change the code back to return an authentication, adjust the tests, and change that example code line, etc.. if you think that's more sensible.

@mladenilic
Copy link
Contributor

It seems that the original intention was to return the user instance. However, I agree with you that returning authentication instance makes more sense.

I think we should revert back to returning authentication instance, but keep everything else (guard clause simplification and user -> authentication variable rename). Also, you can fix that spec (variable name is confusing).

Thanks!

  * `#add_provider_to_user` is returning an Authentication instance
    using a `user` variable name.

  * This commit changes the variable name to match the return type, i.e.
   `user` -> `authentication`

  * Similarly amend a confusing test example
@mtomov mtomov force-pushed the fix-add_provider_to_user-return-value branch from ac9fd85 to 48eeee9 Compare April 2, 2020 16:43
@mtomov
Copy link
Author

mtomov commented Apr 2, 2020

Thanks for your feedback @mladenilic . All amended as talked about. Let me know if you'd like me to change anything else. Will be happy to. Thanks!

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.

2 participants