devise 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of devise might be problematic. Click here for more details.

@@ -1,3 +1,9 @@
1
+ * bug fix
2
+ * Use prepend_before_filter in require_no_authentication.
3
+ * require_no_authentication on unlockable.
4
+ * Fix a bug when giving an association proxy to devise.
5
+ * Do not use lock! on lockable since it's part of ActiveRecord API.
6
+
1
7
  == 1.0.4
2
8
 
3
9
  * bug fix
data/Rakefile CHANGED
@@ -44,7 +44,7 @@ begin
44
44
  s.description = "Flexible authentication solution for Rails with Warden"
45
45
  s.authors = ['José Valim', 'Carlos Antônio']
46
46
  s.files = FileList["[A-Z]*", "{app,config,generators,lib}/**/*", "rails/init.rb"]
47
- s.add_dependency("warden", "~> 0.9.4")
47
+ s.add_dependency("warden", "~> 0.10.2")
48
48
  end
49
49
 
50
50
  Jeweler::GemcutterTasks.new
@@ -21,7 +21,7 @@ class ConfirmationsController < ApplicationController
21
21
 
22
22
  # GET /resource/confirmation?confirmation_token=abcdef
23
23
  def show
24
- self.resource = resource_class.confirm!(:confirmation_token => params[:confirmation_token])
24
+ self.resource = resource_class.confirm_by_token(params[:confirmation_token])
25
25
 
26
26
  if resource.errors.empty?
27
27
  set_flash_message :notice, :confirmed
@@ -1,8 +1,7 @@
1
1
  class PasswordsController < ApplicationController
2
+ prepend_before_filter :require_no_authentication
2
3
  include Devise::Controllers::InternalHelpers
3
4
 
4
- before_filter :require_no_authentication
5
-
6
5
  # GET /resource/password/new
7
6
  def new
8
7
  build_resource
@@ -30,7 +29,7 @@ class PasswordsController < ApplicationController
30
29
 
31
30
  # PUT /resource/password
32
31
  def update
33
- self.resource = resource_class.reset_password!(params[resource_name])
32
+ self.resource = resource_class.reset_password_by_token(params[resource_name])
34
33
 
35
34
  if resource.errors.empty?
36
35
  set_flash_message :notice, :updated
@@ -1,9 +1,8 @@
1
1
  class RegistrationsController < ApplicationController
2
+ prepend_before_filter :require_no_authentication, :only => [ :new, :create ]
3
+ prepend_before_filter :authenticate_scope!, :only => [:edit, :update, :destroy]
2
4
  include Devise::Controllers::InternalHelpers
3
5
 
4
- before_filter :require_no_authentication, :only => [ :new, :create ]
5
- before_filter :authenticate_scope!, :only => [:edit, :update, :destroy]
6
-
7
6
  # GET /resource/sign_in
8
7
  def new
9
8
  build_resource
@@ -1,8 +1,7 @@
1
1
  class SessionsController < ApplicationController
2
+ prepend_before_filter :require_no_authentication, :only => [ :new, :create ]
2
3
  include Devise::Controllers::InternalHelpers
3
4
 
4
- before_filter :require_no_authentication, :only => [ :new, :create ]
5
-
6
5
  # GET /resource/sign_in
7
6
  def new
8
7
  unless resource_just_signed_up?
@@ -35,11 +34,11 @@ class SessionsController < ApplicationController
35
34
 
36
35
  protected
37
36
 
38
- def resource_just_signed_up?
39
- flash[:"#{resource_name}_signed_up"]
40
- end
37
+ def resource_just_signed_up?
38
+ flash[:"#{resource_name}_signed_up"]
39
+ end
41
40
 
42
- def clean_up_passwords(object)
43
- object.clean_up_passwords if object.respond_to?(:clean_up_passwords)
44
- end
41
+ def clean_up_passwords(object)
42
+ object.clean_up_passwords if object.respond_to?(:clean_up_passwords)
43
+ end
45
44
  end
@@ -1,4 +1,5 @@
1
1
  class UnlocksController < ApplicationController
2
+ prepend_before_filter :require_no_authentication
2
3
  include Devise::Controllers::InternalHelpers
3
4
 
4
5
  # GET /resource/unlock/new
@@ -21,7 +22,7 @@ class UnlocksController < ApplicationController
21
22
 
22
23
  # GET /resource/unlock?unlock_token=abcdef
23
24
  def show
24
- self.resource = resource_class.unlock!(:unlock_token => params[:unlock_token])
25
+ self.resource = resource_class.unlock_access_by_token(params[:unlock_token])
25
26
 
26
27
  if resource.errors.empty?
27
28
  set_flash_message :notice, :unlocked
@@ -20,8 +20,8 @@ class DeviseMailer < ::ActionMailer::Base
20
20
 
21
21
  # Configure default email options
22
22
  def setup_mail(record, key)
23
- mapping = Devise::Mapping.find_by_class(record.class)
24
- raise "Invalid devise resource #{record}" unless mapping
23
+ scope_name = Devise::Mapping.find_scope!(record)
24
+ mapping = Devise.mappings[scope_name]
25
25
 
26
26
  subject translate(mapping, key)
27
27
  from mailer_sender(mapping)
@@ -145,8 +145,8 @@ module Devise
145
145
 
146
146
  # Address which sends Devise e-mails.
147
147
  mattr_accessor :mailer_sender
148
- @@mailer_sender = nil
149
-
148
+ @@mailer_sender = nil
149
+
150
150
  # Content Type of Devise e-mails.
151
151
  mattr_accessor :mailer_content_type
152
152
  @@mailer_content_type = 'text/html'
@@ -218,6 +218,9 @@ module Devise
218
218
  # Default is +nil+ (i.e. +false+).
219
219
  # +controller+ - Symbol representing a name of an exisiting or custom *controller* for this module.
220
220
  # Default is +nil+ (i.e. +false+).
221
+ # +route+ - Symbol representing the name of a *route* related to this module which a set of
222
+ # route view helpers should be created for.
223
+ # Default is +nil+ (i.e. +false+).
221
224
  #
222
225
  # == Examples:
223
226
  #
@@ -226,7 +229,7 @@ module Devise
226
229
  # Devise.add_module(:party_module, :model => 'party_module/model')
227
230
  #
228
231
  def add_module(module_name, options = {})
229
- Devise::ALL.unshift module_name unless Devise::ALL.include?(module_name)
232
+ Devise::ALL << module_name unless Devise::ALL.include?(module_name)
230
233
  Devise::STRATEGIES.unshift module_name if options[:strategy] && !Devise::STRATEGIES.include?(module_name)
231
234
 
232
235
  if options[:controller]
@@ -235,6 +238,10 @@ module Devise
235
238
  Devise::CONTROLLERS[controller].unshift module_name unless Devise::CONTROLLERS[controller].include?(module_name)
236
239
  end
237
240
 
241
+ if options[:route]
242
+ Devise::ROUTES.unshift options[:route] unless Devise::ROUTES.include?(options[:route])
243
+ end
244
+
238
245
  if options[:model]
239
246
  Devise::Models.module_eval do
240
247
  autoload :"#{module_name.to_s.classify}", options[:model]
@@ -14,7 +14,7 @@ module Devise
14
14
  hide_action :resource, :scope_name, :resource_name, :resource_class, :devise_mapping, :devise_controller?
15
15
 
16
16
  skip_before_filter *Devise.mappings.keys.map { |m| :"authenticate_#{m}!" }
17
- before_filter :is_devise_resource?
17
+ prepend_before_filter :is_devise_resource?
18
18
  end
19
19
  end
20
20
 
@@ -34,26 +34,19 @@ module Devise
34
34
  nil
35
35
  end
36
36
 
37
- # Find a mapping by a given class. It takes into account single table inheritance as well.
38
- def self.find_by_class(klass)
39
- Devise.mappings.each_value do |mapping|
40
- return mapping if klass <= mapping.to
41
- end
42
- nil
43
- end
44
-
45
37
  # Receives an object and find a scope for it. If a scope cannot be found,
46
38
  # raises an error. If a symbol is given, it's considered to be the scope.
47
39
  def self.find_scope!(duck)
48
40
  case duck
49
41
  when String, Symbol
50
- duck
42
+ return duck
43
+ when Class
44
+ Devise.mappings.each_value { |m| return m.name if duck <= m.to }
51
45
  else
52
- klass = duck.is_a?(Class) ? duck : duck.class
53
- mapping = Devise::Mapping.find_by_class(klass)
54
- raise "Could not find a valid mapping for #{duck}" unless mapping
55
- mapping.name
46
+ Devise.mappings.each_value { |m| return m.name if duck.is_a?(m.to) }
56
47
  end
48
+
49
+ raise "Could not find a valid mapping for #{duck}"
57
50
  end
58
51
 
59
52
  # Default url options which can be used as prefix.
@@ -78,15 +78,10 @@ module Devise
78
78
  # error on :current_password. It also automatically rejects :password and
79
79
  # :password_confirmation if they are blank.
80
80
  def update_with_password(params={})
81
- # TODO Remove me in next release
82
- if params[:old_password].present?
83
- params[:current_password] ||= params[:old_password]
84
- ActiveSupport::Deprecation.warn "old_password is deprecated, please use current_password instead", caller
85
- end
81
+ current_password = params.delete(:current_password)
86
82
 
