thoughtbot-clearance 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/README.textile +8 -16
  2. data/Rakefile +12 -10
  3. data/TODO.textile +7 -4
  4. data/generators/clearance/templates/app/controllers/application.rb +1 -1
  5. data/generators/clearance/templates/app/controllers/confirmations_controller.rb +1 -1
  6. data/generators/clearance/templates/app/controllers/passwords_controller.rb +1 -1
  7. data/generators/clearance/templates/app/controllers/sessions_controller.rb +1 -1
  8. data/generators/clearance/templates/app/controllers/users_controller.rb +1 -1
  9. data/generators/clearance/templates/app/models/user.rb +1 -1
  10. data/generators/clearance/templates/app/models/user_mailer.rb +1 -1
  11. data/generators/clearance/templates/test/functional/confirmations_controller_test.rb +1 -1
  12. data/generators/clearance/templates/test/functional/passwords_controller_test.rb +1 -1
  13. data/generators/clearance/templates/test/functional/sessions_controller_test.rb +1 -1
  14. data/generators/clearance/templates/test/functional/users_controller_test.rb +1 -1
  15. data/generators/clearance/templates/test/unit/user_mailer_test.rb +1 -1
  16. data/generators/clearance/templates/test/unit/user_test.rb +1 -1
  17. data/lib/clearance.rb +6 -6
  18. data/lib/clearance/app/controllers/application_controller.rb +58 -54
  19. data/lib/clearance/app/controllers/confirmations_controller.rb +30 -26
  20. data/lib/clearance/app/controllers/passwords_controller.rb +48 -44
  21. data/lib/clearance/app/controllers/sessions_controller.rb +61 -56
  22. data/lib/clearance/app/controllers/users_controller.rb +32 -28
  23. data/lib/clearance/app/models/user.rb +58 -56
  24. data/lib/clearance/app/models/user_mailer.rb +21 -18
  25. data/lib/clearance/test/test_helper.rb +66 -64
  26. data/lib/clearance/version.rb +2 -2
  27. data/test/rails_root/app/controllers/application.rb +1 -1
  28. data/test/rails_root/app/controllers/confirmations_controller.rb +1 -1
  29. data/test/rails_root/app/controllers/passwords_controller.rb +1 -1
  30. data/test/rails_root/app/controllers/sessions_controller.rb +1 -1
  31. data/test/rails_root/app/controllers/users_controller.rb +1 -1
  32. data/test/rails_root/app/models/user.rb +1 -1
  33. data/test/rails_root/app/models/user_mailer.rb +1 -1
  34. data/test/rails_root/test/functional/confirmations_controller_test.rb +1 -1
  35. data/test/rails_root/test/functional/passwords_controller_test.rb +1 -1
  36. data/test/rails_root/test/functional/sessions_controller_test.rb +1 -1
  37. data/test/rails_root/test/functional/users_controller_test.rb +1 -1
  38. data/test/rails_root/test/test_helper.rb +1 -1
  39. data/test/rails_root/test/unit/user_mailer_test.rb +1 -1
  40. data/test/rails_root/test/unit/user_test.rb +1 -1
  41. metadata +34 -10
  42. data/lib/clearance/test/functionals/confirmations_controller_test.rb +0 -81
  43. data/lib/clearance/test/functionals/passwords_controller_test.rb +0 -188
  44. data/lib/clearance/test/functionals/sessions_controller_test.rb +0 -91
  45. data/lib/clearance/test/functionals/users_controller_test.rb +0 -60
  46. data/lib/clearance/test/units/user_mailer_test.rb +0 -34
  47. data/lib/clearance/test/units/user_test.rb +0 -203
data/README.textile CHANGED
@@ -50,15 +50,10 @@ This will create:
50
50
  test/unit/user_mailer_test.rb
51
51
  test/unit/user_test.rb
52
52
 
53
- If you already have some of these files created, the generator will:
54
-
55
- # NOT overwrite your files
56
- # print out instructions to include Clearance modules in those files manually
57
-
58
53
  For example:
59
54
 
60
55
  app/models/user.rb already exists. Add this line to it:
61
- include Clearance::Models::User
56
+ include Clearance::App::Models::User
62
57
 
63
58
  h2. Tests
64
59
 
@@ -79,7 +74,7 @@ In test/test_helper.rb:
79
74
  class Test::Unit::TestCase
80
75
  self.use_transactional_fixtures = true
81
76
  self.use_instantiated_fixtures = false
