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
。
我在做什麼錯?
迴應來自get和visit返回一頁,如果我沒有記錯的話。我敢打賭,當你得到'index:'時,它會將其反應混淆了。 –