87
- params.delete(:password) if params[:password].blank?
83
+ params.delete(:password) if params[:password].blank?
88
84
  params.delete(:password_confirmation) if params[:password_confirmation].blank?
89
- current_password = params.delete(:current_password)
90
85
 
91
86
  result = if valid_password?(current_password)
92
87
  update_attributes(params)
@@ -103,6 +98,13 @@ module Devise
103
98
 
104
99
  protected
105
100
 
101
+ # Checks whether a password is needed or not. For validations only.
102
+ # Passwords are always required if it's a new record, or if the password
103
+ # or confirmation are being set somewhere.
104
+ def password_required?
105
+ new_record? || !password.nil? || !password_confirmation.nil?
106
+ end
107
+
106
108
  # Digests the password using the configured encryptor.
107
109
  def password_digest(password)
108
110
  self.class.encryptor_class.digest(password, self.class.stretches, self.password_salt, self.class.pepper)
@@ -63,7 +63,7 @@ module Devise
63
63
  # Remove confirmation date and send confirmation instructions, to ensure
64
64
  # after sending these instructions the user won't be able to sign in without
65
65
  # confirming it's account
66
- def resend_confirmation!
66
+ def resend_confirmation_token
67
67
  unless_confirmed do
68
68
  generate_confirmation_token
69
69
  save(false)
@@ -81,11 +81,7 @@ module Devise
81
81
 
82
82
  # The message to be shown if the account is inactive.
83
83
  def inactive_message
84
- if !confirmed?
85
- :unconfirmed
86
- else
87
- super
88
- end
84
+ !confirmed? ? :unconfirmed : super
89
85
  end
90
86
 
91
87
  # If you don't want confirmation to be sent on create, neither a code
@@ -151,7 +147,7 @@ module Devise
151
147
  # Options must contain the user email
152
148
  def send_confirmation_instructions(attributes={})
153
149
  confirmable = find_or_initialize_with_error_by(:email, attributes[:email], :not_found)
154
- confirmable.resend_confirmation! unless confirmable.new_record?
150
+ confirmable.resend_confirmation_token unless confirmable.new_record?
155
151
  confirmable
156
152
  end
157
153
 
@@ -159,8 +155,8 @@ module Devise
159
155
  # If no user is found, returns a new user with an error.
160
156
  # If the user is already confirmed, create an error for the user
161
157
  # Options must have the confirmation_token
162
- def confirm!(attributes={})
163
- confirmable = find_or_initialize_with_error_by(:confirmation_token, attributes[:confirmation_token])
158
+ def confirm_by_token(confirmation_token)
159
+ confirmable = find_or_initialize_with_error_by(:confirmation_token, confirmation_token)
164
160
  confirmable.confirm! unless confirmable.new_record?
165
161
  confirmable
166
162
  end
@@ -27,23 +27,20 @@ module Devise
27
27
  end
28
28
 
29
29
  # Lock an user setting it's locked_at to actual time.
30
- def lock
30
+ def lock_access!
31
31
  self.locked_at = Time.now
32
+
32
33
  if unlock_strategy_enabled?(:email)
33
34
  generate_unlock_token
34
35
  send_unlock_instructions
35
36
  end
36
- end
37
37
 
38
- # Lock an user also saving the record.
39
- def lock!
40
- lock
41
38
  save(false)
42
39
  end
43
40
 
44
41
  # Unlock an user by cleaning locket_at and failed_attempts.
45
- def unlock!
46
- if_locked do
42
+ def unlock_access!
43
+ if_access_locked do
47
44
  self.locked_at = nil
48
45
  self.failed_attempts = 0
49
46
  self.unlock_token = nil
@@ -52,7 +49,7 @@ module Devise
52
49
  end
53
50
 
54
51
  # Verifies whether a user is locked or not.
55
- def locked?
52
+ def access_locked?
56
53
  locked_at && !lock_expired?
57
54
  end
58
55
 
@@ -62,8 +59,8 @@ module Devise
62
59
  end
63
60
 
64
61
  # Resend the unlock instructions if the user is locked.
65
- def resend_unlock!
66
- if_locked do
62
+ def resend_unlock_token
63
+ if_access_locked do
67
64
  generate_unlock_token unless unlock_token.present?
68
65
  save(false)
69
66
  send_unlock_instructions
@@ -73,17 +70,13 @@ module Devise
73
70
  # Overwrites active? from Devise::Models::Activatable for locking purposes
74
71
  # by verifying whether an user is active to sign in or not based on locked?
75
72
  def active?
76
- super && !locked?
73
+ super && !access_locked?
77
74
  end
78
75
 
79
76
  # Overwrites invalid_message from Devise::Models::Authenticatable to define
80
77
  # the correct reason for blocking the sign in.
