current_user is nil when integrating RailsAdmin and Clearance

Hi there,

I’ve been trying to get Clearance and RailsAdmin working together, and in particular, I’m following this blog post from thoughtbot. Everything goes as the blog post describes until I get to the step about setting up the RailsAdmin initializer. Prior to this step, one of the two feature specs was passing, but once I create the initializer with the code provided, both tests fail. (The blog post indicates that they should both pass.)

The problem (which I admit sounds like something simple) is that when the initializer calls .admin? on current_user, it raises an error indicating that current_user is nil.

I’m not very familiar with either Clearance or RailsAdmin, and despite some digging around, I’ve not been able to determine what could be causing this.

So here’s some code:

If someone could point me in the right direction here I would be grateful. Also, if someone could provide a link to a sample Rails 4 app that integrates Clearance and RailsAdmin, that would be very helpful.

Thank you!

I think I’ve found the problem. As I was going through the Clearance documentation this morning, I realized that the Clearance::Backdoor feature is not enabled by default. Once I added this to config/environments/test.rb, everything worked as expected.

IMHO, this bit could be made clearer in the blog post. The post mentions the fact that Clearance::Backdoor is being used, but it is implied that this is just matter-of-fact. It does not say that this needs to be configured explicitly. After finding the fix, I went back to reexamine the blog post and noticed the comment by Daniel Hanson explaining how to add the needed config.

Also of note is that the link from the blog post to the relevant section in Clearance’s README about Clearance::Backdoor is broken. The post links to https://github.com/thoughtbot/clearance#faster-tests when in fact the correct URL is https://github.com/thoughtbot/clearance#fast-feature-specs.

In summary, thanks for Clearance and the blog post. Very cool. Rewording the blog post would make it better still.

Hey! Thanks for posting this. Sorry I am just seeing it now. I authored the post on Clearance + RailsAdmin.

You are 100% right - Clearance::Backdoor needs to be enabled (is not enabled by default).

Not sure what the policy is for updating older blog posts, but I will look into it.

Glad you found the post helpful. :smile:

1 Like