82
- include Clearance::TestHelper
77
+ include Clearance::Test::TestHelper
83
78
  end
84
79
 
85
80
  h2. Controllers
@@ -89,7 +84,7 @@ In app/controllers/application_controller.rb:
89
84
  class ApplicationController < ActionController::Base
90
85
  helper :all
91
86
  protect_from_forgery
92
- include Clearance::ApplicationController
87
+ include Clearance::App::Controllers::ApplicationController
93
88
  end
94
89
 
95
90
  h2. Migration
@@ -112,14 +107,11 @@ h2. Routes
112
107
  ActionController::Routing::Routes.draw do |map|
113
108
 
114
109
  map.resources :users
115
- map.resource :session
116
-
117
- map.resources :users, :has_one => :password
118
- map.resources :users, :has_one => :confirmation
119
-
120
- map.resources :passwords
121
-
122
- map.root :controller => 'sessions', :action => 'new'
110
+ map.resource :session
111
+ map.resources :users, :has_one => :password
112
+ map.resources :users, :has_one => :confirmation
113
+ map.resources :passwords
114
+ map.root :controller => 'sessions', :action => 'new'
123
115
 
124
116
  end
125
117
 
data/Rakefile CHANGED
@@ -1,23 +1,18 @@
1
1
  require 'rake'
2
2
  require 'rake/testtask'
3
3
  require 'date'
4
- require 'lib/clearance/version'
5
- begin
6
- require 'jeweler'
7
- rescue LoadError
8
- end
9
-
4
+
10
5
  test_files_pattern = 'test/rails_root/test/{unit,functional,other}/**/*_test.rb'
11
6
  Rake::TestTask.new do |t|
12
7
  t.libs << 'lib'
13
8
  t.pattern = test_files_pattern
14
9
  t.verbose = false
15
10
  end
16
-
11
+
17
12
  desc "Run the test suite"
18
13
  task :default => :test
19
-
20
- Jeweler.gemspec = Gem::Specification.new do |s|
14
+
15
+ spec = Gem::Specification.new do |s|
21
16
  s.name = "clearance"
22
17
  s.summary = "Simple, complete Rails authentication."
23
18
  s.email = "dcroak@thoughtbot.com"
@@ -27,6 +22,13 @@ Jeweler.gemspec = Gem::Specification.new do |s|
27
22
  s.files = FileList["[A-Z]*", "{generators,lib,test}/**/*"]
28
23
  end
29
24
 
25
+ begin
26
+ require 'jeweler'
27
+ Jeweler.gemspec = spec
28
+ rescue LoadError
29
+ puts "Jeweler not available. sudo gem install technicalpickles-jeweler --source=http://gems.github.com"
30
+ end
31
+
30
32
  namespace :generator do
31
33
  task :templates do
32
34
  app_files = FileList["test/rails_root/app/{controllers,models,views}/**/*"]
@@ -52,4 +54,4 @@ namespace :generator do
52
54
  end
53
55
  end
54
56
  end
55
- end
57
+ end
data/TODO.textile CHANGED
@@ -1,14 +1,17 @@
1
- (this is in order of highest priority first)
1
+ (highest priority first)
2
2
 
3
- # force email confirmation by default
4
- # sessions controller test is missing some tests
3
+ # activation code instead of salt?
4
+ # users#show doesn't exist, but confirmations create redirects there
5
+ # sessions controller test is missing remember_me tests
5
6
  # mailers should not hardcode example.com as from address
7
+ # should_have_form should be pulled into shoulda
8
+ # generator should print out instructions to include modules existing files
6
9
  # check to make sure attr_accessible doesn't override and w/ attr_protected
7
10
  # move shoulda macros in test_helper to shoulda_macros folder
8
11
  # add shoulda and factory girl dependencies to gemspec
9
12
  # refactor Mailer default_url_options[:host] to something cleaner
10
13
 
11
- ideas stolen from merb-auth:
14
+ ideas to steal from merb-auth:
12
15
 
13
16
  # store current_user on the session, not controller
14
17
  # respond with 401 Unauthorized when request requires authentication
@@ -1,5 +1,5 @@
1
1
  class ApplicationController < ActionController::Base
2
2
  helper :all
3
3
  protect_from_forgery
4
- include Clearance::ApplicationController
4
+ include Clearance::App::Controllers::ApplicationController
5
5
  end
@@ -1,3 +1,3 @@
1
1
  class ConfirmationsController < ApplicationController