81
78
  def inactive_message
82
- if locked?
83
- :locked
84
- else
85
- super
86
- end
79
+ access_locked? ? :locked : super
87
80
  end
88
81
 
89
82
  # Overwrites valid_for_authentication? from Devise::Models::Authenticatable
@@ -94,7 +87,10 @@ module Devise
94
87
  self.failed_attempts = 0
95
88
  else
96
89
  self.failed_attempts += 1
97
- lock if failed_attempts > self.class.maximum_attempts
90
+ if failed_attempts > self.class.maximum_attempts
91
+ lock_access!
92
+ return false
93
+ end
98
94
  end
99
95
  save(false) if changed?
100
96
  result
@@ -118,8 +114,8 @@ module Devise
118
114
 
119
115
  # Checks whether the record is locked or not, yielding to the block
120
116
  # if it's locked, otherwise adds an error to email.
121
- def if_locked
122
- if locked?
117
+ def if_access_locked
118
+ if access_locked?
123
119
  yield
124
120
  else
125
121
  self.class.add_error_on(self, :email, :not_locked)
@@ -139,7 +135,7 @@ module Devise
139
135
  # Options must contain the user email
140
136
  def send_unlock_instructions(attributes={})
141
137
  lockable = find_or_initialize_with_error_by(:email, attributes[:email], :not_found)
142
- lockable.resend_unlock! unless lockable.new_record?
138
+ lockable.resend_unlock_token unless lockable.new_record?
143
139
  lockable
144
140
  end
145
141
 
@@ -147,9 +143,9 @@ module Devise
147
143
  # If no user is found, returns a new user with an error.
148
144
  # If the user is not locked, creates an error for the user
149
145
  # Options must have the unlock_token
150
- def unlock!(attributes={})
151
- lockable = find_or_initialize_with_error_by(:unlock_token, attributes[:unlock_token])
152
- lockable.unlock! unless lockable.new_record?
146
+ def unlock_access_by_token(unlock_token)
147
+ lockable = find_or_initialize_with_error_by(:unlock_token, unlock_token)
148
+ lockable.unlock_access! unless lockable.new_record?
153
149
  lockable
154
150
  end
155
151
 
@@ -69,7 +69,7 @@ module Devise
69
69
  # try saving the record. If not user is found, returns a new user
70
70
  # containing an error in reset_password_token attribute.
71
71
  # Attributes must contain reset_password_token, password and confirmation
72
- def reset_password!(attributes={})
72
+ def reset_password_by_token(attributes={})
73
73
  recoverable = find_or_initialize_with_error_by(:reset_password_token, attributes[:reset_password_token])
74
74
  recoverable.reset_password!(attributes[:password], attributes[:password_confirmation]) unless recoverable.new_record?
75
75
  recoverable
@@ -34,15 +34,6 @@ module Devise
34
34
  "to the following methods: #{unavailable_validations.to_sentence}."
35
35
  end
36
36
  end
37
-
38
- protected
39
-
40
- # Checks whether a password is needed or not. For validations only.
41
- # Passwords are always required if it's a new record, or if the password
42
- # or confirmation are being set somewhere.
43
- def password_required?
44
- new_record? || !password.nil? || !password_confirmation.nil?
45
- end
46
37
  end
47
38
  end
48
39
  end
@@ -44,7 +44,7 @@ module Devise
44
44
  # Creates sign_in_count, current_sign_in_at, last_sign_in_at,
45
45
  # current_sign_in_ip, last_sign_in_ip.
46
46
  def trackable
47
- apply_schema :sign_in_count, Integer
47
+ apply_schema :sign_in_count, Integer, :default => 0
48
48
  apply_schema :current_sign_in_at, DateTime
49
49
  apply_schema :last_sign_in_at, DateTime
50
50
  apply_schema :current_sign_in_ip, String
@@ -54,7 +54,7 @@ module Devise
54
54
  # Creates failed_attempts, unlock_token and locked_at
55
55
  def lockable
56
56
  apply_schema :failed_attempts, Integer, :default => 0
57
- apply_schema :unlock_token, String, :limit => 20
57
+ apply_schema :unlock_token, String, :limit => 20
58
58
  apply_schema :locked_at, DateTime
59
59
  end
60
60
 
@@ -24,6 +24,10 @@ module Devise
24
24
  catch_with_redirect { super }
25
25
  end
26
26
 
27
+ def user(*args)
28
+ catch_with_redirect { super }
29
+ end
30
+
27
31
  def catch_with_redirect(&block)
28
32
  result = catch(:warden, &block)
29
33
 
@@ -1,3 +1,3 @@
1
1
  module Devise
2
- VERSION = "1.0.4".freeze
2
+ VERSION = "1.0.5".freeze
3
3
  end
