Assistance in writing tests using bootcamp/google_sign_in

13 views
Skip to first unread message

David McDonald

unread,
Dec 10, 2018, 6:19:19 AM12/10/18
to Ruby on Rails: Talk
I'm currently writing a small app trying to understand "tests" better.  More specifically testing the authentication of my little app.  Right now I've set it up with the bootcamp/google_sign_in gem. Everything works correctly in my application, but when I go to write the test for it I'm unsure how since I'm expecting a 3rd party to provide information.  Is this where I would mock the return object from google and proceed the lookup from my fixtures user file?  I'm unsure this is the approach that should be taken.  If anyone could give me more insight into how to properly do this it would be greatly appreciated. Thanks!

Hasan Diwan

unread,
Dec 11, 2018, 1:12:56 PM12/11/18
to rubyonra...@googlegroups.com
David,
You test only functionality provided by YOU. You don't necessarily need to test upstream functionality. For example, in an app I recently wrote, I needed to provide the time of intersection between two curves and used a library to provide the (maybe complex) maths for the intersection. Rightly or wrongly, I would rely on the upstream developers to make sure the maths are accurate and just test that if curve A and curve B intersect, a time is provided. Also, if there isn't an intersection, a sentinel is returned. --  H

On Mon, 10 Dec 2018 at 03:19, David McDonald <dave...@gmail.com> wrote:
I'm currently writing a small app trying to understand "tests" better.  More specifically testing the authentication of my little app.  Right now I've set it up with the bootcamp/google_sign_in gem. Everything works correctly in my application, but when I go to write the test for it I'm unsure how since I'm expecting a 3rd party to provide information.  Is this where I would mock the return object from google and proceed the lookup from my fixtures user file?  I'm unsure this is the approach that should be taken.  If anyone could give me more insight into how to properly do this it would be greatly appreciated. Thanks!

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/0fa542c8-2187-4f4c-a344-3d746c98a66d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
If you wish to request my time, please do so using bit.ly/hd1AppointmentRequest.
Si vous voudrais faire connnaisance, allez a bit.ly/hd1AppointmentRequest.

Sent from my mobile device
Envoye de mon portable

David McDonald

unread,
Dec 13, 2018, 6:48:11 AM12/13/18
to Ruby on Rails: Talk
Thanks for you reply!  I guess my thought process was to check authentication on my site in the following way.  And I saw this as something that I should be testing and not the developers of the google_sign_in gem.

Test:

1. Test that when an admin user clicks on the "Sign in with Google" link, that person is then redirected to an "admin page".
2. Test that when a site visitor clicks on the "Sign in with Google" link, that person is then redirected to the root_path.

If I'm correct in testing these two options... How do I test the "Sign in with Google" link where I send Google information and then receive their authentication object back?  Perhaps Google supplies a "fake" login for developers to use?  I couldn't find it if so.

Walter Lee Davis

unread,
Dec 13, 2018, 7:58:54 AM12/13/18
to rubyonra...@googlegroups.com

> On Dec 13, 2018, at 6:48 AM, David McDonald <dave...@gmail.com> wrote:
>
> Thanks for you reply! I guess my thought process was to check authentication on my site in the following way. And I saw this as something that I should be testing and not the developers of the google_sign_in gem.
>
> Test:
>
> 1. Test that when an admin user clicks on the "Sign in with Google" link, that person is then redirected to an "admin page".
> 2. Test that when a site visitor clicks on the "Sign in with Google" link, that person is then redirected to the root_path.
>
> If I'm correct in testing these two options... How do I test the "Sign in with Google" link where I send Google information and then receive their authentication object back? Perhaps Google supplies a "fake" login for developers to use? I couldn't find it if so.

Usually what you have to do in these cases is mock the reply from Google, and check that your app responds correctly when there's a Yes or No answer. But honestly, the gem that you are using should have its own tests that cover this. Your app should be testing whether it does whatever it is supposed to do.

Walter

>
>
> On Tuesday, December 11, 2018 at 1:12:56 PM UTC-5, hasan...@gmail.com wrote:
> David,
> You test only functionality provided by YOU. You don't necessarily need to test upstream functionality. For example, in an app I recently wrote, I needed to provide the time of intersection between two curves and used a library to provide the (maybe complex) maths for the intersection. Rightly or wrongly, I would rely on the upstream developers to make sure the maths are accurate and just test that if curve A and curve B intersect, a time is provided. Also, if there isn't an intersection, a sentinel is returned. -- H
>
>
> On Mon, 10 Dec 2018 at 03:19, David McDonald <dave...@gmail.com> wrote:
> I'm currently writing a small app trying to understand "tests" better. More specifically testing the authentication of my little app. Right now I've set it up with the bootcamp/google_sign_in gem. Everything works correctly in my application, but when I go to write the test for it I'm unsure how since I'm expecting a 3rd party to provide information. Is this where I would mock the return object from google and proceed the lookup from my fixtures user file? I'm unsure this is the approach that should be taken. If anyone could give me more insight into how to properly do this it would be greatly appreciated. Thanks!
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/0fa542c8-2187-4f4c-a344-3d746c98a66d%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> OpenPGP: https://sks-keyservers.net/pks/lookup?op=get&search=0xFEBAD7FFD041BBA1
> If you wish to request my time, please do so using bit.ly/hd1AppointmentRequest.
> Si vous voudrais faire connnaisance, allez a bit.ly/hd1AppointmentRequest.
>
> Sent from my mobile device
> Envoye de mon portable
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/f2f8b434-345d-489b-a16d-74712e477b82%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages