我理解user和user_id之间的区别(一个引用了id的用法),但我不明白为什么我在rails中进行集成测试的教程使用:user_id用于测试登录和重定向,以及:用户用于测试注销和重定向。
以下是两者的代码:
require 'test_helper'
class UserStoriesTest < ActionDispatch::IntegrationTest
test "should login user and redirect" do
get login_path
assert_response :success
assert_template 'new'
post session_path, email: 'myemail@email.com', password:
'secret'
assert_response :redirect
assert_redirected_to root_path
follow_redirect!
assert_response :success
assert_template 'index'
assert session[:user_id]
end
test "should logout user and redirect" do
get logout_path
assert_response :redirect
assert_redirected_to root_path
assert_nil session[:user]
follow_redirect!
assert_template 'index'
end
end