Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

authlogic not working with capybara when using the selenium driver

I have all my capybara tests working with my authlogic members area using the default driver, but when i change one test to use selenium driver as it has ajax in it, it gives my theis error :

You must activate the Authlogic::Session::Base.controller with a controller object before creating objects

Things are working with default driver for authlogic so must be something to do with selenium ??

I have include Authlogic::TestCase in my spec_helper and

activate_authlogic
    domain.user_sessions.create(user)

in a before each.

Any one help me with this please ?

thanks rick

like image 909
rick Avatar asked Aug 04 '11 13:08

rick


2 Answers

I posted a cucumber solution here: Log-in through authlogic without having to fill in form every time

For RSpec integration tests it's similar.

In your spec_helper.rb:

require "authlogic/test_case"
RSpec.configure do |config|
  ...
  config.include Authlogic::TestCase
  ApplicationController.skip_before_filter :activate_authlogic
  config.before(:each, :type => :request) do
    activate_authlogic
    UserSession.create(User.find_by_email!(email))
  end
  ...
end

Obviously, if your site is not login only you may want to move the two lines in config.before into a before block in your specific test for logged in specs. If you leave as is you can delete the session with UserSession.find.destroy or obviously follow the logout link (if this makes more sense in your spec).

like image 93
PhilT Avatar answered Oct 14 '22 02:10

PhilT


I think the following code will work to activate authlogic:

Authlogic::Session::Base.controller = Authlogic::ControllerAdapters::RailsAdapter.new(self)

Having said that, I prefer defining a step that actually goes to the login form, fills it out, and logs in. It's slower, but I rarely run my entire integration test suite manually, usually the continuous integration server takes care of that.

like image 3
jcnnghm Avatar answered Oct 14 '22 02:10

jcnnghm