使用Devise进行Rspec控制器测试无法测试重定向

时间:2019-01-29 20:21:59

标签: ruby-on-rails rspec devise

我只是想测试一个:user未在签订,将会被重定向到new_user_session_path,当他们试图访问的东西,他们不能。

当我打电话时:

describe "GET new" do 
    it 'expects redirect unless admin' do
        get :new
        expect(response).to redirect_to(new_user_session_path)
    end
end

我收到以下错误:

1) MealsController GET new expects redirect unless admin
     Failure/Error: redirect_to new_user_session_path, alert: "You must be signed in to access this page."

     NameError:
       undefined local variable or method `new_user_session_path' for #<MealsController:0x007fa066d5d230>
       Did you mean?  new_user_invitation_path

为什么会这样?

编辑:这是我的用户路线:

new_user_session GET    /users/sign_in(.:format)                                                                 sessions#new
              user_session POST   /users/sign_in(.:format)                                                                 sessions#create
      destroy_user_session DELETE /users/sign_out(.:format)                                                                sessions#destroy
         new_user_password GET    /users/password/new(.:format)                                                            devise/passwords#new
        edit_user_password GET    /users/password/edit(.:format)                                                           devise/passwords#edit
             user_password PATCH  /users/password(.:format)                                                                devise/passwords#update
                           PUT    /users/password(.:format)                                                                devise/passwords#update
                           POST   /users/password(.:format)                                                                devise/passwords#create
    accept_user_invitation GET    /users/invitation/accept(.:format)                                                       devise/invitations#edit
    remove_user_invitation GET    /users/invitation/remove(.:format)                                                       devise/invitations#destroy
       new_user_invitation GET    /users/invitation/new(.:format)                                                          devise/invitations#new
           user_invitation PATCH  /users/invitation(.:format)                                                              devise/invitations#update
                           PUT    /users/invitation(.:format)                                                              devise/invitations#update
                           POST   /users/invitation(.:format)                                                              devise/invitations#create
    edit_user_registration GET    /users/edit(.:format)                                                                    devise/registrations#edit
         user_registration PUT    /users(.:format)                                                                         devise/registrations#update

0 个答案:

没有答案