@@ -63,6 +63,11 @@ class DeviseTest < ActiveSupport::TestCase
63
63
  Devise::ALL.delete(:kivi)
64
64
  Devise::CONTROLLERS.delete(:fruits)
65
65
 
66
+ assert_nothing_raised(Exception) { Devise.add_module(:carrot, :route => :vegetable) }
67
+ assert_equal 1, Devise::ROUTES.select { |v| v == :vegetable }.size
68
+ Devise::ALL.delete(:carrot)
69
+ Devise::ROUTES.delete(:vegetable)
70
+
66
71
  assert_nothing_raised(Exception) { Devise.add_module(:authenticatable_again, :model => 'devise/model/authenticatable') }
67
72
  assert defined?(Devise::Models::AuthenticatableAgain)
68
73
  end
@@ -47,14 +47,14 @@ class LockTest < ActionController::IntegrationTest
47
47
 
48
48
  test "locked user should be able to unlock account" do
49
49
  user = create_user(:locked => true)
50
- assert user.locked?
50
+ assert user.access_locked?
51
51
 
52
52
  visit_user_unlock_with_token(user.unlock_token)
53
53
 
54
54
  assert_template 'home/index'
55
55
  assert_contain 'Your account was successfully unlocked.'
56
56
 
57
- assert_not user.reload.locked?
57
+ assert_not user.reload.access_locked?
58
58
  end
59
59
 
60
60
  test "sign in user automatically after unlocking it's account" do
@@ -39,7 +39,7 @@ class TrackableHooksTest < ActionController::IntegrationTest
39
39
 
40
40
  test "increase sign in count" do
41
41
  user = create_user
42
- assert_nil user.sign_in_count
42
+ assert_equal 0, user.sign_in_count
43
43
 
44
44
  sign_in_as_user
45
45
  user.reload
@@ -10,7 +10,7 @@ class UnlockInstructionsTest < ActionMailer::TestCase
10
10
  def user
11
11
  @user ||= begin
12
12
  user = create_user
13
- user.lock!
13
+ user.lock_access!
14
14
  user
15
15
  end
16
16
  end
@@ -39,22 +39,17 @@ class MappingTest < ActiveSupport::TestCase
39
39
  assert_equal Devise.mappings[:admin], Devise::Mapping.find_by_path("/admin_area/session")
40
40
  end
41
41
 
42
- test 'find mapping by class' do
43
- assert_nil Devise::Mapping.find_by_class(String)
44
- assert_equal Devise.mappings[:user], Devise::Mapping.find_by_class(User)
45
- end
46
-
47
- test 'find mapping by class works with single table inheritance' do
48
- klass = Class.new(User)
49
- assert_equal Devise.mappings[:user], Devise::Mapping.find_by_class(klass)
50
- end
51
-
52
42
  test 'find scope for a given object' do
53
43
  assert_equal :user, Devise::Mapping.find_scope!(User)
54
44
  assert_equal :user, Devise::Mapping.find_scope!(:user)
55
45
  assert_equal :user, Devise::Mapping.find_scope!(User.new)
56
46
  end
57
47
 
48
+ test 'find scope works with single table inheritance' do
49
+ assert_equal :user, Devise::Mapping.find_scope!(Class.new(User))
50
+ assert_equal :user, Devise::Mapping.find_scope!(Class.new(User).new)
51
+ end
52
+
58
53
  test 'find scope raises an error if cannot be found' do
59
54
  assert_raise RuntimeError do
60
55
  Devise::Mapping.find_scope!(String)
@@ -15,7 +15,7 @@ class ConfirmableTest < ActiveSupport::TestCase
15
15
  user = create_user
16
16
  3.times do
17
17
  token = user.confirmation_token
18
- user.resend_confirmation!
18
+ user.resend_confirmation_token
19
19
  assert_not_equal token, user.confirmation_token
20
20
  end
21
21
  end
@@ -62,19 +62,19 @@ class ConfirmableTest < ActiveSupport::TestCase
62
62
 
63
63
  test 'should find and confirm an user automatically' do
64
64
  user = create_user
65
- confirmed_user = User.confirm!(:confirmation_token => user.confirmation_token)
65
+ confirmed_user = User.confirm_by_token(user.confirmation_token)
66
66
  assert_equal confirmed_user, user
67
67
  assert user.reload.confirmed?
68
68
  end
69
69
 
70
70
  test 'should return a new record with errors when a invalid token is given' do
71
- confirmed_user = User.confirm!(:confirmation_token => 'invalid_confirmation_token')
71
+ confirmed_user = User.confirm_by_token('invalid_confirmation_token')
72
72
  assert confirmed_user.new_record?
