Search code examples
ruby-on-railsroutesfunctional-testing

Ruby on Rails 2.3.8: Functional Testing: assert_redirect_to not finding action?


Here is zhe error:

NoMethodError: undefined method `dashboard_url' for #<AccountsController:0x105212680 @real_format=nil>

and here is the function which generates the error (on the assert_redirected_to :dashboard line

def login_as_owner(login = SharedTest.user.login, password = SharedTest.user.password)
  old_controller = @controller
  @controller = SessionsController.new
  post(:create, :login => login, :password => password)
  @controller = AccountsController.new 
  assert_redirected_to :dashboard
  @controller = old_controller

end

I do controller switiching, because I need to be able to call this method from any of the functional tests, as the entire app requires being logged in first... though I'm not sure if I'm doing it right.

I ran rake routes, and here are the related routes

               root        /                              {:controller=>"accounts", :action=>"dashboard"}
  dashboard_account GET    /account/dashboard(.:format)   {:controller=>"accounts", :action=>"dashboard"}

Solution

  • try

    assert_redirected_to :dashboard_account
    

    or explicitly specifying url

    assert_redirected_to '/account/dashboard'