undefined method `authenticate?' for nil:NilClass when testing

2,478 views
Skip to first unread message

thoughtafter

unread,
Feb 12, 2011, 6:41:36 PM2/12/11
to Devise
I've been working to switch a rails app from authlogic to devise. The
app seems to work fine but the functional tests seem to completely
fail. Here is the error I'm seeing:

ActionView::TemplateError: undefined method `authenticate?' for
nil:NilClass

[SNIP]

devise (1.0.9) [v] lib/devise/controllers/helpers.rb:197:in
`user_signed_in?'
(eval):2:in `send'
(eval):2:in `user_signed_in?'

This corresponds to the following function which suggests that
"warden" is nil when testing:

def authenticate_#{mapping}!
warden.authenticate!(:scope => :#{mapping})
end

In test_helper I have:

class ActionController::TestCase
include Devise::TestHelpers
[SNIP]
end

This was run with ruby 1.8.7, rails 2.3.11, devise 1.0.9. Have I
missed something about how this is supposed to work?

José Valim

unread,
Feb 13, 2011, 10:10:52 AM2/13/11
to Devise

thoughtafter

unread,
Feb 13, 2011, 4:12:49 PM2/13/11
to Devise
Yes I have checked the wiki and searched this group for each of my
problems prior to submitting questions. I had read that article as
I've now read everything related to testing. Given that article is
about RSpec Devise 1.1, and Rails 3, none of which I am using in this
project, I did not expect it to have any useful information. However,
upon reading it and looking over the code again I realized something.
In the article it mentions the "devise.mapping" env variable in the
request. Some of my controller tests were still using the archaic
setup function that look like this:

def setup
@controller = SomeController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
end

I realized that setting the request variable in such a manner might
screw up Devise as it would be lacking the correct env variables. So
I removed the setup method entirely and retested and this problem was
resolved. So that's something for people to be aware of when
migrating old codebases to devise.


On Feb 13, 7:10 am, José Valim <jose.va...@gmail.com> wrote:
> Have you checked the wiki? Particularly this article?
>
> https://github.com/plataformatec/devise/wiki/How-To:-Controllers-and-...)
Reply all
Reply to author
Forward
0 new messages