我有一个使用 devise_token_auth 的 rails API 应用程序,在我的测试(minitest)中,我需要发送 POST 请求并登录用户,所以我使用了该sign_in
方法,但它似乎没有做任何事情。
这是我的测试文件
require 'test_helper'
class ActivityControllerTest < ActionDispatch::IntegrationTest
include Devise::Test::IntegrationHelpers
test "post activity" do
sign_in users('one')
post '/activity/', params: {
original_activity_log_file: fixture_file_upload('files/test_gpx.gpx', 'application/gpx'),
title: 'test activity',
description: 'test description'
}
assert_response 200
end
end
这是运行时的结果
Expected response to be a <200: OK>, but was a <401: Unauthorized>
Response body: {"errors":["You need to sign in or sign up before continuing."]}.
Expected: 200
Actual: 401
这里可能发生什么导致测试失败?