2
- include Clearance::ConfirmationsController
2
+ include Clearance::App::Controllers::ConfirmationsController
3
3
  end
@@ -1,3 +1,3 @@
1
1
  class PasswordsController < ApplicationController
2
- include Clearance::PasswordsController
2
+ include Clearance::App::Controllers::PasswordsController
3
3
  end
@@ -1,3 +1,3 @@
1
1
  class SessionsController < ApplicationController
2
- include Clearance::SessionsController
2
+ include Clearance::App::Controllers::SessionsController
3
3
  end
@@ -1,3 +1,3 @@
1
1
  class UsersController < ApplicationController
2
- include Clearance::UsersController
2
+ include Clearance::App::Controllers::UsersController
3
3
  end
@@ -1,3 +1,3 @@
1
1
  class User < ActiveRecord::Base
2
- include Clearance::Models::User
2
+ include Clearance::App::Models::User
3
3
  end
@@ -2,6 +2,6 @@ class UserMailer < ActionMailer::Base
2
2
 
3
3
  default_url_options[:host] = HOST
4
4
 
5
- include Clearance::Mailers::User
5
+ include Clearance::App::Models::UserMailer
6
6
 
7
7
  end
@@ -1,5 +1,5 @@
1
1
  require File.dirname(__FILE__) + '/../test_helper'
2
2
 
3
3
  class ConfirmationsControllerTest < ActionController::TestCase
4
- include Clearance::ConfirmationsControllerTest
4
+ include Clearance::Test::Functional::ConfirmationsControllerTest
5
5
  end
@@ -1,5 +1,5 @@
1
1
  require File.dirname(__FILE__) + '/../test_helper'
2
2
 
3
3
  class PasswordsControllerTest < ActionController::TestCase
4
- include Clearance::PasswordsControllerTest
4
+ include Clearance::Test::Functional::PasswordsControllerTest
5
5
  end
@@ -1,5 +1,5 @@
1
1
  require File.dirname(__FILE__) + '/../test_helper'
2
2
 
3
3
  class SessionsControllerTest < ActionController::TestCase
4
- include Clearance::SessionsControllerTest
4
+ include Clearance::Test::Functional::SessionsControllerTest
5
5
  end
@@ -1,5 +1,5 @@
1
1
  require File.dirname(__FILE__) + '/../test_helper'
2
2
 
3
3
  class UsersControllerTest < ActionController::TestCase
4
- include Clearance::UsersControllerTest
4
+ include Clearance::Test::Functional::UsersControllerTest
5
5
  end
@@ -2,5 +2,5 @@ require File.dirname(__FILE__) + '/../test_helper'
2
2
 
3
3
  class UserMailerTest < ActionMailer::TestCase
4
4
  tests UserMailer
5
- include Clearance::UserMailerTest
5
+ include Clearance::Test::Unit::UserMailerTest
6
6
  end
@@ -1,5 +1,5 @@
1
1
  require File.dirname(__FILE__) + '/../test_helper'
2
2
 
3
3
  class UserTest < Test::Unit::TestCase
4
- include Clearance::UserTest
4
+ include Clearance::Test::Unit::UserTest
5
5
  end
data/lib/clearance.rb CHANGED
@@ -5,11 +5,11 @@ require 'clearance/app/controllers/sessions_controller'
5
5
  require 'clearance/app/controllers/users_controller'
6
6
  require 'clearance/app/models/user'
7
7
  require 'clearance/app/models/user_mailer'
8
- require 'clearance/test/functionals/confirmations_controller_test'
9
- require 'clearance/test/functionals/sessions_controller_test'
10
- require 'clearance/test/functionals/users_controller_test'
11
- require 'clearance/test/functionals/passwords_controller_test'
8
+ require 'clearance/test/functional/confirmations_controller_test'
9
+ require 'clearance/test/functional/sessions_controller_test'
10
+ require 'clearance/test/functional/users_controller_test'
11
+ require 'clearance/test/functional/passwords_controller_test'
12
12
  require 'clearance/test/test_helper'
13
- require 'clearance/test/units/user_test'
14
- require 'clearance/test/units/user_mailer_test'
13
+ require 'clearance/test/unit/user_test'
14
+ require 'clearance/test/unit/user_mailer_test'
15
15
  require 'clearance/version'
@@ -1,73 +1,77 @@
1
1
  module Clearance
2
- module ApplicationController
2
+ module App
3
+ module Controllers
4
+ module ApplicationController
3
5
 
