Clearance

Simple, complete Ruby web app authentication.

We have clearance, Clarence.

Features

  • email & password
  • modules, not a generator
  • gem, not a plugin
  • shoulda & factory_girl tests included

Gem installation (Rails 2.1+)

Specify the gem dependency in your config/environment.rb file:

Rails::Initializer.run do |config|
  1. … config.gem “dancroak-clearance”, :lib => ‘clearance’, :source => ‘http://gems.github.com/’ end

Then:

rake gems:install rake gems:unpack

Schema

Change your User model so it has these attributes.

change_table(:users) do |t| t.column :email, :string t.column :crypted_password, :string, :limit => 40 t.column :salt, :string, :limit => 40 t.column :remember_token, :string t.column :remember_token_expires_at, :datetime end add_index :users, [:email, :crypted_password]

User Model

In app/models/user.rb:

include Clearance::Model

Controllers

In app/controllers/application_controller.rb:

include Clearance::ApplicationController

In app/controllers/sessions_controller.rb:

include Clearance::SessionsController

In app/controllers/users_controller.rb:

include Clearance::UsersController

Routes

map.root # ‘/’, :controller => ‘sessions’, :action => ‘new’ map.with_options :controller => ‘sessions’ do |m| m.login ‘/login’, :action => ‘new’ m.logout ‘/logout’, :action => ‘destroy’ end map.resource :session

Tests

The tests use Shoulda and Factory Girl.

In test/test_helper.rb:

include Clearance::TestHelper

In test/unit/user_test.rb:

include Clearance::UserTest

In test/functional/sessions_controller_test.rb:

include Clearance::SessionsControllerTest

In test/functional/users_controller_test.rb:

include Clearance::UsersControllerTest

Authors

  • thoughtbot, inc.
  • Dan Croak
  • Josh Nichols
  • Mike Breen