sorcery icon indicating copy to clipboard operation
sorcery copied to clipboard

🐛 Fix return value of #add_provider_to_user on User instance

Open mtomov opened this issue 4 years ago • 3 comments

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:

    https://github.com/Sorcery/sorcery/blob/c30cefa751c364ee20b361eb63a766f782b69e5e/spec/rails_app/app/controllers/sorcery_controller.rb#L447-L452

mtomov avatar Feb 26 '20 23:02 mtomov

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:

https://github.com/Sorcery/sorcery/blob/c30cefa751c364ee20b361eb63a766f782b69e5e/spec/rails_app/app/controllers/sorcery_controller.rb#L448-L452

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.

mtomov avatar Feb 28 '20 00:02 mtomov

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!

mladenilic avatar Mar 04 '20 22:03 mladenilic

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!

mtomov avatar Apr 02 '20 16:04 mtomov