public
Rubygem
Description: Rails authentication with email & password.
Homepage: http://thoughtbot.com
Clone URL: git://github.com/thoughtbot/clearance.git
qrush (author)
Thu Jul 09 11:51:52 -0700 2009
commit  03406c07039697032677679e7c40b17d5d7f961e
tree    2491a880de79d74b0227239b537df37a611ce53a
parent  df4afe9791464bb3c6fec6e0f3c461f3e79407ee
name age message
file .gitignore Tue Apr 21 14:44:50 -0700 2009 Updating gemspec for 0.6.0 [qrush]
file CHANGELOG.textile Sat Jul 04 16:35:08 -0700 2009 bumping the gem to 0.6.9. [dancroak]
file LICENSE Tue Nov 04 08:33:14 -0800 2008 Add license [mike-burns]
file README.textile Thu Jul 09 11:51:52 -0700 2009 Making sure the readme has the latest gem version [qrush]
file Rakefile Sat Jul 04 16:35:08 -0700 2009 bumping the gem to 0.6.9. [dancroak]
file TODO.textile Mon Mar 30 06:40:37 -0700 2009 updating todo list [dancroak]
directory app/ Sun Jun 07 08:35:19 -0700 2009 deprecated sign_user_in. telling developers to ... [dancroak]
file clearance.gemspec Sat Jul 04 16:35:08 -0700 2009 bumping the gem to 0.6.9. [dancroak]
directory config/ Sat Jun 13 17:08:54 -0700 2009 adding sign_up, sign_in, sign_out named routes [dancroak]
directory generators/ Sat Jul 04 16:30:14 -0700 2009 added timestamps to create users migration [dancroak]
directory lib/ Wed Jun 24 19:30:01 -0700 2009 Added defined? checks for various Rails constan... [dancroak]
directory rails/ Sat Sep 06 13:51:36 -0700 2008 Added test stuff. [technicalpickles]
directory shoulda_macros/ Sat Jun 06 19:43:05 -0700 2009 [#24] should_be_signed_in_as shouldn't look in ... [dancroak]
directory test/ Tue Jun 30 14:10:47 -0700 2009 Making sure Clearance is happy with 1.9 Signed... [Jason Morrison]

Clearance

Rails authentication with email & password.

We have clearance, Clarence.

Wiki

Most information regarding Clearance is on the Github Wiki.

Installation

Clearance is a Rails engine. It works with versions of Rails greater than 2.3.

In config/environment.rb:

config.gem "thoughtbot-clearance", 
  :lib     => 'clearance', 
  :source  => 'http://gems.github.com', 
  :version => '0.6.9'

Vendor the gem:

rake gems:install
rake gems:unpack

Make sure the development database exists and run the generator:

script/generate clearance

A number of files will be created and instructions will be printed.

You may already have some of these files. Don’t worry. You’ll be asked if you want to overwrite them.

Run the migration:

rake db:migrate

Define a HOST constant in your environment files. In config/environments/test.rb and config/environments/development.rb it can be:

HOST = "localhost"

In production.rb it must be the actual host your application is deployed to. The constant is used by mailers to generate URLs in emails.

In config/environment.rb:

DO_NOT_REPLY = "donotreply@example.com"

Define root_url to something in your config/routes.rb:

map.root :controller => 'home'

Cucumber Features

As your app evolves, you want to know that authentication still works. Clearance’s opinion is that you should test its integration with your app using Cucumber.

In config/environments/test.rb:

config.gem 'webrat',
  :version => '= 0.4.4'
config.gem 'cucumber',
  :version => '= 0.3.0'
config.gem 'thoughtbot-factory_girl',
  :lib     => 'factory_girl',
  :source  => "http://gems.github.com", 
  :version => '1.2.1'

Vendor the gems:

rake gems:install RAILS_ENV=test
rake gems:unpack  RAILS_ENV=test

We don’t vendor nokogiri due to its native extensions, so install it normally on your machine:

sudo gem install nokogiri

Run the Cucumber generator (if you haven’t already) and Clearance’s feature generator:

script/generate cucumber
script/generate clearance_features

All of the files generated should be new with the exception of the features/support/paths.rb file. If you have not modified your paths.rb then you will be okay to replace it with this one. If you need to keep your paths.rb file then add these locations in your paths.rb manually:

def path_to(page_name)
  case page_name
   ...
  when /the sign up page/i
   new_user_path
  when /the sign in page/i
   new_session_path
  when /the password reset request page/i
   new_password_path
  ...
end

Authors

Clearance was extracted out of Hoptoad. We merged the authentication code from two of thoughtbot’s clients’ Rails apps and have since used it each time we need authentication. The following people have improved the library. Thank you!

Dan Croak, Mike Burns, Jason Morrison, Joe Ferris, Eugene Bolshakov, Nick Quaranto, Josh Nichols, Mike Breen, Marcel Görner, Bence Nagy, Ben Mabey, Eloy Duran, Tim Pope, Mihai Anca, Mark Cornick, Shay Arnett, Joshua Clayton & Mustafa Ekim.

Questions?

Ask the mailing list

Suggestions, Bugs, Refactoring?

Fork away and create a Github Issue. Please don’t send pull requests.