4
- def self.included(base)
5
- base.class_eval do
6
- helper_method :current_user
7
- helper_method :logged_in?
6
+ def self.included(base)
7
+ base.class_eval do
8
+ helper_method :current_user
9
+ helper_method :logged_in?
8
10
 
9
- include InstanceMethods
11
+ include InstanceMethods
10
12
 
11
- protected
12
- include ProtectedInstanceMethods
13
- end
14
- end
13
+ protected
14
+ include ProtectedInstanceMethods
15
+ end
16
+ end
15
17
 
16
- module InstanceMethods
17
- def current_user
18
- @current_user ||= (user_from_session || user_from_cookie)
19
- end
18
+ module InstanceMethods
19
+ def current_user
20
+ @current_user ||= (user_from_session || user_from_cookie)
21
+ end
20
22
 
21
- def logged_in?
22
- ! current_user.nil?
23
- end
24
- end
23
+ def logged_in?
24
+ ! current_user.nil?
25
+ end
26
+ end
25
27
 
26
- module ProtectedInstanceMethods
27
- def authenticate
28
- deny_access unless self.current_user
29
- end
28
+ module ProtectedInstanceMethods
29
+ def authenticate
30
+ deny_access unless self.current_user
31
+ end
30
32
 
31
- def user_from_session
32
- user_model.find_by_id session[:user_id]
33
- end
33
+ def user_from_session
34
+ user_model.find_by_id session[:user_id]
35
+ end
34
36
 
35
- def user_from_cookie
36
- user = user_model.find_by_remember_token(cookies[:auth_token]) if cookies[:auth_token]
37
- user && user.remember_token? ? user : nil
38
- end
37
+ def user_from_cookie
38
+ user = user_model.find_by_remember_token(cookies[:auth_token]) if cookies[:auth_token]
39
+ user && user.remember_token? ? user : nil
40
+ end
39
41
 
40
- def login(user)
41
- create_session_for(user)
42
- @current_user = user
43
- end
42
+ def login(user)
43
+ create_session_for(user)
44
+ @current_user = user
45
+ end
44
46
 
45
- def create_session_for(user)
46
- session[:user_id] = user.id if user
47
- end
47
+ def create_session_for(user)
48
+ session[:user_id] = user.id if user
49
+ end
48
50
 
49
- def redirect_back_or(default)
50
- session[:return_to] ? redirect_to(session[:return_to]) : redirect_to(default)
51
- session[:return_to] = nil
52
- end
51
+ def redirect_back_or(default)
52
+ session[:return_to] ? redirect_to(session[:return_to]) : redirect_to(default)
53
+ session[:return_to] = nil
54
+ end
53
55
 
54
- def redirect_to_root
55
- redirect_to root_url
56
- end
56
+ def redirect_to_root
57
+ redirect_to root_url
58
+ end
57
59
 
58
- def store_location
59
- session[:return_to] = request.request_uri
60
- end
60
+ def store_location
61
+ session[:return_to] = request.request_uri
62
+ end
61
63
 
62
- def deny_access(flash_message = nil, opts = {})
63
- opts[:redirect] ||= new_session_url
64
- store_location
65
- flash[:error] = flash_message if flash_message
66
- redirect_to opts[:redirect]
67
- end
64
+ def deny_access(flash_message = nil, opts = {})
65
+ opts[:redirect] ||= new_session_url
66
+ store_location
67
+ flash[:error] = flash_message if flash_message
68
+ redirect_to opts[:redirect]
69
+ end
68
70
 
69
- def user_model
70
- User
71
+ def user_model
72
+ User
73
+ end
74
+ end
71
75
  end
72
76
  end
73
77
  end
@@ -1,38 +1,42 @@
1
1
  module Clearance
2
- module ConfirmationsController
2
+ module App
3
+ module Controllers
4
+ module ConfirmationsController
3
5
 
4
- def self.included(base)
5
- base.class_eval do
6
- before_filter :existing_user?, :only => [:new, :create]
6
+ def self.included(base)
7
+ base.class_eval do
8
+ before_filter :existing_user?, :only => [:new, :create]
7
9
 
8
- include InstanceMethods
10
+ include InstanceMethods
9
11
 
10
- private
11
- include PrivateInstanceMethods
12
- end
13
- end
12
+ private
13
+ include PrivateInstanceMethods
14
+ end
15
+ end
14
16
 
