thoughtbot-clearance 0.6.6 → 0.6.7

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.textile CHANGED
@@ -1,9 +1,21 @@
1
- h2. 0.6.6 (5/18/2009)
1
+ h2. 0.6.7 (06/13/2009)
2
+
3
+ * [#30] Added sign_up, sign_in, sign_out named routes. (Dan Croak)
4
+ * [#22] Minimizing Reek smell: Duplication in redirect_back_or. (Dan Croak)
5
+ * Deprecated sign_user_in. Told developers to use sign_in instead. (Dan
6
+ Croak)
7
+ * [#16] flash_success_after_create, flash_notice_after_create, flash_failure_after_create, flash_sucess_after_update, flash_success_after_destroy, etc. (Dan Croak)
8
+ * [#17] bug. added #create to forbidden before_filters on confirmations controller. (Dan Croak)
9
+ * [#24] should_be_signed_in_as shouldn't look in the session. (Dan Croak)
10
+ * README improvements. (Dan Croak)
11
+ * Move routes loading to separate file. (Joshua Clayton)
12
+
13
+ h2. 0.6.6 (05/18/2009)
2
14
 
3
15
  * [#14] replaced class_eval in Clearance::User with modules. This was needed
4
16
  in a thoughtbot client app so we could write our own validations. (Dan Croak)
5
17
 
6
- h2. 0.6.5 (5/17/2009)
18
+ h2. 0.6.5 (05/17/2009)
7
19
 
8
20
  * [#6] Make Clearance i18n aware. (Timur Vafin, Marcel Goerner, Eugene Bolshakov, Dan Croak)
9
21
 
data/README.textile CHANGED
@@ -8,7 +8,7 @@ h2. Wiki
8
8
 
9
9
  Most information regarding Clearance is on the "Github Wiki":http://wiki.github.com/thoughtbot/clearance.
10
10
 
11
- h2. Engine
11
+ h2. Installation
12
12
 
13
13
  Clearance is a Rails engine. It works with versions of Rails greater than 2.3.
14
14
 
@@ -18,7 +18,7 @@ In config/environment.rb:
18
18
  config.gem "thoughtbot-clearance",
19
19
  :lib => 'clearance',
20
20
  :source => 'http://gems.github.com',
21
- :version => '0.6.4'
21
+ :version => '0.6.6'
22
22
  </pre>
23
23
 
24
24
  Vendor the gem:
@@ -40,8 +40,6 @@ Run the migration:
40
40
 
41
41
  @rake db:migrate@
42
42
 
43
- h2. Environment
44
-
45
43
  Define a HOST constant in your environment files.
46
44
  In config/environments/test.rb and config/environments/development.rb it can be:
47
45
 
@@ -82,9 +80,9 @@ rake gems:install RAILS_ENV=test
82
80
  rake gems:unpack RAILS_ENV=test
83
81
  </pre>
84
82
 
85
- Don't vendor nokogiri (due to its native extensions):
83
+ We don't vendor nokogiri due to its native extensions, so install it normally on your machine:
86
84
 
87
- @rm -rf vendor/gems/nokogiri-1.2.3@
85
+ @sudo gem install nokogiri@
88
86
 
89
87
  Run the Cucumber generator (if you haven't already) and Clearance's feature generator:
90
88
 
@@ -111,9 +109,9 @@ end
111
109
 
112
110
  h2. Authors
113
111
 
114
- Clearance was extracted out of "Hoptoad":http://hoptoadapp.com. We merged the authentication code from two of thoughtbot's client's Rails apps and have since used it each time we need authentication. The following people have improved the library. Thank you!
112
+ Clearance was extracted out of "Hoptoad":http://hoptoadapp.com. 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!
115
113
 
116
- 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.
114
+ 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.
117
115
 
118
116
  h2. Questions?
119
117
 
data/Rakefile CHANGED
@@ -51,7 +51,7 @@ task :default => ['test:all', 'test:features']
51
51
 
52
52
  gem_spec = Gem::Specification.new do |gem_spec|
53
53
  gem_spec.name = "clearance"
54
- gem_spec.version = "0.6.6"
54
+ gem_spec.version = "0.6.7"
55
55
  gem_spec.summary = "Rails authentication with email & password."
56
56
  gem_spec.email = "support@thoughtbot.com"
57
57
  gem_spec.homepage = "http://github.com/thoughtbot/clearance"
@@ -71,3 +71,4 @@ task :gemspec do
71
71
  f.write gem_spec.to_yaml
72
72
  end
73
73
  end
74
+
@@ -1,9 +1,9 @@
1
1
  class Clearance::ConfirmationsController < ApplicationController
2
2
  unloadable
3
3
 
4
- before_filter :forbid_confirmed_user, :only => :new
5
- before_filter :forbid_missing_token, :only => :new
6
- before_filter :forbid_non_existent_user, :only => :new
4
+ before_filter :forbid_confirmed_user, :only => [:new, :create]
5
+ before_filter :forbid_missing_token, :only => [:new, :create]
6
+ before_filter :forbid_non_existent_user, :only => [:new, :create]
7
7
  filter_parameter_logging :token
8
8
 
9
9
  def new
@@ -14,11 +14,9 @@ class Clearance::ConfirmationsController < ApplicationController
14
14
  @user = ::User.find_by_id_and_token(params[:user_id], params[:token])
15
15
  @user.confirm_email!
16
16
 
17
- sign_user_in(@user)
18
- flash[:success] = translate(:confirmed_email,
19
- :scope => [:clearance, :controllers, :confirmations],
20
- :default => "Confirmed email and signed in.")
21
- redirect_to url_after_create
17
+ sign_in(@user)
18
+ flash_success_after_create
19
+ redirect_to(url_after_create)
22
20
  end
23
21
 
24
22
  private
@@ -42,6 +40,12 @@ class Clearance::ConfirmationsController < ApplicationController
42
40
  end
43
41
  end
44
42
 
43
+ def flash_success_after_create
44
+ flash[:success] = translate(:confirmed_email,
45
+ :scope => [:clearance, :controllers, :confirmations],
46
+ :default => "Confirmed email and signed in.")
47
+ end
48
+
45
49
  def url_after_create
46
50
  root_url
47
51
  end
@@ -13,15 +13,10 @@ class Clearance::PasswordsController < ApplicationController
13
13
  if user = ::User.find_by_email(params[:password][:email])
14
14
  user.forgot_password!
15
15
  ::ClearanceMailer.deliver_change_password user
16
- flash[:notice] = translate(:deliver_change_password,
17
- :scope => [:clearance, :controllers, :passwords],
18
- :default => "You will receive an email within the next few minutes. " <<
19
- "It contains instructions for changing your password.")
20
- redirect_to url_after_create
16
+ flash_notice_after_create
17
+ redirect_to(url_after_create)
21
18
  else
22
- flash.now[:failure] = translate(:unknown_email,
23
- :scope => [:clearance, :controllers, :passwords],
24
- :default => "Unknown email.")
19
+ flash_failure_after_create
25
20
  render :template => 'passwords/new'
26
21
  end
27
22
  end
@@ -36,10 +31,10 @@ class Clearance::PasswordsController < ApplicationController
36
31
 
37
32
  if @user.update_password(params[:user][:password],
38
33
  params[:user][:password_confirmation])
39
- @user.confirm_email! unless @user.email_confirmed?
40
- sign_user_in(@user)
41
- flash[:success] = translate(:signed_in, :default => "Signed in.")
42
- redirect_to url_after_update
34
+ @user.confirm_email!
35
+ sign_in(@user)
36
+ flash_success_after_update
37
+ redirect_to(url_after_update)
43
38
  else
44
39
  render :template => 'passwords/edit'
45
40
  end
@@ -59,10 +54,27 @@ class Clearance::PasswordsController < ApplicationController
59
54
  end
60
55
  end
61
56
 
57
+ def flash_notice_after_create
58
+ flash[:notice] = translate(:deliver_change_password,
59
+ :scope => [:clearance, :controllers, :passwords],
60
+ :default => "You will receive an email within the next few minutes. " <<
61
+ "It contains instructions for changing your password.")
62
+ end
63
+
64
+ def flash_failure_after_create
65
+ flash.now[:failure] = translate(:unknown_email,
66
+ :scope => [:clearance, :controllers, :passwords],
67
+ :default => "Unknown email.")
68
+ end
69
+
62
70
  def url_after_create
63
71
  new_session_url
64
72
  end
65
73
 
74
+ def flash_success_after_update
75
+ flash[:success] = translate(:signed_in, :default => "Signed in.")
76
+ end
77
+
66
78
  def url_after_update
67
79
  root_url
68
80
  end
@@ -10,40 +10,57 @@ class Clearance::SessionsController < ApplicationController
10
10
 
11
11
  def create
12
12
  @user = ::User.authenticate(params[:session][:email],
13
- params[:session][:password])
13
+ params[:session][:password])
14
14
  if @user.nil?
15
- flash.now[:failure] = translate(:bad_email_or_password,
16
- :scope => [:clearance, :controllers, :sessions],
17
- :default => "Bad email or password.")
15
+ flash_failure_after_create
18
16
  render :template => 'sessions/new', :status => :unauthorized
19
17
  else
20
18
  if @user.email_confirmed?
21
- sign_user_in(@user)
19
+ sign_in(@user)
22
20
  remember(@user) if remember?
23
- flash[:success] = translate(:signed_in, :default => "Signed in.")
24
- redirect_back_or url_after_create
21
+ flash_success_after_create
22
+ redirect_back_or(url_after_create)
25
23
  else
26
24
  ::ClearanceMailer.deliver_confirmation(@user)
27
- deny_access(translate(:unconfirmed_email,
28
- :scope => [:clearance, :controllers, :sessions],
29
- :default => "User has not confirmed email. " <<
30
- "Confirmation email will be resent."))
25
+ flash_notice_after_create
26
+ redirect_to(new_session_url)
31
27
  end
32
28
  end
33
29
  end
34
30
 
35
31
  def destroy
36
32
  forget(current_user)
37
- flash[:success] = translate(:signed_out, :default => "Signed out.")
38
- redirect_to url_after_destroy
33
+ flash_success_after_destroy
34
+ redirect_to(url_after_destroy)
39
35
  end
40
36
 
41
37
  private
42
38
 
39
+ def flash_failure_after_create
40
+ flash.now[:failure] = translate(:bad_email_or_password,
41
+ :scope => [:clearance, :controllers, :sessions],
42
+ :default => "Bad email or password.")
43
+ end
44
+
45
+ def flash_success_after_create
46
+ flash[:success] = translate(:signed_in, :default => "Signed in.")
47
+ end
48
+
49
+ def flash_notice_after_create
50
+ flash[:notice] = translate(:unconfirmed_email,
51
+ :scope => [:clearance, :controllers, :sessions],
52
+ :default => "User has not confirmed email. " <<
53
+ "Confirmation email will be resent.")
54
+ end
55
+
43
56
  def url_after_create
44
57
  root_url
45
58
  end
46
59
 
60
+ def flash_success_after_destroy
61
+ flash[:success] = translate(:signed_out, :default => "Signed out.")
62
+ end
63
+
47
64
  def url_after_destroy
48
65
  new_session_url
49
66
  end
@@ -13,11 +13,8 @@ class Clearance::UsersController < ApplicationController
13
13
  @user = ::User.new params[:user]
14
14
  if @user.save
15
15
  ::ClearanceMailer.deliver_confirmation @user
16
- flash[:notice] = translate(:deliver_confirmation,
17
- :scope => [:clearance, :controllers, :users],
18
- :default => "You will receive an email within the next few minutes. " <<
19
- "It contains instructions for confirming your account.")
20
- redirect_to url_after_create
16
+ flash_notice_after_create
17
+ redirect_to(url_after_create)
21
18
  else
22
19
  render :template => 'users/new'
23
20
  end
@@ -25,6 +22,13 @@ class Clearance::UsersController < ApplicationController
25
22
 
26
23
  private
27
24
 
25
+ def flash_notice_after_create
26
+ flash[:notice] = translate(:deliver_confirmation,
27
+ :scope => [:clearance, :controllers, :users],
28
+ :default => "You will receive an email within the next few minutes. " <<
29
+ "It contains instructions for confirming your account.")
30
+ end
31
+
28
32
  def url_after_create
29
33
  new_session_url
30
34
  end
@@ -1,19 +1,30 @@
1
1
  ActionController::Routing::Routes.draw do |map|
2
2
  map.resources :passwords,
3
3
  :controller => 'clearance/passwords',
4
- :only => [:new, :create]
4
+ :only => [:new, :create]
5
5
 
6
6
  map.resource :session,
7
7
  :controller => 'clearance/sessions',
8
- :only => [:new, :create, :destroy]
8
+ :only => [:new, :create, :destroy]
9
9
 
10
10
  map.resources :users, :controller => 'clearance/users' do |users|
11
11
  users.resource :password,
12
12
  :controller => 'clearance/passwords',
13
- :only => [:create, :edit, :update]
13
+ :only => [:create, :edit, :update]
14
14
 
15
15
  users.resource :confirmation,
16
16
  :controller => 'clearance/confirmations',
17
- :only => [:new, :create]
17
+ :only => [:new, :create]
18
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
19
30
  end
@@ -7,40 +7,6 @@ Rails::Generator::Commands::Base.class_eval do
7
7
  end
8
8
 
9
9
  Rails::Generator::Commands::Create.class_eval do
10
-
11
- def route_resources(resource_list)
12
- sentinel = 'ActionController::Routing::Routes.draw do |map|'
13
-
14
- logger.route "map.resources #{resource_list}"
15
- unless options[:pretend] || file_contains?('config/routes.rb', resource_list)
16
- gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
17
- "#{match}\n map.resources #{resource_list}"
18
- end
19
- end
20
- end
21
-
22
- def route_resource(resource_list)
23
- sentinel = 'ActionController::Routing::Routes.draw do |map|'
24
-
25
- logger.route "map.resource #{resource_list}"
26
- unless options[:pretend] || file_contains?('config/routes.rb', resource_list)
27
- gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
28
- "#{match}\n map.resource #{resource_list}"
29
- end
30
- end
31
- end
32
-
33
- def route_name(name, path, route_options = {})
34
- sentinel = 'ActionController::Routing::Routes.draw do |map|'
35
-
36
- logger.route "map.#{name} '#{path}', :controller => '#{route_options[:controller]}', :action => '#{route_options[:action]}'"
37
- unless options[:pretend]
38
- gsub_file_once 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
39
- "#{match}\n map.#{name} '#{path}', :controller => '#{route_options[:controller]}', :action => '#{route_options[:action]}'"
40
- end
41
- end
42
- end
43
-
44
10
  def insert_into(file, line)
45
11
  logger.insert "#{line} into #{file}"
46
12
  unless options[:pretend] || file_contains?(file, line)
@@ -52,30 +18,6 @@ Rails::Generator::Commands::Create.class_eval do
52
18
  end
53
19
 
54
20
  Rails::Generator::Commands::Destroy.class_eval do
55
- def route_resource(resource_list)
56
- look_for = " map.resource #{resource_list}\n".gsub(/[\[\]]/, '\\\\\0')
57
- logger.route "map.resource #{resource_list} #{look_for}"
58
- unless options[:pretend]
59
- gsub_file 'config/routes.rb', /(#{look_for})/mi, ''
60
- end
61
- end
62
-
63
- def route_resources(resource_list)
64
- look_for = " map.resources #{resource_list}\n".gsub(/[\[\]]/, '\\\\\0')
65
- logger.route "map.resources #{resource_list} #{look_for}"
66
- unless options[:pretend]
67
- gsub_file 'config/routes.rb', /(#{look_for})/mi, ''
68
- end
69
- end
70
-
71
- def route_name(name, path, route_options = {})
72
- look_for = "\n map.#{name} '#{path}', :controller => '#{route_options[:controller]}', :action => '#{route_options[:action]}'"
73
- logger.route "map.#{name} '#{path}', :controller => '#{route_options[:controller]}', :action => '#{route_options[:action]}'"
74
- unless options[:pretend]
75
- gsub_file 'config/routes.rb', /(#{look_for})/mi, ''
76
- end
77
- end
78
-
79
21
  def insert_into(file, line)
80
22
  logger.remove "#{line} from #{file}"
81
23
  unless options[:pretend]
@@ -85,18 +27,6 @@ Rails::Generator::Commands::Destroy.class_eval do
85
27
  end
86
28
 
87
29
  Rails::Generator::Commands::List.class_eval do
88
- def route_resource(resources_list)
89
- logger.route "map.resource #{resource_list}"
90
- end
91
-
92
- def route_resources(resources_list)
93
- logger.route "map.resource #{resource_list}"
94
- end
95
-
96
- def route_name(name, path, options = {})
97
- logger.route "map.#{name} '#{path}', :controller => '{options[:controller]}', :action => '#{options[:action]}'"
98
- end
99
-
100
30
  def insert_into(file, line)
101
31
  logger.insert "#{line} into #{file}"
102
32
  end
data/lib/clearance.rb CHANGED
@@ -1,19 +1,6 @@
1
1
  require 'clearance/extensions/errors'
2
2
  require 'clearance/extensions/rescue'
3
+ require 'clearance/extensions/routes'
3
4
 
4
5
  require 'clearance/authentication'
5
6
  require 'clearance/user'
6
-
7
- class ActionController::Routing::RouteSet
8
- def load_routes_with_clearance!
9
- lib_path = File.dirname(__FILE__)
10
- clearance_routes = File.join(lib_path, *%w[.. config clearance_routes.rb])
11
- unless configuration_files.include?(clearance_routes)
12
- add_configuration_file(clearance_routes)
13
- end
14
- load_routes_without_clearance!
15
- end
16
-
17
- alias_method_chain :load_routes!, :clearance
18
- end
19
-
@@ -42,6 +42,7 @@ module Clearance
42
42
  end
43
43
 
44
44
  def sign_user_in(user)
45
+ warn "[DEPRECATION] sign_user_in: unnecessary. use sign_in(user) instead."
45
46
  sign_in(user)
46
47
  end
47
48
 
@@ -63,22 +64,25 @@ module Clearance
63
64
 
64
65
  def forget(user)
65
66
  user.forget_me! if user
66
- cookies.delete :remember_token
67
+ cookies.delete(:remember_token)
67
68
  reset_session
68
69
  end
69
70
 
70
71
  def redirect_back_or(default)
71
- session[:return_to] ||= params[:return_to]
72
- if session[:return_to]
73
- redirect_to(session[:return_to])
74
- else
75
- redirect_to(default)
76
- end
72
+ redirect_to(return_to || default)
73
+ clear_return_to
74
+ end
75
+
76
+ def return_to
77
+ session[:return_to] || params[:return_to]
78
+ end
79
+
80
+ def clear_return_to
77
81
  session[:return_to] = nil
78
82
  end
79
83
 
80
84
  def redirect_to_root
81
- redirect_to root_url
85
+ redirect_to(root_url)
82
86
  end
83
87
 
84
88
  def store_location
@@ -88,7 +92,7 @@ module Clearance
88
92
  def deny_access(flash_message = nil, opts = {})
89
93
  store_location
90
94
  flash[:failure] = flash_message if flash_message
91
- redirect_to new_session_url
95
+ redirect_to(new_session_url)
92
96
  end
93
97
  end
94
98
 
@@ -0,0 +1,12 @@
1
+ class ActionController::Routing::RouteSet
2
+ def load_routes_with_clearance!
3
+ lib_path = File.dirname(__FILE__)
4
+ clearance_routes = File.join(lib_path, *%w[.. .. .. config clearance_routes.rb])
5
+ unless configuration_files.include?(clearance_routes)
6
+ add_configuration_file(clearance_routes)
7
+ end
8
+ load_routes_without_clearance!
9
+ end
10
+
11
+ alias_method_chain :load_routes!, :clearance
12
+ end
@@ -8,8 +8,9 @@ module Clearance
8
8
  user = block.bind(self).call
9
9
  assert_not_nil user,
10
10
  "please pass a User. try: should_be_signed_in_as { @user }"
11
- assert_equal user.id, session[:user_id],
12
- "session[:user_id] is not set to User's id"
11
+ assert_equal user, @controller.send(:current_user),
12
+ "#{user.inspect} is not the current_user, " <<
13
+ "which is #{@controller.send(:current_user).inspect}"
13
14
  end
14
15
  end
15
16
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thoughtbot-clearance
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.6
4
+ version: 0.6.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Croak
@@ -24,7 +24,7 @@ autorequire:
24
24
  bindir: bin
25
25
  cert_chain: []
26
26
 
27
- date: 2009-05-17 21:00:00 -07:00
27
+ date: 2009-06-12 21:00:00 -07:00
28
28
  default_executable:
29
29
  dependencies: []
30
30
 
@@ -95,6 +95,7 @@ files:
95
95
  - lib/clearance/extensions
96
96
  - lib/clearance/extensions/errors.rb
97
97
  - lib/clearance/extensions/rescue.rb
98
+ - lib/clearance/extensions/routes.rb
98
99
  - lib/clearance/user.rb
99
100
  - lib/clearance.rb
100
101
  - shoulda_macros/clearance.rb