Clearance
Simple, complete Ruby web app authentication.
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|- … config.gem “dancroak-clearance”, :lib => ‘clearance’, :source => ‘http://gems.github.com/’ end
Then:
rake gems:install rake gems:unpackSchema
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::ModelControllers
In app/controllers/application_controller.rb:
include Clearance::ApplicationControllerIn app/controllers/sessions_controller.rb:
include Clearance::SessionsControllerIn app/controllers/users_controller.rb:
include Clearance::UsersControllerRoutes
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 :sessionTests
The tests use Shoulda and Factory Girl.
In test/test_helper.rb:
include Clearance::TestHelperIn test/unit/user_test.rb:
include Clearance::UserTestIn test/functional/sessions_controller_test.rb:
include Clearance::SessionsControllerTestIn test/functional/users_controller_test.rb:
include Clearance::UsersControllerTestAuthors
- thoughtbot, inc.
- Dan Croak
- Josh Nichols
- Mike Breen