15
- module InstanceMethods
16
- def new
17
- @user = User.find_by_id_and_salt(params[:user_id], params[:salt])
18
- end
17
+ module InstanceMethods
18
+ def new
19
+ @user = User.find_by_id_and_salt(params[:user_id], params[:salt])
20
+ end
19
21
 
20
- def create
21
- @user = User.find_by_id_and_salt(params[:user_id], params[:salt])
22
- @user.confirm!
23
- session[:user_id] = @user.id
24
- redirect_to user_path(@user)
25
- end
26
- end
22
+ def create
23
+ @user = User.find_by_id_and_salt(params[:user_id], params[:salt])
24
+ @user.confirm!
25
+ session[:user_id] = @user.id
26
+ redirect_to user_path(@user)
27
+ end
28
+ end
27
29
 
28
- module PrivateInstanceMethods
29
- def existing_user?
30
- user = User.find_by_id_and_salt(params[:user_id], params[:salt])
31
- if user.nil?
32
- render :nothing => true, :status => :not_found
30
+ module PrivateInstanceMethods
31
+ def existing_user?
32
+ user = User.find_by_id_and_salt(params[:user_id], params[:salt])
33
+ if user.nil?
34
+ render :nothing => true, :status => :not_found
35
+ end
36
+ end
33
37
  end
38
+
34
39
  end
35
40
  end
36
-
37
41
  end
38
42
  end
@@ -1,57 +1,61 @@
1
1
  module Clearance
2
- module PasswordsController
2
+ module App
3
+ module Controllers
4
+ module PasswordsController
3
5
 
4
- def self.included(base)
5
- base.class_eval do
6
- before_filter :existing_user?, :only => [:edit, :update]
7
- filter_parameter_logging :password, :password_confirmation
8
- include InstanceMethods
9
- private
10
- include PrivateInstanceMethods
11
- end
12
- end
6
+ def self.included(base)
7
+ base.class_eval do
8
+ before_filter :existing_user?, :only => [:edit, :update]
9
+ filter_parameter_logging :password, :password_confirmation
10
+ include InstanceMethods
11
+ private
12
+ include PrivateInstanceMethods
13
+ end
14
+ end
13
15
 
14
- module InstanceMethods
15
- def new
16
- end
16
+ module InstanceMethods
17
+ def new
18
+ end
17
19
 
18
- def create
19
- user = User.find_by_email params[:password][:email]
20
- if user.nil?
21
- flash.now[:warning] = 'Unknown email'
22
- render :action => :new
23
- else
24
- UserMailer.deliver_change_password user
25
- redirect_to new_session_url
26
- end
27
- end
20
+ def create
21
+ user = User.find_by_email params[:password][:email]
22
+ if user.nil?
23
+ flash.now[:warning] = 'Unknown email'
24
+ render :action => :new
25
+ else
26
+ UserMailer.deliver_change_password user
27
+ redirect_to new_session_url
28
+ end
29
+ end
28
30
 
29
- def edit
30
- @user = User.find_by_email_and_crypted_password(params[:email],
31
- params[:password])
32
- end
31
+ def edit
32
+ @user = User.find_by_email_and_crypted_password(params[:email],
33
+ params[:password])
34
+ end
33
35
 
34
- def update
35
- @user = User.find_by_email_and_crypted_password(params[:email],
36
- params[:password])
37
- if @user.update_attributes params[:user]
38
- session[:user_id] = @user.id
39
- redirect_to @user
40
- else
41
- render :action => :edit
36
+ def update
37
+ @user = User.find_by_email_and_crypted_password(params[:email],
38
+ params[:password])
39
+ if @user.update_attributes params[:user]
40
+ session[:user_id] = @user.id
41
+ redirect_to @user
42
+ else
43
+ render :action => :edit
44
+ end
45
+ end
42
46
  end
43
- end
44
- end
45
47
 
46
- module PrivateInstanceMethods
47
- def existing_user?
48
- user = User.find_by_email_and_crypted_password(params[:email],
49
- params[:password])
50
- if user.nil?
51
- render :nothing => true, :status => :not_found
48
+ module PrivateInstanceMethods
49
+ def existing_user?
50
+ user = User.find_by_email_and_crypted_password(params[:email],
51
+ params[:password])
52
+ if user.nil?
53
+ render :nothing => true, :status => :not_found
54
+ end
55
+ end
52
56
  end
57
+
53
58
  end
54
59
  end
55
-
56
60
  end
57
61
  end