73
73
  assert_match /invalid/, confirmed_user.errors[:confirmation_token]
74
74
  end
75
75
 
76
76
  test 'should return a new record with errors when a blank token is given' do
77
- confirmed_user = User.confirm!(:confirmation_token => '')
77
+ confirmed_user = User.confirm_by_token('')
78
78
  assert confirmed_user.new_record?
79
79
  assert_match /blank/, confirmed_user.errors[:confirmation_token]
80
80
  end
@@ -83,7 +83,7 @@ class ConfirmableTest < ActiveSupport::TestCase
83
83
  user = create_user
84
84
  user.confirmed_at = Time.now
85
85
  user.save
86
- confirmed_user = User.confirm!(:confirmation_token => user.confirmation_token)
86
+ confirmed_user = User.confirm_by_token(user.confirmation_token)
87
87
  assert confirmed_user.confirmed?
88
88
  assert confirmed_user.errors[:email]
89
89
  end
@@ -173,7 +173,7 @@ class ConfirmableTest < ActiveSupport::TestCase
173
173
  test 'should not be able to send instructions if the user is already confirmed' do
174
174
  user = create_user
175
175
  user.confirm!
176
- assert_not user.resend_confirmation!
176
+ assert_not user.resend_confirmation_token
177
177
  assert user.confirmed?
178
178
  assert_equal 'already confirmed', user.errors[:email]
179
179
  end
@@ -17,14 +17,14 @@ class LockableTest < ActiveSupport::TestCase
17
17
  user = create_user
18
18
  attempts = Devise.maximum_attempts + 1
19
19
  attempts.times { authenticated_user = User.authenticate(:email => user.email, :password => "anotherpassword") }
20
- assert user.reload.locked?
20
+ assert user.reload.access_locked?
21
21
  end
22
22
 
23
23
  test "should respect maximum attempts configuration" do
24
24
  user = create_user
25
25
  swap Devise, :maximum_attempts => 2 do
26
26
  3.times { authenticated_user = User.authenticate(:email => user.email, :password => "anotherpassword") }
27
- assert user.reload.locked?
27
+ assert user.reload.access_locked?
28
28
  end
29
29
  end
30
30
 
@@ -38,25 +38,26 @@ class LockableTest < ActiveSupport::TestCase
38
38
 
39
39
  test "should verify wheter a user is locked or not" do
40
40
  user = create_user
41
- assert_not user.locked?
42
- user.lock!
43
- assert user.locked?
41
+ assert_not user.access_locked?
42
+ user.lock_access!
43
+ assert user.access_locked?
44
44
  end
45
45
 
46
46
  test "active? should be the opposite of locked?" do
47
47
  user = create_user
48
48
  user.confirm!
49
49
  assert user.active?
50
- user.lock!
50
+ user.lock_access!
51
51
  assert_not user.active?
52
52
  end
53
53
 
54
54
  test "should unlock an user by cleaning locked_at, falied_attempts and unlock_token" do
55
55
  user = create_user
56
- user.lock!
56
+ user.lock_access!
57
57
  assert_not_nil user.reload.locked_at
58
58
  assert_not_nil user.reload.unlock_token
59
- user.unlock!
59
+
60
+ user.unlock_access!
60
61
  assert_nil user.reload.locked_at
61
62
  assert_nil user.reload.unlock_token
62
63
  assert 0, user.reload.failed_attempts
@@ -64,12 +65,13 @@ class LockableTest < ActiveSupport::TestCase
64
65
 
65
66
  test 'should not unlock an unlocked user' do
66
67
  user = create_user
67
- assert_not user.unlock!
68
+
69
+ assert_not user.unlock_access!
68
70
  assert_match /not locked/, user.errors[:email]
69
71
  end
70
72
 
71
73
  test "new user should not be locked and should have zero failed_attempts" do
72
- assert_not new_user.locked?
74
+ assert_not new_user.access_locked?
73
75
  assert_equal 0, create_user.failed_attempts
74
76
  end
75
77
 
@@ -77,10 +79,10 @@ class LockableTest < ActiveSupport::TestCase
77
79
  swap Devise, :unlock_in => 3.hours do
78
80
  user = new_user
79
81
  user.locked_at = 2.hours.ago
80
- assert user.locked?
82
+ assert user.access_locked?
81
83
 
82
84
  Devise.unlock_in = 1.hour
83
- assert_not user.locked?
85
+ assert_not user.access_locked?
84
86
  end
85
87
  end
86
88
 
@@ -88,14 +90,14 @@ class LockableTest < ActiveSupport::TestCase
88
90
  swap Devise, :unlock_strategy => :email do
89
91
  user = new_user
90
92
  user.locked_at = 2.hours.ago
91
- assert user.locked?
93
+ assert user.access_locked?
92
94
  end
