Interesting Things
All strategies that inherit from Devise::Strategies::Authenticatable (which may be all right now) check for user.active?. To deactivate a user, just add an active column to User model, and a message to present with inactive_message:
# User model def active? !!active end def inactive_message "Sorry, this account has been deactivated." end
and to test:
# Any session controller spec
it "should throw an error with an inactive user" do
user = Factory.create(:user, :password => "password")
user.active = false
user.save!
error = catch(:warden) do
post :create, :user => {:username => user.username, :password => "password"}
end
error[:message].should =~ /deactivated/
end
Hello, i’ve tried this and it doesn’t work for me. I’m using devise (2.1.2). Any suggestion?
February 8, 2013 at 12:38 am
Hey Alex, I’m seeing the same problem. It looks like Devise 2.1.2 uses “active_for_authentication?” See https://github.com/plataformatec/devise/blob/master/lib/devise/models/authenticatable.rb
April 3, 2013 at 2:44 pm