Skip to content
croaky edited this page Sep 13, 2010 · 12 revisions

Modules

Clearance works by mixing behavior into tests, controllers, and models. For any file that you do not want to overwrite, include the corresponding Clearance module. They are namespaced exactly like the directory structure of a Rails app.

Application controller example:

class ApplicationController < ActionController::Base include Clearance::App::Controllers::ApplicationController end

User model example:

class User < ActiveRecord::Base include Clearance::App::Models::User end

User test example:

class UserTest < Test::Unit::TestCase include Clearance::Test::Unit::UserTest end

The migration

The generator will also create a migration to add a “users” table and run it. If the table already exists in the database, the migration will just add fields and indexes that are missing and required by Clearance. If the migration fails, the generator will revert all changes back.

Routes

Clearance will add these routes to your routes.rb:

map.resources :users, :has_one => [:password, :confirmation] map.resource :session map.resources :passwords

Please note that Clearance depends on root_url, so please make sure that it is defined to something in your config/routes.rb:

map.root :controller => ‘home’

Please note that Clearance depends on root_url, so please make sure that it is defined to something in your config/routes.rb:

map.root :controller => ‘users’, :action => ‘new’

Environments

You need to define HOST constant in your environments files. In config/environments/test.rb and config/environments/development.rb it can be:

HOST = “localhost”

While in config/environments/production.rb it must be the actual host your application is deployed to because the constant is used by mailers to generate URLs in emails.

In config/environment.rb:

DO_NOT_REPLY = “[email protected]

The flash

You will need to display the success, failure, and notice flash messages in your layout. We recommend creating an app/layouts/_flashes.html.erb partial similar to the _flashes partial in Suspenders:

<div id="flash">
  <% flash.each do |key, value| -%>
    <div id="flash_<%= key -%>"><%= html_escape(value) %></div>
  <% end -%>
</div>

which is then rendered inside the body tag of your application layout:

<%= render :partial => ‘layouts/flashes’ -%>

Tests

The tests use Shoulda >= 2.9.1 and Factory Girl >= 1.2.0.

The generator will create a user factory in test/factories/clearance.rb unless
you have it defined somewhere else.