2013-12-17 38 views
3

使用Capybara測試令牌認證的正確方法是什麼?下面是我:如果我沒有get :index通過Capybara向控制器傳遞GET參數

describe ApplicationController do 
    let!(:user) { create :user, authentication_token: 1 } 

    specify "token should work now" do 
    visit "/?auth_token=#{user.authentication_token}" 
    # get :index 
    response.should_not redirect_to(new_user_session_url) 
    end 

    specify "token shouldn't work in the future" do 
    Timecop.travel(2.weeks) 
    visit "/?auth_token=#{user.authentication_token}" 
    # get :index 
    response.should redirect_to(new_user_session_url) 
    Timecop.return 
    end 
end 

測試失敗。但是如果我註釋掉那條線,測試就會被保存下來,但是這不應該是正確的方法,因爲我已經在它上面有visit

我在做什麼錯?

+0

迴應來自get和visit返回一頁,如果我沒有記錯的話。我敢打賭,當你得到'index:'時,它會將其反應混淆了。 –

回答

3

事實證明visit不會將變量傳遞給控制器​​。將其更改爲get :index, auth_token: user.authentication_token解決了該問題。

相關問題