设计sign_out在测试中不起作用-sign_out之后仍可以访问,没有重定向

时间:2019-03-26 01:33:40

标签: ruby-on-rails devise ruby-on-rails-5

这是我设计的控制器:

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之后未重定向?

0 个答案:

没有答案