Reputation: 31
I am new to capybara but I am trying to use it to test (with cucumber) an app I am converting from rails 2 to rails 3. However, I am getting strange behavior when testing log in. I have a cucumber login step that does the following:
visit login_path
fill_in 'Email', :with => '[email protected]'
fill_in 'Password', :with => 'XXXXXXXXX'
click_button 'Log in'
When this custom step runs cucumber gives me the following error:
The action 'index' could not be found for UserSessionsController
AbstractController::ActionNotFound)
And the log outputs the following:
Started GET "/login" for 127.0.0.1 at Fri May 06 15:48:42 -0400 2011
Processing by UserSessionsController#new as HTML
Redirected to https://www.example.com/login
Completed 302 Found in 1ms
Started GET "/login" for 127.0.0.1 at Fri May 06 15:48:42 -0400 2011
Processing by UserSessionsController#new as HTML
Rendered user_sessions/new.html.erb within layouts/promo (15.8ms)
Completed 200 OK in 38ms (Views: 24.5ms | ActiveRecord: 2.9ms)
Started POST "/user_sessions" for 127.0.0.1 at Fri May 06 15:48:42 -0400 2011
Processing by UserSessionsController#create as HTML
Parameters: {"commit"=>"Log in", "user_session"=>{"password"=>"[FILTERED]", "email"=>"[email protected]"}, "utf8"=>"✓"}
Redirected to https://www.example.com/user_sessions
Completed 302 Found in 1ms
Started GET "/user_sessions" for 127.0.0.1 at Fri May 06 15:48:42 -0400 2011
SQL (0.6ms) ROLLBACK
So here are my questions:
Why is the /login GET and then redirected to /login???
Why is the POST to /user_sessions also getting redirected to itself (which causes the error I see)???
Everything works perfectly fine in development and I see no 302 status codes. It may be something simple but I don't see it.
EDIT: 5 min after submitting this I realized it was the SSL_requirement plugin causing the redirects. When I comment out "ssl_required", the tests pass. I will have to do more research into Capybara to find out how to configure it unless someone comes up with an answer.
EDIT ANSWER (since it won't let me post one for 8 hours): I found the answer. As I stated in my edit, the issue is the redirection due to SSL requirement. A very good description of the problem can be found here: https://github.com/jnicklas/capybara/issues/85. The current solution is a patch which worked for me that can be found here: https://gist.github.com/466411.
Upvotes: 2
Views: 2210
Reputation: 31
I found the answer. As I stated in my edit, the issue is the redirection due to SSL requirement. A very good description of the problem can be found here: https://github.com/jnicklas/capybara/issues/85. The current solution is a patch which worked for me that can be found here: https://gist.github.com/466411.
Upvotes: 1