[rspec-users] Problem testing Authlogic UserSession

Martin Hawkins martin.hawkins at gmail.com
Mon Nov 15 17:36:50 EST 2010


I've posted this to the Authlogic group but things seem a little quiet, so
perhaps someone here can help:

'm testing Authlogic 2.1.6, running under Rails 3.0.1., using rspec
2.1.0

I have the following:
user.rb
class User < ActiveRecord::Base
  acts_as_authentic do |config|
    config.login_field :email
    config.ignore_blank_passwords false
    config.disable_perishable_token_maintenance true
  end
end

user_session.rb
class UserSession < Authlogic::Session::Base
end

user_sessions_controller_spec.rb
require 'spec_helper'

def user_session_create
  @user = Factory.create(:user)
  @user_session = UserSession.create(:email => @user.email, :password =>
@user.password)
end

describe UserSessionsController do
  before(:each) do
    :activate_authlogic
  end

  describe "create a user session" do
    it "creates a user session using the user credentials" do
      user_session_create
      @user_session.email.should == @user.email
    end
  end

  describe "find a user session" do
    it "locates the user session" do
      user_session_create
      us = UserSession.find
      us.email.should == @user.email
    end
  end
end

I have the correct lines in spec_helper.rb ( require "authlogic/test_case"
and include Authlogic::TestCase)
The create a user session test is ok but the find a user session test is
failing with
Failures:
  1) UserSessionsController find a user session locates the user session
     Failure/Error: us.email.should == @user.email
     expected: "ron2.weasley2 at hogworts.com",
          got: nil (using ==)

When I try this using console, I get the following
ruby-1.8.7-p302 > require "authlogic/test_case"
 => true
ruby-1.8.7-p302 > include Authlogic::TestCase
 => Object

ruby-1.8.7-p302 >ron = User.first

ruby-1.8.7-p302 > activate_authlogic
 => #<ApplicationController:0x105a06300
@view_context_class=nil, @_status=200, @action_has_layout=true,
@_headers={"Content- Type"=>"text/html"}>
ruby-1.8.7-p302 > us = UserSession.new(:email => ron.email, :password =>
ron.password)
 => #<UserSession:
{:password=>"<protected>", :email=>"ron1.weasley1 at hogworts.com"}>
ruby-1.8.7-p302 > us.save
NoMethodError: undefined method `remote_ip' for nil:NilClass from
/Users/martin/.rvm/gems/ruby-1.8.7-p302 at pta3/gems/
activesupport-3.0.1/lib/active_support/whiny_nil.rb:48:in `method_missing' from
/Users/martin/.rvm/gems/ruby-1.8.7-p302 at pta3/gems/
authlogic-2.1.6/lib/authlogic/session/magic_columns.rb:61:in `update_info' from
/Users/martin/.rvm/gems/ruby-1.8.7-p302 at pta3/gems/
activesupport-3.0.1/lib/active_support/callbacks.rb:414:in
`_run_before_save_callbacks' from
/Users/martin/.rvm/gems/ruby-1.8.7-p302 at pta3/gems/
activesupport-3.0.1/lib/active_support/callbacks.rb:93:in `send' from
/Users/martin/.rvm/gems/ruby-1.8.7-p302 at pta3/gems/
activesupport-3.0.1/lib/active_support/callbacks.rb:93:in `run_callbacks' from
/Users/martin/.rvm/gems/ruby-1.8.7-p302 at pta3/gems/
authlogic-2.1.6/lib/authlogic/session/callbacks.rb:83:in `before_save' from
/Users/martin/.rvm/gems/ruby-1.8.7-p302 at pta3/gems/
authlogic-2.1.6/lib/authlogic/session/existence.rb:68:in `save' from
(irb):9

I'm at a bit of a loss to explain this - any help very welcome!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20101115/a1d3be53/attachment.html>


More information about the rspec-users mailing list