<commit_before>h1. Clearance

Simple, complete Ruby web app authentication. 

"We have clearance, Clarence.":http://www.youtube.com/v/mNRXJEE3Nz8

h2. Features

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

h2. 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:unpack

h2. 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]

h2. User Model

In app/models/user.rb:

  include Clearance::Model

h2. 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

h2. 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

h2. 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

h2. Authors

* thoughtbot, inc.
* <NAME>
* <NAME>
* <NAME><commit_msg>moving tests first in the README, adding information about User Factory<commit_after>h1. Clearance

Simple, complete Ruby web app authentication. 

"We have clearance, Clarence.":http://www.youtube.com/v/mNRXJEE3Nz8

h2. Features

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

h2. 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:unpack

h2. Tests

The tests use Shoulda and Factory Girl. You should create a User Factory:

  Factory.sequence :email do |n|
	  "<EMAIL>"
	end

	Factory.define :user do |user|
	  user.email { Factory.next :email }
	  user.password '<PASSWORD>'
	  user.password_confirmation '<PASSWORD>'
	end

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

h2. 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]

h2. User Model

In app/models/user.rb:

  include Clearance::Model

h2. 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

h2. 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

h2. Authors

* thoughtbot, inc.
* <NAME>
* <NAME>
* <NAME>
{'fraction_non_alphanumeric': 0.11290705966246732, 'fraction_numerical': 0.008081768481102924, 'mean_word_length': 3.859122401847575, 'pattern_counts': {'":': 2, '<': 12, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7340253', 'n_tokens_mistral': 1445, 'n_tokens_neox': 1366, 'n_words': 373}