在我的系统中,用户通过 rails 网站注册。我必须从用 ruby 编写的自定义应用程序服务器对用户进行身份验证。
错误信息:
You must activate the Authlogic::Session::Base.controller with a controller object before creating objects (Authlogic::Session::Activation::NotActivatedError)
来自:http ://rdoc.info/projects/binarylogic/authlogic
require "authlogic/test_case" # include at the top of test_helper.rb
setup :activate_authlogic # run before tests are executed
UserSession.create(users(:whomever)) # logs a user in
先试试这个:
Authlogic::Session::Base.controller = Authlogic::ControllerAdapters::RailsAdapter.new(self)
我使用来自 user239662 的答案的建议解决了这个错误(我不清楚,因此我发布了这个解决方案)。我的 Cucumber 步骤定义现在如下所示:
When /^I am logged in as "(.*)"$/ do |user|
@current_user = User.make!(:username => user)
require 'authlogic/test_case'
activate_authlogic
@current_session = UserSession.create!(@current_user)
end