Using OmniAuth (with omniauth_crowd), I'd like user to be redirected back to the login page if he doesn't submit right username and password. It works fine in production, but I have annoying problem testing it.
To mock OmniAuth provider, I use the following code, as recommended by the author of OmniAuth plugin:
OmniAuth.config.test_mode = true
OmniAuth.config.mock_auth[:someProvider] = :invalid_credentials
visit_page @page
The code above automatically (i.e. without entering username and password) redirects Capybara to the session#failure
. My session#failure
redirects to the login_path
.
Thus I end up in a loop:
redirected more than 5 times, check for infinite redirects. (Capybara::InfiniteRedirectError)
What is the best workaround for my case?
I had a simular issue with Omniauth.
Not sure if there is a workaround, since it is the way OmniAuth.config.mock_auth
works.
My solution was to use fakeweb
instead of the OmniAuth mocking.
You should probably start off by looking at how omniauth_crowd is tested itself.
Here is a good example:
https://github.com/robdimarco/omniauth_crowd/blob/master/spec/omniauth/strategies/crowd_spec.rb#L49-69
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With