Skip to content
This repository
Browse code

convert to a rails 3 engines, routes, etc.

  • Loading branch information...
commit c347cd2c05c0db07301f5a4bb217ef0c98b0c844 1 parent 395b589
Chad Pytel authored
1  .gitignore
@@ -4,5 +4,6 @@ test/rails_root/log/*.log
4 4 *.swp
5 5 .rake_tasks
6 6 test/rails_root/*
  7 +test/rails3_root
7 8 !test/rails_root/vendor/gems/justinfrench-formtastic-0.2.1
8 9 *.gem
7 Rakefile
@@ -9,7 +9,7 @@ namespace :test do
9 9 "generator:clearance"]) do |task|
10 10 task.libs << "lib"
11 11 task.libs << "test"
12   - task.pattern = "test/**/user_test.rb"
  12 + task.pattern = "test/**/*_test.rb"
13 13 task.verbose = false
14 14 end
15 15
@@ -55,13 +55,12 @@ namespace :generator do
55 55 FileUtils.mkdir_p("test/rails3_root/vendor/plugins")
56 56 clearance_root = File.expand_path(File.dirname(__FILE__))
57 57 system("ln -s #{clearance_root} test/rails3_root/vendor/plugins/clearance")
  58 + FileUtils.rm_rf("test/rails3_root/features")
58 59 end
59 60
60 61 desc "Run the clearance generator"
61 62 task :clearance do
62   - clearance_command = "cd test/rails3_root && ./script/rails generate clearance && rake db:migrate db:test:prepare"
63   - p clearance_command
64   - system clearance_command
  63 + system "cd test/rails3_root && ./script/rails generate clearance && rake db:migrate db:test:prepare"
65 64 end
66 65
67 66 desc "Run the clearance features generator"
30 config/routes.rb
... ... @@ -0,0 +1,30 @@
  1 +Rails.application.routes.draw do |map|
  2 + map.resources :passwords,
  3 + :controller => 'clearance/passwords',
  4 + :only => [:new, :create]
  5 +
  6 + map.resource :session,
  7 + :controller => 'clearance/sessions',
  8 + :only => [:new, :create, :destroy]
  9 +
  10 + map.resources :users, :controller => 'clearance/users' do |users|
  11 + users.resource :password,
  12 + :controller => 'clearance/passwords',
  13 + :only => [:create, :edit, :update]
  14 +
  15 + users.resource :confirmation,
  16 + :controller => 'clearance/confirmations',
  17 + :only => [:new, :create]
  18 + end
  19 +
  20 + map.sign_up 'sign_up',
  21 + :controller => 'clearance/users',
  22 + :action => 'new'
  23 + map.sign_in 'sign_in',
  24 + :controller => 'clearance/sessions',
  25 + :action => 'new'
  26 + map.sign_out 'sign_out',
  27 + :controller => 'clearance/sessions',
  28 + :action => 'destroy',
  29 + :method => :delete
  30 +end
3  lib/clearance.rb
@@ -2,6 +2,7 @@
2 2 require 'clearance/extensions/rescue'
3 3
4 4 require 'clearance/configuration'
5   -require 'clearance/routes'
6 5 require 'clearance/authentication'
7 6 require 'clearance/user'
  7 +
  8 +require 'clearance/engine'
8 lib/clearance/engine.rb
... ... @@ -0,0 +1,8 @@
  1 +require "clearance"
  2 +require "rails"
  3 +
  4 +module Clearance
  5 + class Engine < Rails::Engine
  6 + engine_name :clearance
  7 + end
  8 +end
49 lib/clearance/routes.rb
... ... @@ -1,49 +0,0 @@
1   -module Clearance
2   - class Routes
3   -
4   - # In your application's config/routes.rb, draw Clearance's routes:
5   - #
6   - # @example
7   - # map.resources :posts
8   - # Clearance::Routes.draw(map)
9   - #
10   - # If you need to override a Clearance route, invoke your app route
11   - # earlier in the file so Rails' router short-circuits when it finds
12   - # your route:
13   - #
14   - # @example
15   - # map.resources :users, :only => [:new, :create]
16   - # Clearance::Routes.draw(map)
17   - def self.draw(map)
18   - map.resources :passwords,
19   - :controller => 'clearance/passwords',
20   - :only => [:new, :create]
21   -
22   - map.resource :session,
23   - :controller => 'clearance/sessions',
24   - :only => [:new, :create, :destroy]
25   -
26   - map.resources :users, :controller => 'clearance/users' do |users|
27   - users.resource :password,
28   - :controller => 'clearance/passwords',
29   - :only => [:create, :edit, :update]
30   -
31   - users.resource :confirmation,
32   - :controller => 'clearance/confirmations',
33   - :only => [:new, :create]
34   - end
35   -
36   - map.sign_up 'sign_up',
37   - :controller => 'clearance/users',
38   - :action => 'new'
39   - map.sign_in 'sign_in',
40   - :controller => 'clearance/sessions',
41   - :action => 'new'
42   - map.sign_out 'sign_out',
43   - :controller => 'clearance/sessions',
44   - :action => 'destroy',
45   - :method => :delete
46   - end
47   -
48   - end
49   -end
11 lib/rails/generators/clearance_features_generator.rb
... ... @@ -0,0 +1,11 @@
  1 +class ClearanceFeaturesGenerator < Rails::Generators::Base
  2 + desc "Put the clearance features in place"
  3 +
  4 + def self.source_root
  5 + @_clearance_source_root ||= File.expand_path("../../../../../../../../../generators/clearance_features/templates", __FILE__)
  6 + end
  7 +
  8 + def install
  9 + directory "features"
  10 + end
  11 +end
2  lib/rails/generators/clearance_generator.rb
@@ -25,8 +25,6 @@ def install
25 25 template "user.rb", user_model
26 26 end
27 27
28   - route "Clearance::Routes.draw(map)"
29   -
30 28 template "factories.rb", "test/factories/clearance.rb"
31 29
32 30 migration_template "migrations/#{migration_source_name}.rb",
3  test/rails3_root/config/routes.rb
... ... @@ -1,5 +1,6 @@
1 1 Rails3Root::Application.routes.draw do |map|
2   - Clearance::Routes.draw(map)
  2 + map.resource :account
  3 + map.root :controller => 'accounts', :action => 'edit'
3 4
4 5 # The priority is based upon order of creation:
5 6 # first created -> highest priority.
20 test/rails3_root/db/migrate/20100609194816_clearance_create_users.rb
... ... @@ -1,20 +0,0 @@
1   -class ClearanceCreateUsers < ActiveRecord::Migration
2   - def self.up
3   - create_table(:users) do |t|
4   - t.string :email
5   - t.string :encrypted_password, :limit => 128
6   - t.string :salt, :limit => 128
7   - t.string :confirmation_token, :limit => 128
8   - t.string :remember_token, :limit => 128
9   - t.boolean :email_confirmed, :default => false, :null => false
10   - t.timestamps
11   - end
12   -
13   - add_index :users, :email
14   - add_index :users, :remember_token
15   - end
16   -
17   - def self.down
18   - drop_table :users
19   - end
20   -end
2  test/rails3_root/db/schema.rb
@@ -9,7 +9,7 @@
9 9 #
10 10 # It's strongly recommended to check this file into your version control system.
11 11
12   -ActiveRecord::Schema.define(:version => 20100609194816) do
  12 +ActiveRecord::Schema.define(:version => 20100609202802) do
13 13
14 14 create_table "users", :force => true do |t|
15 15 t.string "email"

0 comments on commit c347cd2

Please sign in to comment.
Something went wrong with that request. Please try again.