devise 3.2.0 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of devise might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/.travis.yml +18 -3
- data/CHANGELOG.md +82 -9
- data/CONTRIBUTING.md +2 -2
- data/Gemfile +7 -9
- data/Gemfile.lock +102 -96
- data/MIT-LICENSE +1 -1
- data/README.md +94 -42
- data/Rakefile +1 -1
- data/app/controllers/devise/confirmations_controller.rb +5 -3
- data/app/controllers/devise/omniauth_callbacks_controller.rb +2 -2
- data/app/controllers/devise/passwords_controller.rb +5 -3
- data/app/controllers/devise/registrations_controller.rb +26 -10
- data/app/controllers/devise/sessions_controller.rb +39 -14
- data/app/controllers/devise/unlocks_controller.rb +4 -2
- data/app/controllers/devise_controller.rb +6 -6
- data/app/helpers/devise_helper.rb +2 -2
- data/app/views/devise/confirmations/new.html.erb +2 -2
- data/app/views/devise/mailer/confirmation_instructions.html.erb +1 -1
- data/app/views/devise/mailer/reset_password_instructions.html.erb +1 -1
- data/app/views/devise/mailer/unlock_instructions.html.erb +1 -1
- data/app/views/devise/passwords/edit.html.erb +3 -3
- data/app/views/devise/passwords/new.html.erb +2 -2
- data/app/views/devise/registrations/edit.html.erb +6 -6
- data/app/views/devise/registrations/new.html.erb +5 -5
- data/app/views/devise/sessions/new.html.erb +5 -5
- data/app/views/devise/shared/_links.erb +1 -1
- data/app/views/devise/unlocks/new.html.erb +2 -2
- data/config/locales/en.yml +17 -16
- data/devise.gemspec +2 -2
- data/gemfiles/{Gemfile.rails-3.2.x → Gemfile.rails-3.2-stable} +8 -10
- data/gemfiles/Gemfile.rails-3.2-stable.lock +166 -0
- data/gemfiles/Gemfile.rails-4.0-stable +29 -0
- data/gemfiles/Gemfile.rails-4.0-stable.lock +162 -0
- data/gemfiles/Gemfile.rails-head +32 -0
- data/gemfiles/Gemfile.rails-head.lock +190 -0
- data/lib/devise/controllers/helpers.rb +84 -29
- data/lib/devise/controllers/rememberable.rb +3 -3
- data/lib/devise/controllers/scoped_views.rb +1 -1
- data/lib/devise/controllers/sign_in_out.rb +9 -10
- data/lib/devise/controllers/store_location.rb +56 -0
- data/lib/devise/controllers/url_helpers.rb +3 -1
- data/lib/devise/failure_app.rb +12 -10
- data/lib/devise/hooks/activatable.rb +5 -6
- data/lib/devise/hooks/csrf_cleaner.rb +3 -1
- data/lib/devise/hooks/lockable.rb +1 -1
- data/lib/devise/hooks/proxy.rb +2 -2
- data/lib/devise/hooks/rememberable.rb +2 -2
- data/lib/devise/hooks/timeoutable.rb +10 -3
- data/lib/devise/hooks/trackable.rb +1 -1
- data/lib/devise/mailers/helpers.rb +8 -8
- data/lib/devise/mapping.rb +4 -1
- data/lib/devise/models/authenticatable.rb +5 -5
- data/lib/devise/models/confirmable.rb +14 -14
- data/lib/devise/models/database_authenticatable.rb +18 -5
- data/lib/devise/models/lockable.rb +14 -11
- data/lib/devise/models/omniauthable.rb +1 -1
- data/lib/devise/models/recoverable.rb +23 -7
- data/lib/devise/models/rememberable.rb +6 -6
- data/lib/devise/models/timeoutable.rb +2 -2
- data/lib/devise/models/trackable.rb +5 -2
- data/lib/devise/models/validatable.rb +6 -6
- data/lib/devise/modules.rb +10 -10
- data/lib/devise/omniauth/url_helpers.rb +2 -2
- data/lib/devise/orm/active_record.rb +1 -1
- data/lib/devise/orm/mongoid.rb +1 -1
- data/lib/devise/rails/routes.rb +107 -78
- data/lib/devise/rails.rb +7 -1
- data/lib/devise/strategies/authenticatable.rb +11 -4
- data/lib/devise/strategies/base.rb +1 -1
- data/lib/devise/strategies/database_authenticatable.rb +7 -4
- data/lib/devise/test_helpers.rb +2 -2
- data/lib/devise/time_inflector.rb +2 -2
- data/lib/devise/version.rb +1 -1
- data/lib/devise.rb +15 -10
- data/lib/generators/active_record/devise_generator.rb +27 -10
- data/lib/generators/active_record/templates/migration.rb +4 -4
- data/lib/generators/active_record/templates/migration_existing.rb +4 -4
- data/lib/generators/devise/devise_generator.rb +5 -3
- data/lib/generators/devise/install_generator.rb +5 -0
- data/lib/generators/devise/views_generator.rb +31 -18
- data/lib/generators/mongoid/devise_generator.rb +20 -19
- data/lib/generators/templates/README +4 -4
- data/lib/generators/templates/devise.rb +20 -11
- data/lib/generators/templates/markerb/confirmation_instructions.markerb +1 -1
- data/lib/generators/templates/markerb/reset_password_instructions.markerb +1 -1
- data/lib/generators/templates/markerb/unlock_instructions.markerb +1 -1
- data/lib/generators/templates/simple_form_for/confirmations/new.html.erb +2 -2
- data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +4 -4
- data/lib/generators/templates/simple_form_for/passwords/new.html.erb +2 -2
- data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +6 -6
- data/lib/generators/templates/simple_form_for/registrations/new.html.erb +4 -4
- data/lib/generators/templates/simple_form_for/sessions/new.html.erb +4 -4
- data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +2 -2
- data/script/cached-bundle +49 -0
- data/script/s3-put +71 -0
- data/test/controllers/custom_registrations_controller_test.rb +35 -0
- data/test/controllers/helpers_test.rb +89 -31
- data/test/controllers/internal_helpers_test.rb +11 -8
- data/test/controllers/passwords_controller_test.rb +1 -1
- data/test/controllers/sessions_controller_test.rb +29 -25
- data/test/controllers/url_helpers_test.rb +4 -4
- data/test/delegator_test.rb +1 -1
- data/test/devise_test.rb +21 -8
- data/test/failure_app_test.rb +61 -25
- data/test/generators/active_record_generator_test.rb +10 -4
- data/test/generators/devise_generator_test.rb +2 -2
- data/test/generators/mongoid_generator_test.rb +3 -3
- data/test/generators/views_generator_test.rb +30 -1
- data/test/helpers/devise_helper_test.rb +14 -13
- data/test/integration/authenticatable_test.rb +61 -45
- data/test/integration/confirmable_test.rb +95 -55
- data/test/integration/database_authenticatable_test.rb +16 -16
- data/test/integration/http_authenticatable_test.rb +12 -12
- data/test/integration/lockable_test.rb +43 -43
- data/test/integration/omniauthable_test.rb +3 -3
- data/test/integration/recoverable_test.rb +53 -53
- data/test/integration/registerable_test.rb +90 -80
- data/test/integration/rememberable_test.rb +15 -15
- data/test/integration/timeoutable_test.rb +27 -16
- data/test/integration/trackable_test.rb +4 -4
- data/test/mailers/confirmation_instructions_test.rb +7 -7
- data/test/mailers/reset_password_instructions_test.rb +6 -6
- data/test/mailers/unlock_instructions_test.rb +5 -5
- data/test/mapping_test.rb +3 -3
- data/test/models/authenticatable_test.rb +3 -3
- data/test/models/confirmable_test.rb +32 -32
- data/test/models/database_authenticatable_test.rb +32 -27
- data/test/models/lockable_test.rb +57 -33
- data/test/models/recoverable_test.rb +34 -22
- data/test/models/rememberable_test.rb +29 -14
- data/test/models/serializable_test.rb +8 -8
- data/test/models/timeoutable_test.rb +1 -1
- data/test/models/trackable_test.rb +28 -0
- data/test/models/validatable_test.rb +13 -13
- data/test/omniauth/config_test.rb +4 -4
- data/test/omniauth/url_helpers_test.rb +3 -3
- data/test/orm/mongoid.rb +1 -1
- data/test/parameter_sanitizer_test.rb +1 -1
- data/test/rails_app/app/active_record/shim.rb +1 -1
- data/test/rails_app/app/active_record/user_on_engine.rb +7 -0
- data/test/rails_app/app/active_record/user_on_main_app.rb +7 -0
- data/test/rails_app/app/controllers/admins/sessions_controller.rb +1 -1
- data/test/rails_app/app/controllers/admins_controller.rb +1 -1
- data/test/rails_app/app/controllers/application_controller.rb +5 -2
- data/test/rails_app/app/controllers/application_with_fake_engine.rb +30 -0
- data/test/rails_app/app/controllers/custom/registrations_controller.rb +21 -0
- data/test/rails_app/app/controllers/home_controller.rb +1 -1
- data/test/rails_app/app/controllers/publisher/registrations_controller.rb +1 -1
- data/test/rails_app/app/controllers/publisher/sessions_controller.rb +1 -1
- data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +4 -4
- data/test/rails_app/app/controllers/users_controller.rb +6 -6
- data/test/rails_app/app/mailers/users/mailer.rb +4 -4
- data/test/rails_app/app/mongoid/admin.rb +11 -11
- data/test/rails_app/app/mongoid/shim.rb +2 -2
- data/test/rails_app/app/mongoid/user.rb +19 -19
- data/test/rails_app/app/mongoid/user_on_engine.rb +39 -0
- data/test/rails_app/app/mongoid/user_on_main_app.rb +39 -0
- data/test/rails_app/app/views/admins/sessions/new.html.erb +1 -1
- data/test/rails_app/app/views/home/admin_dashboard.html.erb +1 -1
- data/test/rails_app/app/views/home/index.html.erb +1 -1
- data/test/rails_app/app/views/home/join.html.erb +1 -1
- data/test/rails_app/app/views/home/user_dashboard.html.erb +1 -1
- data/test/rails_app/app/views/layouts/application.html.erb +1 -1
- data/test/rails_app/config/application.rb +2 -2
- data/test/rails_app/config/boot.rb +7 -1
- data/test/rails_app/config/environments/development.rb +0 -4
- data/test/rails_app/config/environments/production.rb +0 -4
- data/test/rails_app/config/initializers/devise.rb +7 -5
- data/test/rails_app/config/initializers/secret_token.rb +1 -1
- data/test/rails_app/config/routes.rb +60 -42
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +7 -7
- data/test/rails_app/db/schema.rb +21 -17
- data/test/rails_app/lib/shared_admin.rb +4 -4
- data/test/rails_app/lib/shared_user.rb +1 -1
- data/test/rails_app/lib/shared_user_without_omniauth.rb +13 -0
- data/test/routes_test.rb +72 -58
- data/test/support/action_controller/record_identifier.rb +10 -0
- data/test/support/assertions.rb +2 -3
- data/test/support/helpers.rb +4 -4
- data/test/support/integration.rb +14 -14
- data/test/support/mongoid.yml +6 -0
- data/test/test_helper.rb +2 -7
- data/test/test_helpers_test.rb +25 -35
- data/test/test_models.rb +12 -5
- metadata +53 -38
- data/gemfiles/Gemfile.rails-3.2.x.lock +0 -159
@@ -53,7 +53,7 @@ class ConfirmationInstructionsTest < ActionMailer::TestCase
|
|
53
53
|
|
54
54
|
test 'custom mailer renders parent mailer template' do
|
55
55
|
Devise.mailer = 'Users::Mailer'
|
56
|
-
|
56
|
+
assert_present mail.body.encoded
|
57
57
|
end
|
58
58
|
|
59
59
|
test 'setup reply to as copy from sender' do
|
@@ -67,13 +67,13 @@ class ConfirmationInstructionsTest < ActionMailer::TestCase
|
|
67
67
|
end
|
68
68
|
|
69
69
|
test 'setup subject from I18n' do
|
70
|
-
store_translations :en, :
|
70
|
+
store_translations :en, devise: { mailer: { confirmation_instructions: { subject: 'Account Confirmation' } } } do
|
71
71
|
assert_equal 'Account Confirmation', mail.subject
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
75
|
test 'subject namespaced by model' do
|
76
|
-
store_translations :en, :
|
76
|
+
store_translations :en, devise: { mailer: { confirmation_instructions: { user_subject: 'User Account Confirmation' } } } do
|
77
77
|
assert_equal 'User Account Confirmation', mail.subject
|
78
78
|
end
|
79
79
|
end
|
@@ -83,9 +83,9 @@ class ConfirmationInstructionsTest < ActionMailer::TestCase
|
|
83
83
|
end
|
84
84
|
|
85
85
|
test 'body should have link to confirm the account' do
|
86
|
-
host = ActionMailer::Base.default_url_options
|
86
|
+
host, port = ActionMailer::Base.default_url_options.values_at :host, :port
|
87
87
|
|
88
|
-
if mail.body.encoded =~ %r{<a href=\"http://#{host}/users/confirmation\?confirmation_token=([^"]+)">}
|
88
|
+
if mail.body.encoded =~ %r{<a href=\"http://#{host}:#{port}/users/confirmation\?confirmation_token=([^"]+)">}
|
89
89
|
assert_equal Devise.token_generator.digest(user.class, :confirmation_token, $1), user.confirmation_token
|
90
90
|
else
|
91
91
|
flunk "expected confirmation url regex to match"
|
@@ -93,7 +93,7 @@ class ConfirmationInstructionsTest < ActionMailer::TestCase
|
|
93
93
|
end
|
94
94
|
|
95
95
|
test 'renders a scoped if scoped_views is set to true' do
|
96
|
-
swap Devise, :
|
96
|
+
swap Devise, scoped_views: true do
|
97
97
|
assert_equal user.email, mail.body.decoded
|
98
98
|
end
|
99
99
|
end
|
@@ -108,7 +108,7 @@ class ConfirmationInstructionsTest < ActionMailer::TestCase
|
|
108
108
|
end
|
109
109
|
|
110
110
|
test 'mailer sender accepts a proc' do
|
111
|
-
swap Devise, :
|
111
|
+
swap Devise, mailer_sender: proc { "another@example.com" } do
|
112
112
|
assert_equal ['another@example.com'], mail.from
|
113
113
|
end
|
114
114
|
end
|
@@ -55,7 +55,7 @@ class ResetPasswordInstructionsTest < ActionMailer::TestCase
|
|
55
55
|
|
56
56
|
test 'custom mailer renders parent mailer template' do
|
57
57
|
Devise.mailer = 'Users::Mailer'
|
58
|
-
|
58
|
+
assert_present mail.body.encoded
|
59
59
|
end
|
60
60
|
|
61
61
|
test 'setup reply to as copy from sender' do
|
@@ -63,13 +63,13 @@ class ResetPasswordInstructionsTest < ActionMailer::TestCase
|
|
63
63
|
end
|
64
64
|
|
65
65
|
test 'setup subject from I18n' do
|
66
|
-
store_translations :en, :
|
66
|
+
store_translations :en, devise: { mailer: { reset_password_instructions: { subject: 'Reset instructions' } } } do
|
67
67
|
assert_equal 'Reset instructions', mail.subject
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
71
|
test 'subject namespaced by model' do
|
72
|
-
store_translations :en, :
|
72
|
+
store_translations :en, devise: { mailer: { reset_password_instructions: { user_subject: 'User Reset Instructions' } } } do
|
73
73
|
assert_equal 'User Reset Instructions', mail.subject
|
74
74
|
end
|
75
75
|
end
|
@@ -79,9 +79,9 @@ class ResetPasswordInstructionsTest < ActionMailer::TestCase
|
|
79
79
|
end
|
80
80
|
|
81
81
|
test 'body should have link to confirm the account' do
|
82
|
-
host = ActionMailer::Base.default_url_options
|
82
|
+
host, port = ActionMailer::Base.default_url_options.values_at :host, :port
|
83
83
|
|
84
|
-
if mail.body.encoded =~ %r{<a href=\"http://#{host}/users/password/edit\?reset_password_token=([^"]+)">}
|
84
|
+
if mail.body.encoded =~ %r{<a href=\"http://#{host}:#{port}/users/password/edit\?reset_password_token=([^"]+)">}
|
85
85
|
assert_equal Devise.token_generator.digest(user.class, :reset_password_token, $1), user.reset_password_token
|
86
86
|
else
|
87
87
|
flunk "expected reset password url regex to match"
|
@@ -89,7 +89,7 @@ class ResetPasswordInstructionsTest < ActionMailer::TestCase
|
|
89
89
|
end
|
90
90
|
|
91
91
|
test 'mailer sender accepts a proc' do
|
92
|
-
swap Devise, :
|
92
|
+
swap Devise, mailer_sender: proc { "another@example.com" } do
|
93
93
|
assert_equal ['another@example.com'], mail.from
|
94
94
|
end
|
95
95
|
end
|
@@ -56,7 +56,7 @@ class UnlockInstructionsTest < ActionMailer::TestCase
|
|
56
56
|
|
57
57
|
test 'custom mailer renders parent mailer template' do
|
58
58
|
Devise.mailer = 'Users::Mailer'
|
59
|
-
|
59
|
+
assert_present mail.body.encoded
|
60
60
|
end
|
61
61
|
|
62
62
|
test 'setup reply to as copy from sender' do
|
@@ -64,13 +64,13 @@ class UnlockInstructionsTest < ActionMailer::TestCase
|
|
64
64
|
end
|
65
65
|
|
66
66
|
test 'setup subject from I18n' do
|
67
|
-
store_translations :en, :
|
67
|
+
store_translations :en, devise: { mailer: { unlock_instructions: { subject: 'Yo unlock instructions' } } } do
|
68
68
|
assert_equal 'Yo unlock instructions', mail.subject
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
72
|
test 'subject namespaced by model' do
|
73
|
-
store_translations :en, :
|
73
|
+
store_translations :en, devise: { mailer: { unlock_instructions: { user_subject: 'User Unlock Instructions' } } } do
|
74
74
|
assert_equal 'User Unlock Instructions', mail.subject
|
75
75
|
end
|
76
76
|
end
|
@@ -80,9 +80,9 @@ class UnlockInstructionsTest < ActionMailer::TestCase
|
|
80
80
|
end
|
81
81
|
|
82
82
|
test 'body should have link to unlock the account' do
|
83
|
-
host = ActionMailer::Base.default_url_options
|
83
|
+
host, port = ActionMailer::Base.default_url_options.values_at :host, :port
|
84
84
|
|
85
|
-
if mail.body.encoded =~ %r{<a href=\"http://#{host}/users/unlock\?unlock_token=([^"]+)">}
|
85
|
+
if mail.body.encoded =~ %r{<a href=\"http://#{host}:#{port}/users/unlock\?unlock_token=([^"]+)">}
|
86
86
|
assert_equal Devise.token_generator.digest(user.class, :unlock_token, $1), user.unlock_token
|
87
87
|
else
|
88
88
|
flunk "expected unlock url regex to match"
|
data/test/mapping_test.rb
CHANGED
@@ -110,12 +110,12 @@ class MappingTest < ActiveSupport::TestCase
|
|
110
110
|
assert mapping.lockable?
|
111
111
|
assert_not mapping.omniauthable?
|
112
112
|
end
|
113
|
-
|
113
|
+
|
114
114
|
test 'find mapping by path' do
|
115
115
|
assert_raise RuntimeError do
|
116
116
|
Devise::Mapping.find_by_path!('/accounts/facebook/callback')
|
117
117
|
end
|
118
|
-
|
118
|
+
|
119
119
|
assert_nothing_raised do
|
120
120
|
Devise::Mapping.find_by_path!('/:locale/accounts/login')
|
121
121
|
end
|
@@ -123,5 +123,5 @@ class MappingTest < ActiveSupport::TestCase
|
|
123
123
|
assert_nothing_raised do
|
124
124
|
Devise::Mapping.find_by_path!('/accounts/facebook/callback', :path)
|
125
125
|
end
|
126
|
-
end
|
126
|
+
end
|
127
127
|
end
|
@@ -6,8 +6,8 @@ class AuthenticatableTest < ActiveSupport::TestCase
|
|
6
6
|
end
|
7
7
|
|
8
8
|
test 'find_first_by_auth_conditions allows custom filtering parameters' do
|
9
|
-
user = User.create!(:
|
10
|
-
assert_equal User.find_first_by_auth_conditions({ :
|
11
|
-
assert_nil User.find_first_by_auth_conditions({ :
|
9
|
+
user = User.create!(email: "example@example.com", password: "1234567")
|
10
|
+
assert_equal User.find_first_by_auth_conditions({ email: "example@example.com" }), user
|
11
|
+
assert_nil User.find_first_by_auth_conditions({ email: "example@example.com" }, id: user.id.to_s.next)
|
12
12
|
end
|
13
13
|
end
|
@@ -82,7 +82,7 @@ class ConfirmableTest < ActiveSupport::TestCase
|
|
82
82
|
|
83
83
|
test 'should send confirmation instructions by email' do
|
84
84
|
assert_email_sent "mynewuser@example.com" do
|
85
|
-
create_user :
|
85
|
+
create_user email: "mynewuser@example.com"
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
@@ -119,23 +119,23 @@ class ConfirmableTest < ActiveSupport::TestCase
|
|
119
119
|
assert_email_not_sent do
|
120
120
|
user = new_user
|
121
121
|
user.email = ''
|
122
|
-
user.save(:
|
122
|
+
user.save(validate: false)
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
126
126
|
test 'should find a user to send confirmation instructions' do
|
127
127
|
user = create_user
|
128
|
-
confirmation_user = User.send_confirmation_instructions(:
|
128
|
+
confirmation_user = User.send_confirmation_instructions(email: user.email)
|
129
129
|
assert_equal confirmation_user, user
|
130
130
|
end
|
131
131
|
|
132
132
|
test 'should return a new user if no email was found' do
|
133
|
-
confirmation_user = User.send_confirmation_instructions(:
|
133
|
+
confirmation_user = User.send_confirmation_instructions(email: "invalid@example.com")
|
134
134
|
assert_not confirmation_user.persisted?
|
135
135
|
end
|
136
136
|
|
137
137
|
test 'should add error to new user email if no email was found' do
|
138
|
-
confirmation_user = User.send_confirmation_instructions(:
|
138
|
+
confirmation_user = User.send_confirmation_instructions(email: "invalid@example.com")
|
139
139
|
assert confirmation_user.errors[:email]
|
140
140
|
assert_equal "not found", confirmation_user.errors[:email].join
|
141
141
|
end
|
@@ -143,7 +143,7 @@ class ConfirmableTest < ActiveSupport::TestCase
|
|
143
143
|
test 'should send email instructions for the user confirm its email' do
|
144
144
|
user = create_user
|
145
145
|
assert_email_sent user.email do
|
146
|
-
User.send_confirmation_instructions(:
|
146
|
+
User.send_confirmation_instructions(email: user.email)
|
147
147
|
end
|
148
148
|
end
|
149
149
|
|
@@ -155,7 +155,7 @@ class ConfirmableTest < ActiveSupport::TestCase
|
|
155
155
|
assert_not_nil user.reload.confirmation_token
|
156
156
|
end
|
157
157
|
|
158
|
-
test 'should not resend email instructions if the user change
|
158
|
+
test 'should not resend email instructions if the user change their email' do
|
159
159
|
user = create_user
|
160
160
|
user.email = 'new_test@example.com'
|
161
161
|
assert_email_not_sent do
|
@@ -183,7 +183,7 @@ class ConfirmableTest < ActiveSupport::TestCase
|
|
183
183
|
end
|
184
184
|
|
185
185
|
test 'confirm time should fallback to devise confirm in default configuration' do
|
186
|
-
swap Devise, :
|
186
|
+
swap Devise, allow_unconfirmed_access_for: 1.day do
|
187
187
|
user = new_user
|
188
188
|
user.confirmation_sent_at = 2.days.ago
|
189
189
|
assert_not user.active_for_authentication?
|
@@ -194,7 +194,7 @@ class ConfirmableTest < ActiveSupport::TestCase
|
|
194
194
|
end
|
195
195
|
|
196
196
|
test 'should be active when confirmation sent at is not overpast' do
|
197
|
-
swap Devise, :
|
197
|
+
swap Devise, allow_unconfirmed_access_for: 5.days do
|
198
198
|
Devise.allow_unconfirmed_access_for = 5.days
|
199
199
|
user = create_user
|
200
200
|
|
@@ -246,17 +246,17 @@ class ConfirmableTest < ActiveSupport::TestCase
|
|
246
246
|
end
|
247
247
|
|
248
248
|
test 'should find a user to send email instructions for the user confirm its email by authentication_keys' do
|
249
|
-
swap Devise, :
|
249
|
+
swap Devise, authentication_keys: [:username, :email] do
|
250
250
|
user = create_user
|
251
|
-
confirm_user = User.send_confirmation_instructions(:
|
251
|
+
confirm_user = User.send_confirmation_instructions(email: user.email, username: user.username)
|
252
252
|
assert_equal confirm_user, user
|
253
253
|
end
|
254
254
|
end
|
255
255
|
|
256
256
|
test 'should require all confirmation_keys' do
|
257
|
-
swap Devise, :
|
257
|
+
swap Devise, confirmation_keys: [:username, :email] do
|
258
258
|
user = create_user
|
259
|
-
confirm_user = User.send_confirmation_instructions(:
|
259
|
+
confirm_user = User.send_confirmation_instructions(email: user.email)
|
260
260
|
assert_not confirm_user.persisted?
|
261
261
|
assert_equal "can't be blank", confirm_user.errors[:username].join
|
262
262
|
end
|
@@ -275,13 +275,13 @@ class ConfirmableTest < ActiveSupport::TestCase
|
|
275
275
|
end
|
276
276
|
|
277
277
|
test 'should accept confirmation email token after 2 days when expiration is set to 3 days' do
|
278
|
-
swap Devise, :
|
278
|
+
swap Devise, confirm_within: 3.days do
|
279
279
|
assert confirm_user_by_token_with_confirmation_sent_at(2.days.ago)
|
280
280
|
end
|
281
281
|
end
|
282
282
|
|
283
283
|
test 'should not accept confirmation email token after 4 days when expiration is set to 3 days' do
|
284
|
-
swap Devise, :
|
284
|
+
swap Devise, confirm_within: 3.days do
|
285
285
|
assert_not confirm_user_by_token_with_confirmation_sent_at(4.days.ago)
|
286
286
|
end
|
287
287
|
end
|
@@ -327,7 +327,7 @@ class ReconfirmableTest < ActiveSupport::TestCase
|
|
327
327
|
admin = create_admin
|
328
328
|
assert admin.confirm!
|
329
329
|
assert_nil admin.confirmation_token
|
330
|
-
assert admin.update_attributes(:
|
330
|
+
assert admin.update_attributes(email: 'new_test@example.com')
|
331
331
|
assert_not_nil admin.confirmation_token
|
332
332
|
end
|
333
333
|
|
@@ -335,7 +335,7 @@ class ReconfirmableTest < ActiveSupport::TestCase
|
|
335
335
|
admin = create_admin
|
336
336
|
assert admin.confirm!
|
337
337
|
admin.skip_reconfirmation!
|
338
|
-
assert admin.update_attributes(:
|
338
|
+
assert admin.update_attributes(email: 'new_test@example.com')
|
339
339
|
assert_nil admin.confirmation_token
|
340
340
|
end
|
341
341
|
|
@@ -344,16 +344,16 @@ class ReconfirmableTest < ActiveSupport::TestCase
|
|
344
344
|
admin.skip_confirmation_notification!
|
345
345
|
|
346
346
|
assert_email_not_sent do
|
347
|
-
admin.update_attributes(:
|
347
|
+
admin.update_attributes(email: 'new_test@example.com')
|
348
348
|
end
|
349
349
|
end
|
350
350
|
|
351
351
|
test 'should regenerate confirmation token after changing email' do
|
352
352
|
admin = create_admin
|
353
353
|
assert admin.confirm!
|
354
|
-
assert admin.update_attributes(:
|
354
|
+
assert admin.update_attributes(email: 'old_test@example.com')
|
355
355
|
token = admin.confirmation_token
|
356
|
-
assert admin.update_attributes(:
|
356
|
+
assert admin.update_attributes(email: 'new_test@example.com')
|
357
357
|
assert_not_equal token, admin.confirmation_token
|
358
358
|
end
|
359
359
|
|
@@ -361,7 +361,7 @@ class ReconfirmableTest < ActiveSupport::TestCase
|
|
361
361
|
admin = create_admin
|
362
362
|
assert admin.confirm!
|
363
363
|
assert_email_sent "new_test@example.com" do
|
364
|
-
assert admin.update_attributes(:
|
364
|
+
assert admin.update_attributes(email: 'new_test@example.com')
|
365
365
|
end
|
366
366
|
assert_match "new_test@example.com", ActionMailer::Base.deliveries.last.body.encoded
|
367
367
|
end
|
@@ -370,7 +370,7 @@ class ReconfirmableTest < ActiveSupport::TestCase
|
|
370
370
|
admin = create_admin
|
371
371
|
assert admin.confirm!
|
372
372
|
assert_email_not_sent do
|
373
|
-
assert admin.update_attributes(:
|
373
|
+
assert admin.update_attributes(password: 'newpass', password_confirmation: 'newpass')
|
374
374
|
end
|
375
375
|
end
|
376
376
|
|
@@ -379,21 +379,21 @@ class ReconfirmableTest < ActiveSupport::TestCase
|
|
379
379
|
assert admin.confirm!
|
380
380
|
assert_email_not_sent do
|
381
381
|
admin.email = ''
|
382
|
-
admin.save(:
|
382
|
+
admin.save(validate: false)
|
383
383
|
end
|
384
384
|
end
|
385
385
|
|
386
386
|
test 'should stay confirmed when email is changed' do
|
387
387
|
admin = create_admin
|
388
388
|
assert admin.confirm!
|
389
|
-
assert admin.update_attributes(:
|
389
|
+
assert admin.update_attributes(email: 'new_test@example.com')
|
390
390
|
assert admin.confirmed?
|
391
391
|
end
|
392
392
|
|
393
393
|
test 'should update email only when it is confirmed' do
|
394
394
|
admin = create_admin
|
395
395
|
assert admin.confirm!
|
396
|
-
assert admin.update_attributes(:
|
396
|
+
assert admin.update_attributes(email: 'new_test@example.com')
|
397
397
|
assert_not_equal 'new_test@example.com', admin.email
|
398
398
|
assert admin.confirm!
|
399
399
|
assert_equal 'new_test@example.com', admin.email
|
@@ -402,27 +402,27 @@ class ReconfirmableTest < ActiveSupport::TestCase
|
|
402
402
|
test 'should not allow admin to get past confirmation email by resubmitting their new address' do
|
403
403
|
admin = create_admin
|
404
404
|
assert admin.confirm!
|
405
|
-
assert admin.update_attributes(:
|
405
|
+
assert admin.update_attributes(email: 'new_test@example.com')
|
406
406
|
assert_not_equal 'new_test@example.com', admin.email
|
407
|
-
assert admin.update_attributes(:
|
407
|
+
assert admin.update_attributes(email: 'new_test@example.com')
|
408
408
|
assert_not_equal 'new_test@example.com', admin.email
|
409
409
|
end
|
410
410
|
|
411
411
|
test 'should find a admin by send confirmation instructions with unconfirmed_email' do
|
412
412
|
admin = create_admin
|
413
413
|
assert admin.confirm!
|
414
|
-
assert admin.update_attributes(:
|
415
|
-
confirmation_admin = Admin.send_confirmation_instructions(:
|
414
|
+
assert admin.update_attributes(email: 'new_test@example.com')
|
415
|
+
confirmation_admin = Admin.send_confirmation_instructions(email: admin.unconfirmed_email)
|
416
416
|
assert_equal confirmation_admin, admin
|
417
417
|
end
|
418
418
|
|
419
419
|
test 'should return a new admin if no email or unconfirmed_email was found' do
|
420
|
-
confirmation_admin = Admin.send_confirmation_instructions(:
|
420
|
+
confirmation_admin = Admin.send_confirmation_instructions(email: "invalid@email.com")
|
421
421
|
assert_not confirmation_admin.persisted?
|
422
422
|
end
|
423
423
|
|
424
424
|
test 'should add error to new admin email if no email or unconfirmed_email was found' do
|
425
|
-
confirmation_admin = Admin.send_confirmation_instructions(:
|
425
|
+
confirmation_admin = Admin.send_confirmation_instructions(email: "invalid@email.com")
|
426
426
|
assert confirmation_admin.errors[:email]
|
427
427
|
assert_equal "not found", confirmation_admin.errors[:email].join
|
428
428
|
end
|
@@ -431,7 +431,7 @@ class ReconfirmableTest < ActiveSupport::TestCase
|
|
431
431
|
admin = create_admin
|
432
432
|
admin.unconfirmed_email = "new_test@email.com"
|
433
433
|
assert admin.save
|
434
|
-
admin = Admin.find_by_unconfirmed_email_with_errors(:
|
434
|
+
admin = Admin.find_by_unconfirmed_email_with_errors(email: "new_test@email.com")
|
435
435
|
assert admin.persisted?
|
436
436
|
end
|
437
437
|
|
@@ -6,7 +6,7 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
|
|
6
6
|
test 'should downcase case insensitive keys when saving' do
|
7
7
|
# case_insensitive_keys is set to :email by default.
|
8
8
|
email = 'Foo@Bar.com'
|
9
|
-
user = new_user(:
|
9
|
+
user = new_user(email: email)
|
10
10
|
|
11
11
|
assert_equal email, user.email
|
12
12
|
user.save!
|
@@ -16,7 +16,7 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
|
|
16
16
|
test 'should downcase case insensitive keys that refer to virtual attributes when saving' do
|
17
17
|
email = 'Foo@Bar1.com'
|
18
18
|
confirmation = 'Foo@Bar1.com'
|
19
|
-
attributes = valid_attributes(:
|
19
|
+
attributes = valid_attributes(email: email, email_confirmation: confirmation)
|
20
20
|
user = UserWithVirtualAttributes.new(attributes)
|
21
21
|
|
22
22
|
assert_equal confirmation, user.email_confirmation
|
@@ -27,7 +27,7 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
|
|
27
27
|
test 'should not mutate value assigned to case insensitive key' do
|
28
28
|
email = 'Foo@Bar.com'
|
29
29
|
original_email = email.dup
|
30
|
-
user = new_user(:
|
30
|
+
user = new_user(email: email)
|
31
31
|
|
32
32
|
user.save!
|
33
33
|
assert_equal original_email, email
|
@@ -36,7 +36,7 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
|
|
36
36
|
test 'should remove whitespace from strip whitespace keys when saving' do
|
37
37
|
# strip_whitespace_keys is set to :email by default.
|
38
38
|
email = ' foo@bar.com '
|
39
|
-
user = new_user(:
|
39
|
+
user = new_user(email: email)
|
40
40
|
|
41
41
|
assert_equal email, user.email
|
42
42
|
user.save!
|
@@ -46,20 +46,20 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
|
|
46
46
|
test 'should not mutate value assigned to string whitespace key' do
|
47
47
|
email = ' foo@bar.com '
|
48
48
|
original_email = email.dup
|
49
|
-
user = new_user(:
|
49
|
+
user = new_user(email: email)
|
50
50
|
|
51
51
|
user.save!
|
52
52
|
assert_equal original_email, email
|
53
53
|
end
|
54
54
|
|
55
55
|
test "doesn't throw exception when globally configured strip_whitespace_keys are not present on a model" do
|
56
|
-
swap Devise, :
|
56
|
+
swap Devise, strip_whitespace_keys: [:fake_key] do
|
57
57
|
assert_nothing_raised { create_user }
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
61
|
test "doesn't throw exception when globally configured case_insensitive_keys are not present on a model" do
|
62
|
-
swap Devise, :
|
62
|
+
swap Devise, case_insensitive_keys: [:fake_key] do
|
63
63
|
assert_nothing_raised { create_user }
|
64
64
|
end
|
65
65
|
end
|
@@ -93,6 +93,11 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
|
|
93
93
|
assert_present user.encrypted_password
|
94
94
|
end
|
95
95
|
|
96
|
+
test 'should support custom encryption methods' do
|
97
|
+
user = UserWithCustomEncryption.new(password: '654321')
|
98
|
+
assert_equal user.encrypted_password, '123456'
|
99
|
+
end
|
100
|
+
|
96
101
|
test 'allow authenticatable_salt to work even with nil encrypted password' do
|
97
102
|
user = User.new
|
98
103
|
user.encrypted_password = nil
|
@@ -100,8 +105,8 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
|
|
100
105
|
end
|
101
106
|
|
102
107
|
test 'should not generate encrypted password if password is blank' do
|
103
|
-
assert_blank new_user(:
|
104
|
-
assert_blank new_user(:
|
108
|
+
assert_blank new_user(password: nil).encrypted_password
|
109
|
+
assert_blank new_user(password: '').encrypted_password
|
105
110
|
end
|
106
111
|
|
107
112
|
test 'should encrypt password again if password has changed' do
|
@@ -136,23 +141,23 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
|
|
136
141
|
|
137
142
|
test 'should update password with valid current password' do
|
138
143
|
user = create_user
|
139
|
-
assert user.update_with_password(:
|
140
|
-
:
|
144
|
+
assert user.update_with_password(current_password: '12345678',
|
145
|
+
password: 'pass4321', password_confirmation: 'pass4321')
|
141
146
|
assert user.reload.valid_password?('pass4321')
|
142
147
|
end
|
143
148
|
|
144
149
|
test 'should add an error to current password when it is invalid' do
|
145
150
|
user = create_user
|
146
|
-
assert_not user.update_with_password(:
|
147
|
-
:
|
151
|
+
assert_not user.update_with_password(current_password: 'other',
|
152
|
+
password: 'pass4321', password_confirmation: 'pass4321')
|
148
153
|
assert user.reload.valid_password?('12345678')
|
149
154
|
assert_match "is invalid", user.errors[:current_password].join
|
150
155
|
end
|
151
156
|
|
152
157
|
test 'should add an error to current password when it is blank' do
|
153
158
|
user = create_user
|
154
|
-
assert_not user.update_with_password(:
|
155
|
-
:
|
159
|
+
assert_not user.update_with_password(password: 'pass4321',
|
160
|
+
password_confirmation: 'pass4321')
|
156
161
|
assert user.reload.valid_password?('12345678')
|
157
162
|
assert_match "can't be blank", user.errors[:current_password].join
|
158
163
|
end
|
@@ -161,41 +166,41 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
|
|
161
166
|
user = UserWithValidation.create!(valid_attributes)
|
162
167
|
user.save
|
163
168
|
assert user.persisted?
|
164
|
-
assert_not user.update_with_password(:
|
169
|
+
assert_not user.update_with_password(username: "")
|
165
170
|
assert_match "usertest", user.reload.username
|
166
171
|
assert_match "can't be blank", user.errors[:username].join
|
167
172
|
end
|
168
173
|
|
169
174
|
test 'should ignore password and its confirmation if they are blank' do
|
170
175
|
user = create_user
|
171
|
-
assert user.update_with_password(:
|
176
|
+
assert user.update_with_password(current_password: '12345678', email: "new@example.com")
|
172
177
|
assert_equal "new@example.com", user.email
|
173
178
|
end
|
174
179
|
|
175
180
|
test 'should not update password with invalid confirmation' do
|
176
181
|
user = create_user
|
177
|
-
assert_not user.update_with_password(:
|
178
|
-
:
|
182
|
+
assert_not user.update_with_password(current_password: '12345678',
|
183
|
+
password: 'pass4321', password_confirmation: 'other')
|
179
184
|
assert user.reload.valid_password?('12345678')
|
180
185
|
end
|
181
186
|
|
182
187
|
test 'should clean up password fields on failure' do
|
183
188
|
user = create_user
|
184
|
-
assert_not user.update_with_password(:
|
185
|
-
:
|
189
|
+
assert_not user.update_with_password(current_password: '12345678',
|
190
|
+
password: 'pass4321', password_confirmation: 'other')
|
186
191
|
assert user.password.blank?
|
187
192
|
assert user.password_confirmation.blank?
|
188
193
|
end
|
189
194
|
|
190
195
|
test 'should update the user without password' do
|
191
196
|
user = create_user
|
192
|
-
user.update_without_password(:
|
197
|
+
user.update_without_password(email: 'new@example.com')
|
193
198
|
assert_equal 'new@example.com', user.email
|
194
199
|
end
|
195
200
|
|
196
201
|
test 'should not update password without password' do
|
197
202
|
user = create_user
|
198
|
-
user.update_without_password(:
|
203
|
+
user.update_without_password(password: 'pass4321', password_confirmation: 'pass4321')
|
199
204
|
assert !user.reload.valid_password?('pass4321')
|
200
205
|
assert user.valid_password?('12345678')
|
201
206
|
end
|
@@ -221,12 +226,12 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
|
|
221
226
|
end
|
222
227
|
|
223
228
|
test 'downcase_keys with validation' do
|
224
|
-
User.create(:
|
225
|
-
user = User.create(:
|
229
|
+
User.create(email: "HEllO@example.com", password: "123456")
|
230
|
+
user = User.create(email: "HEllO@example.com", password: "123456")
|
226
231
|
assert !user.valid?
|
227
232
|
end
|
228
233
|
|
229
|
-
test '
|
234
|
+
test 'required_fields should be encryptable_password and the email field by default' do
|
230
235
|
assert_same_content Devise::Models::DatabaseAuthenticatable.required_fields(User), [
|
231
236
|
:email,
|
232
237
|
:encrypted_password
|
@@ -234,7 +239,7 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
|
|
234
239
|
end
|
235
240
|
|
236
241
|
test 'required_fields should be encryptable_password and the login when the login is on authentication_keys' do
|
237
|
-
swap Devise, :
|
242
|
+
swap Devise, authentication_keys: [:login] do
|
238
243
|
assert_same_content Devise::Models::DatabaseAuthenticatable.required_fields(User), [
|
239
244
|
:encrypted_password,
|
240
245
|
:login
|