Rails版本3.0.4和Ruby 1.9.2
我正在使用设计gem,并设置了我的应用程序,以便用户必须登录才能执行任何操作。在编写我的功能测试时,我发现所有的测试都犯了同样的错误。
`method_missing': undefined method `new_user_session_path'
这很奇怪,如果我rake routes
我可以看到
new_user_session GET /devise/login(.:format) {:action=>"new", :controller=>"devise/sessions"}
我还可以确认,当我运行应用程序时,所有link_to
在使用该路径时都有效。
对于某个控制器的测试,我是否需要做一些特别的事情来查看其他路线?
的routes.rb
Nge::Application.routes.draw do
resources :companies
resources :users
devise_for :users, :path => "devise", :path_names => { :sign_in => 'login', :sign_out => 'logout', :password => 'secret', :confirmation => 'verification', :unlock => 'unblock', :registration => 'register', :sign_up => 'cmon_let_me_in' }
...
end
测试/功能/ companies_controller_test.rb
require 'test_helper'
class CompaniesControllerTest < ActionController::TestCase
context "When a user is NOT signed in" do
[:index, :new].each do |action|
context "and GET ##{action.to_s}" do
setup {get action}
should set_the_flash.to(/must sign-up/)
should redirect_to(new_user_session_path)
end
end
...
end
end
答案 0 :(得分:1)
答案 1 :(得分:0)
您可以尝试重新排序路线,以便设计路线是第一个吗?
所以routes.rb文件看起来像这样 -
Nge::Application.routes.draw do
resources :companies
devise_for :users, :path => "devise", :path_names => { :sign_in => 'login', :sign_out => 'logout', :password => 'secret', :confirmation => 'verification', :unlock => 'unblock', :registration => 'register', :sign_up => 'cmon_let_me_in' }
resources :users
...
end