comopasta Gr
2009-Nov-11 11:41 UTC
Render :action and routes problem with cucumber scenario
Hi, I have a cucumber scenario to verify what happens when an user account is not active yet. In that situation it will display an error and keep the user in the same login screen. The scenario includes: ... And I press "Login" Then I should be on the login page And I should see "Your account has not been activated yet." ... ------------- In routes.rb I have: map.login ''/login'', :controller => ''user_sessions'', :action => ''new'' ------------- In paths.rb I have: when /the login page/ login_path ------------- In user_sessions_controller.rb I have: if !@user.active? @show_div = true @error_note = "Your account has not been activated yet!" @user_session = UserSession.new render :action => :new else ------------- In new.html.erb a hidden div meant to show the errors: <div id="error_div" style="visibility: <%= @show_div ? ''visible'' : ''hidden'' %>"> <%= @error_note %> </div> ------------- My problem is that cucumber test fails with this: And I press "Login" Then I should be on the login page expected: "/login", got: "/user_session" (using ==) Which makes sense because paths.rb say one thing and render :action say something else. But I like to use the render :action so I can easily activate the error message for the user. What would be the best approach to solve this problem? The thing works but not the cucumber test. Thanks. -- Posted via http://www.ruby-forum.com/.
comopasta Gr
2009-Nov-11 21:22 UTC
Re: Render :action and routes problem with cucumber scenario
Hi, this is how I fixed it. Not sure if it is the best way but cucumber passes and the "real" application also behaves as expected. Scenario: ... And I press "Login" Then I must be on the login page <--- this won''t use the webrat default step And I should see "Your account has not been activated yet." ... Then I have define a step where I actually tell the expected route: Then /^I must be on (.+)$/ do |page_name| URI.parse(current_url).path.should == "/user_session" end Cheers. -- Posted via http://www.ruby-forum.com/.