Ruby on Rails 2.3.8:功能测试:assert_redirect_to没有找到行动?

时间:2011-07-12 13:18:02

标签: ruby-on-rails routing functional-testing

这是错误:

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

这里是生成错误的函数(在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

我做控制器switiching,因为我需要能够从任何功能测试中调用此方法,因为整个应用程序需要首先登录...虽然我不确定我是否正确执行

我跑了rake路线,这里是相关的路线

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

1 个答案:

答案 0 :(得分:1)

assert_redirected_to :dashboard_account

或明确指定url

assert_redirected_to '/account/dashboard'