Ruby on rails 如何使用Authlogic以编程方式登录用户?
我正在测试我的仪表板控制器,它需要用户登录才能访问。下面是我的代码 需要“测试助手”Ruby on rails 如何使用Authlogic以编程方式登录用户?,ruby-on-rails,authlogic,Ruby On Rails,Authlogic,我正在测试我的仪表板控制器,它需要用户登录才能访问。下面是我的代码 需要“测试助手” class DashboardControllerTest < ActionController::TestCase test "should redirect if not logged in" do get :index assert_response 302 end test "should get index if logged in" do user = User.
class DashboardControllerTest < ActionController::TestCase
test "should redirect if not logged in" do
get :index
assert_response 302
end
test "should get index if logged in" do
user = User.create(:username => "trivektor", :password => "abcd", :email => "trivektor@gmail.com", :first_name => "Tri", :last_name => "Vuong", :active => true)
user_session = UserSession.create(:email => "trivektor@gmail.com", :password => "abcd")
# get :index
# assert_response 200
end
end
类DashboardControllerTest请帮忙。谢谢。在创建新的用户会话之前,您需要激活authlogic,只需创建一个新的测试文件并添加以下内容:
class ActionController::TestCase
setup :activate_authlogic
end