On Dec 16, 11:27 am, byrnejb <
byrn...@harte-lyne.ca> wrote:
> I am trying to write a short-form login/logout step that works with
> Authlogic (2.1.6) and I cannot seem to discover how to get this to
> work. Has anyone here managed to do this successfully?
I think that I have figured out the secret decoder ring.
For Cucumber testing one must place somewhere in a file in the
features/support directory:
require 'authlogic/test_case'
Then one must first invoke the activate_authlogic_method or visit a
controller. The simplest thing to do is to place the activate call
inside a Before block in a Cucumber step definition file:
Before do
activate_authlogic
end
Then the UserSession.find returns a session object if one exists and
nil otherwise. If a session exists then the #record method can be
used to examine the user. So UserSession.find.record => user.instance
if UserSession.find; Otherwise it fails since nil has no such
method. I evidently had tripped over some conflict with instance
variables in my initial implementation and that completely confused
me.
With this information then the following is possible:
Then /user named "(.*)" is authenticated/ do |login|
user = User.find_by_login!( login )
UserSession.create!( user )
end
Then /user is not authenticated/ do
UserSession.find.destroy
end