Problem with Authlogic and Unit/Functional Tests in Rails
Posted
by mmacaulay
on Stack Overflow
See other posts from Stack Overflow
or by mmacaulay
Published on 2010-04-14T01:24:18Z
Indexed on
2010/04/14
1:33 UTC
Read the original article
Hit count: 713
I'm learning how unit testing is done in Rails, and I've run into a problem involving Authlogic.
According to the Documentation there are a few things required to use Authlogic stuff in your tests:
test_helper.rb:
require "authlogic/test_case"
class ActiveSupport::TestCase
setup :activate_authlogic
end
Then in my functional tests I can login users:
UserSession.create(users(:tester))
The problem seems to stem from the setup :activate_authlogic
line in test_helper.rb, whenever that is included, I get the following errors when running functional tests:
NoMethodError: undefined method `request=' for nil:NilClass
authlogic (2.1.3) lib/authlogic/controller_adapters/abstract_adapter.rb:63:in `send'
authlogic (2.1.3) lib/authlogic/controller_adapters/abstract_adapter.rb:63:in `method_missing'
If I remove setup :activate_authlogic
and add instead Authlogic::Session::Base.controller = Authlogic::ControllerAdapters::RailsAdapter.new(self)
to test_helper.rb, my functional tests seem to work but now my unit tests fail:
NoMethodError: undefined method `params' for ActiveSupport::TestCase:Class
authlogic (2.1.3) lib/authlogic/controller_adapters/abstract_adapter.rb:30:in `params'
authlogic (2.1.3) lib/authlogic/session/params.rb:96:in `params_credentials'
authlogic (2.1.3) lib/authlogic/session/params.rb:72:in `params_enabled?'
authlogic (2.1.3) lib/authlogic/session/params.rb:66:in `persist_by_params'
authlogic (2.1.3) lib/authlogic/session/callbacks.rb:79:in `persist'
authlogic (2.1.3) lib/authlogic/session/persistence.rb:55:in `persisting?'
authlogic (2.1.3) lib/authlogic/session/persistence.rb:39:in `find'
authlogic (2.1.3) lib/authlogic/acts_as_authentic/session_maintenance.rb:96:in `get_session_information'
authlogic (2.1.3) lib/authlogic/acts_as_authentic/session_maintenance.rb:95:in `each'
authlogic (2.1.3) lib/authlogic/acts_as_authentic/session_maintenance.rb:95:in `get_session_information'
/test/unit/user_test.rb:23:in `test_should_save_user_with_email_password_and_confirmation'
What am I doing wrong?
© Stack Overflow or respective owner