93
95
  end
94
96
 
95
97
  test "should set unlock_token when locking" do
96
98
  user = create_user
97
99
  assert_nil user.unlock_token
98
- user.lock!
100
+ user.lock_access!
99
101
  assert_not_nil user.unlock_token
100
102
  end
101
103
 
@@ -104,7 +106,7 @@ class LockableTest < ActiveSupport::TestCase
104
106
  user.lock!
105
107
  3.times do
106
108
  token = user.unlock_token
107
- user.resend_unlock!
109
+ user.resend_unlock_token
108
110
  assert_equal token, user.unlock_token
109
111
  end
110
112
  end
@@ -113,7 +115,7 @@ class LockableTest < ActiveSupport::TestCase
113
115
  unlock_tokens = []
114
116
  3.times do
115
117
  user = create_user
116
- user.lock!
118
+ user.lock_access!
117
119
  token = user.unlock_token
118
120
  assert !unlock_tokens.include?(token)
119
121
  unlock_tokens << token
@@ -123,7 +125,7 @@ class LockableTest < ActiveSupport::TestCase
123
125
  test "should not generate unlock_token when :email is not an unlock strategy" do
124
126
  swap Devise, :unlock_strategy => :time do
125
127
  user = create_user
126
- user.lock!
128
+ user.lock_access!
127
129
  assert_nil user.unlock_token
128
130
  end
129
131
  end
@@ -132,7 +134,7 @@ class LockableTest < ActiveSupport::TestCase
132
134
  swap Devise, :unlock_strategy => :email do
133
135
  user = create_user
134
136
  assert_email_sent do
135
- user.lock!
137
+ user.lock_access!
136
138
  end
137
139
  end
138
140
  end
@@ -141,42 +143,42 @@ class LockableTest < ActiveSupport::TestCase
141
143
  swap Devise, :unlock_strategy => :time do
142
144
  user = create_user
143
145
  assert_email_not_sent do
144
- user.lock!
146
+ user.lock_access!
145
147
  end
146
148
  end
147
149
  end
148
150
 
149
151
  test 'should find and unlock an user automatically' do
150
152
  user = create_user
151
- user.lock!
152
- locked_user = User.unlock!(:unlock_token => user.unlock_token)
153
+ user.lock_access!
154
+ locked_user = User.unlock_access_by_token(user.unlock_token)
153
155
  assert_equal locked_user, user
154
- assert_not user.reload.locked?
156
+ assert_not user.reload.access_locked?
155
157
  end
156
158
 
157
159
  test 'should return a new record with errors when a invalid token is given' do
158
- locked_user = User.unlock!(:unlock_token => 'invalid_token')
160
+ locked_user = User.unlock_access_by_token('invalid_token')
159
161
  assert locked_user.new_record?
160
162
  assert_match /invalid/, locked_user.errors[:unlock_token]
161
163
  end
162
164
 
163
165
  test 'should return a new record with errors when a blank token is given' do
164
- locked_user = User.unlock!(:unlock_token => '')
166
+ locked_user = User.unlock_access_by_token('')
165
167
  assert locked_user.new_record?
166
168
  assert_match /blank/, locked_user.errors[:unlock_token]
167
169
  end
168
170
 
169
171
  test 'should authenticate a unlocked user' do
170
172
  user = create_user
171
- user.lock!
172
- user.unlock!
173
+ user.lock_access!
174
+ user.unlock_access!
173
175
  authenticated_user = User.authenticate(:email => user.email, :password => user.password)
174
176
  assert_equal authenticated_user, user
175
177
  end
176
178
 
177
179
  test 'should find a user to send unlock instructions' do
178
180
  user = create_user
179
- user.lock!
181
+ user.lock_access!
180
182
  unlock_user = User.send_unlock_instructions(:email => user.email)
181
183
  assert_equal unlock_user, user
182
184
  end
@@ -194,8 +196,8 @@ class LockableTest < ActiveSupport::TestCase
194
196
 
195
197
  test 'should not be able to send instructions if the user is not locked' do
196
198
  user = create_user
197
- assert_not user.resend_unlock!
198
- assert_not user.locked?
199
+ assert_not user.resend_unlock_token
200
+ assert_not user.access_locked?
199
201
  assert_equal 'not locked', user.errors[:email]
200
202
  end
201
203
 
@@ -104,18 +104,18 @@ class RecoverableTest < ActiveSupport::TestCase
104
104
  user = create_user
105
105
  user.send :generate_reset_password_token!
106
106
 
107
- reset_password_user = User.reset_password!(:reset_password_token => user.reset_password_token)
107
+ reset_password_user = User.reset_password_by_token(:reset_password_token => user.reset_password_token)
108
108
  assert_equal reset_password_user, user
