这是我设计的控制器:
class UsersController < ApplicationController
before_action :authenticate_user!, only: [:mypage]
和路线:
get "/mypage", to: "users#mypage"
现在,我要测试登录和注销。我的测试是:
class RorIntegrationTest < ActionDispatch::IntegrationTest
include Devise::Test::IntegrationHelpers
test "sign_in then sign_out" do
get "/mypage"
user = users(:someuser)
assert_response :redirect
sign_in(user)
get "/mypage"
assert_response :success
sign_out(user)
get "/mypage"
assert_response :redirect # this is line 17
end
但结果是:
Failure:
RorIntegrationTest#test_sign_in_then_sign_out [/ror/test/integration/ror_integration_test.rb:17]:
Expected response to be a <3XX: redirect>, but was a <200: OK>
bin/rails test test/integration/ror_integration_test.rb:6
似乎第一个get "/mypage"
已正确重定向,但是为什么第二个sign_out
之后未重定向?