Integration testing with Cucumber and AuthLogic x-post to Cucumber

65 views
Skip to first unread message

byrnejb

unread,
Dec 16, 2010, 11:27:09 AM12/16/10
to Authlogic
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 have tried this:

Before do
activate_authlogic
end

When /user named "(.*)" logs in/ do |login|
user = User.find_by_username( login.downcase )
@local_user_session = UserSession.create!( user )
puts( @local_user_session )
end

gives this:
#<UserSession: {:unauthorized_record=>"<protected>"}>

But this user session object does not seem to match what I get from
user_session_controller#create
#<UserSession:
{:password=>"<protected>", :username=>#<ActiveSupport::Multibyte::Chars:
0x2ac27e7afec0 @wrapped_string="myuser">}>

Destroying the UserSession gives the same result as the create
#<UserSession: {:unauthorized_record=>"<protected>"}>

I then changed to the alternate syntax and used the create! method.
This indicates the root of the problem:

user = User.find_by_username!( name.hll_normalise )
puts( user.username )
@current_user_session = UserSession.create!(
:login => user.username,
:password => user.username + "-password",
:remember_me => true )

gives:

tester
Your session is invalid and has the following errors: Username
cannot be blank (Authlogic::Session::Existence::SessionInvalidError)
./features/app/models/users/step_definitions/
user_authentication_steps.rb:175:in `/user named "(.*)" is
authenticated/'
features/app/models/users/user_authentication.feature:59:in `And
the user named "tester" is authenticated'

Is AuthLogic still actively supported? I do not see any activity on
the GitHub repository since the beginning of September and the issues
list seems to be getting little attention as well. If it has been
abandoned then which fork are people moving to?


byrnejb

unread,
Dec 16, 2010, 1:11:36 PM12/16/10
to Authlogic
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



Reply all
Reply to author
Forward
0 new messages