109
109
  end
110
110
 
111
111
  test 'should a new record with errors if no reset_password_token is found' do
112
- reset_password_user = User.reset_password!(:reset_password_token => 'invalid_token')
112
+ reset_password_user = User.reset_password_by_token(:reset_password_token => 'invalid_token')
113
113
  assert reset_password_user.new_record?
114
114
  assert_match /invalid/, reset_password_user.errors[:reset_password_token]
115
115
  end
116
116
 
117
117
  test 'should a new record with errors if reset_password_token is blank' do
118
- reset_password_user = User.reset_password!(:reset_password_token => '')
118
+ reset_password_user = User.reset_password_by_token(:reset_password_token => '')
119
119
  assert reset_password_user.new_record?
120
120
  assert_match /blank/, reset_password_user.errors[:reset_password_token]
121
121
  end
@@ -125,7 +125,7 @@ class RecoverableTest < ActiveSupport::TestCase
125
125
  old_password = user.password
126
126
  user.send :generate_reset_password_token!
127
127
 
128
- reset_password_user = User.reset_password!(
128
+ reset_password_user = User.reset_password_by_token(
129
129
  :reset_password_token => user.reset_password_token,
130
130
  :password => 'new_password',
131
131
  :password_confirmation => 'new_password'
@@ -26,6 +26,20 @@ class ActiveRecordTest < ActiveSupport::TestCase
26
26
  assert_include_modules Admin, :authenticatable, :registerable, :timeoutable
27
27
  end
28
28
 
29
+ test 'order of module inclusion' do
30
+ correct_module_order = [:authenticatable, :registerable, :timeoutable]
31
+ incorrect_module_order = [:authenticatable, :timeoutable, :registerable]
32
+
33
+ assert_include_modules Admin, *incorrect_module_order
34
+
35
+ # get module constants from symbol list
36
+ module_constants = correct_module_order.collect { |mod| Devise::Models::const_get(mod.to_s.classify) }
37
+
38
+ # confirm that they adhere to the order in ALL
39
+ # get included modules, filter out the noise, and reverse the order
40
+ assert_equal module_constants, (Admin.included_modules & module_constants).reverse
41
+ end
42
+
29
43
  test 'set a default value for stretches' do
30
44
  assert_equal 15, Configurable.stretches
31
45
  end
@@ -7,4 +7,6 @@ class ApplicationController < ActionController::Base
7
7
 
8
8
  # Scrub sensitive parameters from your log
9
9
  filter_parameter_logging :password
10
+
11
+ before_filter :current_user
10
12
  end
@@ -14,7 +14,7 @@ class ActionController::IntegrationTest
14
14
  :created_at => Time.now.utc
15
15
  )
16
16
  user.confirm! unless options[:confirm] == false
17
- user.lock! if options[:locked] == true
17
+ user.lock_access! if options[:locked] == true
18
18
  user
19
19
  end
20
20
  end
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: devise
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 0
8
+ - 5
9
+ version: 1.0.5
5
10
  platform: ruby
6
11
  authors:
7
12
  - "Jos\xC3\xA9 Valim"
@@ -10,19 +15,23 @@ autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
17
 
13
- date: 2010-03-03 00:00:00 +01:00
18
+ date: 2010-03-26 00:00:00 +01:00
14
19
  default_executable:
15
20
  dependencies:
16
21
  - !ruby/object:Gem::Dependency
17
22
  name: warden
18
- type: :runtime
19
- version_requirement:
20
- version_requirements: !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
21
25
  requirements:
22
26
  - - ~>
23
27
  - !ruby/object:Gem::Version
24
- version: 0.9.4
25
- version:
28
+ segments:
29
+ - 0
30
+ - 10
31
+ - 2
32
+ version: 0.10.2
33
+ type: :runtime
34
+ version_requirements: *id001
26
35
  description: Flexible authentication solution for Rails with Warden
27
36
  email: contact@plataformatec.com.br
28
37
  executables: []
@@ -125,18 +134,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
125
134
  requirements:
126
135
  - - ">="
127
136
  - !ruby/object:Gem::Version
137
+ segments:
138
+ - 0
128
139
  version: "0"
129
- version:
130
140
  required_rubygems_version: !ruby/object:Gem::Requirement
131
141
  requirements:
132
142
  - - ">="
133
143
  - !ruby/object:Gem::Version
144
+ segments:
145
+ - 0
134
146
  version: "0"
135
- version:
136
147
  requirements: []
137
148
 
138
149
  rubyforge_project:
139
- rubygems_version: 1.3.5
150
+ rubygems_version: 1.3.6
140
151
  signing_key:
141
152
  specification_version: 3
142
153
  summary: Flexible authentication solution for Rails with Warden