devise 1.0.10 → 1.1.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.
- data/CHANGELOG.rdoc +62 -10
- data/Gemfile +23 -0
- data/Gemfile.lock +118 -0
- data/README.rdoc +116 -77
- data/Rakefile +4 -2
- data/TODO +3 -2
- data/app/controllers/{confirmations_controller.rb → devise/confirmations_controller.rb} +1 -1
- data/app/controllers/{passwords_controller.rb → devise/passwords_controller.rb} +1 -1
- data/app/controllers/{registrations_controller.rb → devise/registrations_controller.rb} +12 -8
- data/app/controllers/devise/sessions_controller.rb +23 -0
- data/app/controllers/{unlocks_controller.rb → devise/unlocks_controller.rb} +1 -8
- data/app/helpers/devise_helper.rb +17 -0
- data/app/mailers/devise/mailer.rb +71 -0
- data/app/views/devise/confirmations/new.html.erb +12 -0
- data/app/views/devise/passwords/edit.html.erb +16 -0
- data/app/views/devise/passwords/new.html.erb +12 -0
- data/app/views/devise/registrations/edit.html.erb +25 -0
- data/app/views/devise/registrations/new.html.erb +18 -0
- data/app/views/devise/sessions/new.html.erb +17 -0
- data/app/views/devise/shared/_links.erb +19 -0
- data/app/views/devise/unlocks/new.html.erb +12 -0
- data/{lib/devise → config}/locales/en.yml +16 -12
- data/lib/devise/controllers/helpers.rb +57 -52
- data/lib/devise/controllers/internal_helpers.rb +19 -50
- data/lib/devise/controllers/scoped_views.rb +35 -0
- data/lib/devise/controllers/url_helpers.rb +1 -1
- data/lib/devise/encryptors/authlogic_sha512.rb +0 -2
- data/lib/devise/encryptors/base.rb +1 -1
- data/lib/devise/encryptors/bcrypt.rb +2 -4
- data/lib/devise/encryptors/clearance_sha1.rb +0 -2
- data/lib/devise/encryptors/sha1.rb +6 -8
- data/lib/devise/encryptors/sha512.rb +6 -8
- data/lib/devise/failure_app.rb +76 -39
- data/lib/devise/hooks/activatable.rb +6 -10
- data/lib/devise/hooks/forgetable.rb +11 -0
- data/lib/devise/hooks/rememberable.rb +40 -30
- data/lib/devise/hooks/timeoutable.rb +7 -3
- data/lib/devise/hooks/trackable.rb +5 -14
- data/lib/devise/mapping.rb +35 -62
- data/lib/devise/models/authenticatable.rb +126 -0
- data/lib/devise/models/confirmable.rb +19 -22
- data/lib/devise/models/database_authenticatable.rb +26 -60
- data/lib/devise/models/lockable.rb +43 -28
- data/lib/devise/models/recoverable.rb +11 -10
- data/lib/devise/models/rememberable.rb +56 -26
- data/lib/devise/models/timeoutable.rb +1 -3
- data/lib/devise/models/token_authenticatable.rb +14 -43
- data/lib/devise/models/trackable.rb +14 -0
- data/lib/devise/models/validatable.rb +16 -2
- data/lib/devise/models.rb +16 -53
- data/lib/devise/modules.rb +23 -0
- data/lib/devise/orm/active_record.rb +10 -15
- data/lib/devise/orm/mongoid.rb +29 -0
- data/lib/devise/path_checker.rb +18 -0
- data/lib/devise/rails/routes.rb +232 -117
- data/lib/devise/rails/warden_compat.rb +18 -39
- data/lib/devise/rails.rb +64 -9
- data/lib/devise/schema.rb +47 -23
- data/lib/devise/strategies/authenticatable.rb +123 -0
- data/lib/devise/strategies/base.rb +2 -3
- data/lib/devise/strategies/database_authenticatable.rb +7 -22
- data/lib/devise/strategies/rememberable.rb +21 -7
- data/lib/devise/strategies/token_authenticatable.rb +31 -19
- data/lib/devise/test_helpers.rb +6 -6
- data/lib/devise/version.rb +1 -1
- data/lib/devise.rb +174 -157
- data/lib/generators/active_record/devise_generator.rb +28 -0
- data/{generators/devise → lib/generators/active_record}/templates/migration.rb +9 -3
- data/lib/generators/devise/devise_generator.rb +17 -0
- data/lib/generators/devise/install_generator.rb +24 -0
- data/lib/generators/devise/orm_helpers.rb +23 -0
- data/{generators/devise_install → lib/generators/devise}/templates/README +9 -7
- data/lib/generators/devise/templates/devise.rb +142 -0
- data/lib/generators/devise/views_generator.rb +63 -0
- data/lib/generators/devise_install_generator.rb +4 -0
- data/lib/generators/devise_views_generator.rb +4 -0
- data/lib/generators/mongoid/devise_generator.rb +17 -0
- data/test/controllers/helpers_test.rb +48 -19
- data/test/controllers/internal_helpers_test.rb +12 -16
- data/test/controllers/url_helpers_test.rb +21 -10
- data/test/devise_test.rb +16 -25
- data/test/encryptors_test.rb +2 -3
- data/test/failure_app_test.rb +106 -27
- data/test/integration/authenticatable_test.rb +138 -126
- data/test/integration/confirmable_test.rb +22 -15
- data/test/integration/database_authenticatable_test.rb +38 -0
- data/test/integration/http_authenticatable_test.rb +9 -12
- data/test/integration/lockable_test.rb +22 -15
- data/test/integration/recoverable_test.rb +6 -6
- data/test/integration/registerable_test.rb +42 -33
- data/test/integration/rememberable_test.rb +84 -22
- data/test/integration/timeoutable_test.rb +16 -4
- data/test/integration/token_authenticatable_test.rb +45 -12
- data/test/integration/trackable_test.rb +1 -1
- data/test/mailers/confirmation_instructions_test.rb +11 -17
- data/test/mailers/reset_password_instructions_test.rb +7 -7
- data/test/mailers/unlock_instructions_test.rb +7 -7
- data/test/mapping_test.rb +22 -95
- data/test/models/confirmable_test.rb +12 -19
- data/test/models/{authenticatable_test.rb → database_authenticatable_test.rb} +24 -56
- data/test/models/lockable_test.rb +32 -46
- data/test/models/recoverable_test.rb +7 -7
- data/test/models/rememberable_test.rb +118 -35
- data/test/models/timeoutable_test.rb +1 -1
- data/test/models/token_authenticatable_test.rb +5 -19
- data/test/models/trackable_test.rb +1 -1
- data/test/models/validatable_test.rb +20 -27
- data/test/models_test.rb +12 -5
- data/test/orm/active_record.rb +1 -23
- data/test/orm/mongoid.rb +10 -0
- data/test/rails_app/app/active_record/admin.rb +1 -5
- data/test/rails_app/app/active_record/shim.rb +2 -0
- data/test/rails_app/app/active_record/user.rb +3 -3
- data/test/rails_app/app/controllers/application_controller.rb +2 -5
- data/test/rails_app/app/controllers/home_controller.rb +3 -0
- data/test/rails_app/app/controllers/publisher/registrations_controller.rb +2 -0
- data/test/rails_app/app/controllers/publisher/sessions_controller.rb +2 -0
- data/test/rails_app/app/controllers/sessions_controller.rb +6 -0
- data/test/rails_app/app/controllers/users_controller.rb +7 -5
- data/test/rails_app/app/mongoid/admin.rb +6 -0
- data/test/rails_app/app/mongoid/shim.rb +16 -0
- data/test/rails_app/app/mongoid/user.rb +10 -0
- data/test/rails_app/config/application.rb +35 -0
- data/test/rails_app/config/boot.rb +10 -107
- data/test/rails_app/config/environment.rb +4 -41
- data/test/rails_app/config/environments/development.rb +15 -13
- data/test/rails_app/config/environments/production.rb +25 -20
- data/test/rails_app/config/environments/test.rb +33 -28
- data/test/rails_app/config/initializers/backtrace_silencers.rb +7 -0
- data/test/rails_app/config/initializers/devise.rb +95 -38
- data/test/rails_app/config/initializers/secret_token.rb +2 -0
- data/test/rails_app/config/routes.rb +47 -25
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +27 -0
- data/test/rails_app/db/schema.rb +86 -0
- data/test/routes_test.rb +62 -47
- data/test/support/{assertions_helper.rb → assertions.rb} +2 -15
- data/test/support/{tests_helper.rb → helpers.rb} +18 -3
- data/test/support/{integration_tests_helper.rb → integration.rb} +24 -7
- data/test/support/webrat/integrations/rails.rb +32 -0
- data/test/test_helper.rb +11 -11
- data/test/test_helpers_test.rb +30 -15
- metadata +105 -64
- data/app/controllers/sessions_controller.rb +0 -42
- data/app/models/devise_mailer.rb +0 -68
- data/app/views/confirmations/new.html.erb +0 -12
- data/app/views/passwords/edit.html.erb +0 -16
- data/app/views/passwords/new.html.erb +0 -12
- data/app/views/registrations/edit.html.erb +0 -25
- data/app/views/registrations/new.html.erb +0 -17
- data/app/views/sessions/new.html.erb +0 -17
- data/app/views/shared/_devise_links.erb +0 -19
- data/app/views/unlocks/new.html.erb +0 -12
- data/generators/devise/USAGE +0 -5
- data/generators/devise/devise_generator.rb +0 -15
- data/generators/devise/lib/route_devise.rb +0 -32
- data/generators/devise/templates/model.rb +0 -9
- data/generators/devise_install/USAGE +0 -3
- data/generators/devise_install/devise_install_generator.rb +0 -15
- data/generators/devise_install/templates/devise.rb +0 -105
- data/generators/devise_views/USAGE +0 -3
- data/generators/devise_views/devise_views_generator.rb +0 -21
- data/lib/devise/models/activatable.rb +0 -16
- data/lib/devise/models/http_authenticatable.rb +0 -23
- data/lib/devise/orm/data_mapper.rb +0 -83
- data/lib/devise/orm/mongo_mapper.rb +0 -52
- data/lib/devise/strategies/http_authenticatable.rb +0 -59
- data/rails/init.rb +0 -2
- data/test/integration/rack_middleware_test.rb +0 -47
- data/test/orm/mongo_mapper.rb +0 -20
- data/test/rails_app/app/mongo_mapper/admin.rb +0 -13
- data/test/rails_app/app/mongo_mapper/user.rb +0 -14
- data/test/rails_app/config/initializers/new_rails_defaults.rb +0 -24
- data/test/rails_app/config/initializers/session_store.rb +0 -15
- /data/app/views/{devise_mailer → devise/mailer}/confirmation_instructions.html.erb +0 -0
- /data/app/views/{devise_mailer → devise/mailer}/reset_password_instructions.html.erb +0 -0
- /data/app/views/{devise_mailer → devise/mailer}/unlock_instructions.html.erb +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require '
|
|
1
|
+
require 'test_helper'
|
|
2
2
|
|
|
3
3
|
class ConfirmationInstructionsTest < ActionMailer::TestCase
|
|
4
4
|
|
|
@@ -23,7 +23,7 @@ class ConfirmationInstructionsTest < ActionMailer::TestCase
|
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
test 'content type should be set to html' do
|
|
26
|
-
|
|
26
|
+
assert mail.content_type.include?('text/html')
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
test 'send confirmation instructions to the user email' do
|
|
@@ -36,50 +36,44 @@ class ConfirmationInstructionsTest < ActionMailer::TestCase
|
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
test 'setup subject from I18n' do
|
|
39
|
-
store_translations :en, :devise => { :mailer => { :confirmation_instructions => 'Account Confirmation' } } do
|
|
39
|
+
store_translations :en, :devise => { :mailer => { :confirmation_instructions => { :subject => 'Account Confirmation' } } } do
|
|
40
40
|
assert_equal 'Account Confirmation', mail.subject
|
|
41
41
|
end
|
|
42
42
|
end
|
|
43
43
|
|
|
44
44
|
test 'subject namespaced by model' do
|
|
45
|
-
store_translations :en, :devise => { :mailer => { :
|
|
45
|
+
store_translations :en, :devise => { :mailer => { :confirmation_instructions => { :user_subject => 'User Account Confirmation' } } } do
|
|
46
46
|
assert_equal 'User Account Confirmation', mail.subject
|
|
47
47
|
end
|
|
48
48
|
end
|
|
49
49
|
|
|
50
50
|
test 'body should have user info' do
|
|
51
|
-
assert_match /#{user.email}/, mail.body
|
|
51
|
+
assert_match /#{user.email}/, mail.body.encoded
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
test 'body should have link to confirm the account' do
|
|
55
55
|
host = ActionMailer::Base.default_url_options[:host]
|
|
56
56
|
confirmation_url_regexp = %r{<a href=\"http://#{host}/users/confirmation\?confirmation_token=#{user.confirmation_token}">}
|
|
57
|
-
assert_match confirmation_url_regexp, mail.body
|
|
57
|
+
assert_match confirmation_url_regexp, mail.body.encoded
|
|
58
58
|
end
|
|
59
59
|
|
|
60
60
|
test 'renders a scoped if scoped_views is set to true' do
|
|
61
61
|
swap Devise, :scoped_views => true do
|
|
62
|
-
assert_equal user.email, mail.body
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
test 'content type should be set to plain when manually configured' do
|
|
67
|
-
swap Devise, :mailer_content_type => "text/plain" do
|
|
68
|
-
assert_equal "text/plain", mail.content_type
|
|
62
|
+
assert_equal user.email, mail.body.decoded
|
|
69
63
|
end
|
|
70
64
|
end
|
|
71
65
|
|
|
72
66
|
test 'renders a scoped if scoped_views is set in the mailer class' do
|
|
73
67
|
begin
|
|
74
|
-
|
|
75
|
-
assert_equal user.email, mail.body
|
|
68
|
+
Devise::Mailer.scoped_views = true
|
|
69
|
+
assert_equal user.email, mail.body.decoded
|
|
76
70
|
ensure
|
|
77
|
-
|
|
71
|
+
Devise::Mailer.send :remove_instance_variable, :@scoped_views
|
|
78
72
|
end
|
|
79
73
|
end
|
|
80
74
|
|
|
81
75
|
test 'mailer sender accepts a proc' do
|
|
82
|
-
swap Devise, :mailer_sender =>
|
|
76
|
+
swap Devise, :mailer_sender => proc { "another@example.com" } do
|
|
83
77
|
assert_equal ['another@example.com'], mail.from
|
|
84
78
|
end
|
|
85
79
|
end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require '
|
|
1
|
+
require 'test_helper'
|
|
2
2
|
|
|
3
3
|
class ResetPasswordInstructionsTest < ActionMailer::TestCase
|
|
4
4
|
|
|
@@ -27,7 +27,7 @@ class ResetPasswordInstructionsTest < ActionMailer::TestCase
|
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
test 'content type should be set to html' do
|
|
30
|
-
|
|
30
|
+
assert mail.content_type.include?('text/html')
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
test 'send confirmation instructions to the user email' do
|
|
@@ -39,29 +39,29 @@ class ResetPasswordInstructionsTest < ActionMailer::TestCase
|
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
test 'setup subject from I18n' do
|
|
42
|
-
store_translations :en, :devise => { :mailer => { :reset_password_instructions => 'Reset instructions' } } do
|
|
42
|
+
store_translations :en, :devise => { :mailer => { :reset_password_instructions => { :subject => 'Reset instructions' } } } do
|
|
43
43
|
assert_equal 'Reset instructions', mail.subject
|
|
44
44
|
end
|
|
45
45
|
end
|
|
46
46
|
|
|
47
47
|
test 'subject namespaced by model' do
|
|
48
|
-
store_translations :en, :devise => { :mailer => { :
|
|
48
|
+
store_translations :en, :devise => { :mailer => { :reset_password_instructions => { :user_subject => 'User Reset Instructions' } } } do
|
|
49
49
|
assert_equal 'User Reset Instructions', mail.subject
|
|
50
50
|
end
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
test 'body should have user info' do
|
|
54
|
-
assert_match
|
|
54
|
+
assert_match(/#{user.email}/, mail.body.encoded)
|
|
55
55
|
end
|
|
56
56
|
|
|
57
57
|
test 'body should have link to confirm the account' do
|
|
58
58
|
host = ActionMailer::Base.default_url_options[:host]
|
|
59
59
|
reset_url_regexp = %r{<a href=\"http://#{host}/users/password/edit\?reset_password_token=#{user.reset_password_token}">}
|
|
60
|
-
assert_match reset_url_regexp, mail.body
|
|
60
|
+
assert_match reset_url_regexp, mail.body.encoded
|
|
61
61
|
end
|
|
62
62
|
|
|
63
63
|
test 'mailer sender accepts a proc' do
|
|
64
|
-
swap Devise, :mailer_sender =>
|
|
64
|
+
swap Devise, :mailer_sender => proc { "another@example.com" } do
|
|
65
65
|
assert_equal ['another@example.com'], mail.from
|
|
66
66
|
end
|
|
67
67
|
end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require '
|
|
1
|
+
require 'test_helper'
|
|
2
2
|
|
|
3
3
|
class UnlockInstructionsTest < ActionMailer::TestCase
|
|
4
4
|
|
|
@@ -27,7 +27,7 @@ class UnlockInstructionsTest < ActionMailer::TestCase
|
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
test 'content type should be set to html' do
|
|
30
|
-
|
|
30
|
+
assert mail.content_type.include?('text/html')
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
test 'send unlock instructions to the user email' do
|
|
@@ -39,24 +39,24 @@ class UnlockInstructionsTest < ActionMailer::TestCase
|
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
test 'setup subject from I18n' do
|
|
42
|
-
store_translations :en, :devise => { :mailer => { :unlock_instructions => '
|
|
43
|
-
assert_equal '
|
|
42
|
+
store_translations :en, :devise => { :mailer => { :unlock_instructions => { :subject => 'Yo unlock instructions' } } } do
|
|
43
|
+
assert_equal 'Yo unlock instructions', mail.subject
|
|
44
44
|
end
|
|
45
45
|
end
|
|
46
46
|
|
|
47
47
|
test 'subject namespaced by model' do
|
|
48
|
-
store_translations :en, :devise => { :mailer => { :
|
|
48
|
+
store_translations :en, :devise => { :mailer => { :unlock_instructions => { :user_subject => 'User Unlock Instructions' } } } do
|
|
49
49
|
assert_equal 'User Unlock Instructions', mail.subject
|
|
50
50
|
end
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
test 'body should have user info' do
|
|
54
|
-
assert_match
|
|
54
|
+
assert_match(/#{user.email}/, mail.body.encoded)
|
|
55
55
|
end
|
|
56
56
|
|
|
57
57
|
test 'body should have link to unlock the account' do
|
|
58
58
|
host = ActionMailer::Base.default_url_options[:host]
|
|
59
59
|
unlock_url_regexp = %r{<a href=\"http://#{host}/users/unlock\?unlock_token=#{user.unlock_token}">}
|
|
60
|
-
assert_match unlock_url_regexp, mail.body
|
|
60
|
+
assert_match unlock_url_regexp, mail.body.encoded
|
|
61
61
|
end
|
|
62
62
|
end
|
data/test/mapping_test.rb
CHANGED
|
@@ -1,42 +1,33 @@
|
|
|
1
|
-
require '
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class FakeRequest < Struct.new(:path_info, :params)
|
|
4
|
+
end
|
|
2
5
|
|
|
3
6
|
class MappingTest < ActiveSupport::TestCase
|
|
7
|
+
def fake_request(path, params={})
|
|
8
|
+
FakeRequest.new(path, params)
|
|
9
|
+
end
|
|
4
10
|
|
|
5
11
|
test 'store options' do
|
|
6
12
|
mapping = Devise.mappings[:user]
|
|
7
|
-
|
|
8
13
|
assert_equal User, mapping.to
|
|
9
|
-
assert_equal User.devise_modules, mapping.
|
|
10
|
-
assert_equal :users, mapping.
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
test 'allows as to be given' do
|
|
14
|
-
assert_equal :admin_area, Devise.mappings[:admin].as
|
|
14
|
+
assert_equal User.devise_modules, mapping.modules
|
|
15
|
+
assert_equal :users, mapping.plural
|
|
16
|
+
assert_equal :user, mapping.singular
|
|
17
|
+
assert_equal "users", mapping.path
|
|
15
18
|
end
|
|
16
19
|
|
|
17
|
-
test '
|
|
18
|
-
assert_equal
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
test 'allows a controller depending on the mapping' do
|
|
22
|
-
mapping = Devise.mappings[:user]
|
|
23
|
-
assert mapping.allows?(:sessions)
|
|
24
|
-
assert mapping.allows?(:confirmations)
|
|
25
|
-
assert mapping.allows?(:passwords)
|
|
26
|
-
|
|
27
|
-
mapping = Devise.mappings[:admin]
|
|
28
|
-
assert mapping.allows?(:sessions)
|
|
29
|
-
assert_not mapping.allows?(:confirmations)
|
|
30
|
-
assert_not mapping.allows?(:passwords)
|
|
20
|
+
test 'allows path to be given' do
|
|
21
|
+
assert_equal "admin_area", Devise.mappings[:admin].path
|
|
31
22
|
end
|
|
32
23
|
|
|
33
|
-
test '
|
|
34
|
-
|
|
35
|
-
assert_equal Devise.mappings[:user], Devise::Mapping.find_by_path("/users/session")
|
|
24
|
+
test 'allows custom singular to be given' do
|
|
25
|
+
assert_equal "accounts", Devise.mappings[:manager].path
|
|
36
26
|
end
|
|
37
27
|
|
|
38
|
-
test '
|
|
39
|
-
assert_equal
|
|
28
|
+
test 'has strategies depending on the model declaration' do
|
|
29
|
+
assert_equal [:rememberable, :token_authenticatable, :database_authenticatable], Devise.mappings[:user].strategies
|
|
30
|
+
assert_equal [:database_authenticatable], Devise.mappings[:admin].strategies
|
|
40
31
|
end
|
|
41
32
|
|
|
42
33
|
test 'find scope for a given object' do
|
|
@@ -62,7 +53,7 @@ class MappingTest < ActiveSupport::TestCase
|
|
|
62
53
|
assert_equal 'sign_out', mapping.path_names[:sign_out]
|
|
63
54
|
assert_equal 'password', mapping.path_names[:password]
|
|
64
55
|
assert_equal 'confirmation', mapping.path_names[:confirmation]
|
|
65
|
-
assert_equal 'sign_up',
|
|
56
|
+
assert_equal 'sign_up', mapping.path_names[:sign_up]
|
|
66
57
|
assert_equal 'unlock', mapping.path_names[:unlock]
|
|
67
58
|
end
|
|
68
59
|
|
|
@@ -76,83 +67,19 @@ class MappingTest < ActiveSupport::TestCase
|
|
|
76
67
|
assert_equal 'unblock', mapping.path_names[:unlock]
|
|
77
68
|
end
|
|
78
69
|
|
|
79
|
-
test 'has an empty path as default path prefix' do
|
|
80
|
-
mapping = Devise.mappings[:user]
|
|
81
|
-
assert_equal '/', mapping.path_prefix
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
test 'allow path prefix to be configured' do
|
|
85
|
-
mapping = Devise.mappings[:manager]
|
|
86
|
-
assert_equal '/:locale/', mapping.path_prefix
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
test 'retrieve as from the proper position' do
|
|
90
|
-
assert_equal 1, Devise.mappings[:user].as_position
|
|
91
|
-
assert_equal 2, Devise.mappings[:manager].as_position
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
test 'raw path is returned' do
|
|
95
|
-
assert_equal '/users', Devise.mappings[:user].raw_path
|
|
96
|
-
assert_equal '/:locale/accounts', Devise.mappings[:manager].raw_path
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
test 'raw path ignores the relative_url_root' do
|
|
100
|
-
swap ActionController::Base, :relative_url_root => "/abc" do
|
|
101
|
-
assert_equal '/users', Devise.mappings[:user].raw_path
|
|
102
|
-
end
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
test 'parsed path is returned' do
|
|
106
|
-
begin
|
|
107
|
-
Devise.default_url_options {{ :locale => I18n.locale }}
|
|
108
|
-
assert_equal '/users', Devise.mappings[:user].parsed_path
|
|
109
|
-
assert_equal '/en/accounts', Devise.mappings[:manager].parsed_path
|
|
110
|
-
ensure
|
|
111
|
-
Devise.default_url_options {{ }}
|
|
112
|
-
end
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
test 'parsed path adds in the relative_url_root' do
|
|
116
|
-
swap ActionController::Base, :relative_url_root => '/abc' do
|
|
117
|
-
assert_equal '/abc/users', Devise.mappings[:user].parsed_path
|
|
118
|
-
end
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
test 'parsed path deals with a nil relative_url_root' do
|
|
122
|
-
swap ActionController::Base, :relative_url_root => nil do
|
|
123
|
-
assert_equal '/users', Devise.mappings[:user].raw_path
|
|
124
|
-
end
|
|
125
|
-
end
|
|
126
|
-
|
|
127
|
-
test 'should have default route options' do
|
|
128
|
-
assert_equal({}, Devise.mappings[:user].route_options)
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
test 'should allow passing route options to devise routes' do
|
|
132
|
-
assert_equal({ :requirements => { :extra => 'value' } }, Devise.mappings[:manager].route_options)
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
test 'sign_out_via defaults to :get' do
|
|
136
|
-
assert_equal :get, Devise.mappings[:user].sign_out_via
|
|
137
|
-
end
|
|
138
|
-
|
|
139
|
-
test 'allows custom sign_out_via to be given' do
|
|
140
|
-
assert_equal :delete, Devise.mappings[:sign_out_via_delete].sign_out_via
|
|
141
|
-
assert_equal :post, Devise.mappings[:sign_out_via_post].sign_out_via
|
|
142
|
-
assert_equal :any, Devise.mappings[:sign_out_via_anymethod].sign_out_via
|
|
143
|
-
end
|
|
144
|
-
|
|
145
70
|
test 'magic predicates' do
|
|
146
71
|
mapping = Devise.mappings[:user]
|
|
147
72
|
assert mapping.authenticatable?
|
|
148
73
|
assert mapping.confirmable?
|
|
149
74
|
assert mapping.recoverable?
|
|
150
75
|
assert mapping.rememberable?
|
|
76
|
+
assert mapping.registerable?
|
|
151
77
|
|
|
152
78
|
mapping = Devise.mappings[:admin]
|
|
153
79
|
assert mapping.authenticatable?
|
|
80
|
+
assert mapping.recoverable?
|
|
81
|
+
assert mapping.lockable?
|
|
154
82
|
assert_not mapping.confirmable?
|
|
155
|
-
assert_not mapping.recoverable?
|
|
156
83
|
assert_not mapping.rememberable?
|
|
157
84
|
end
|
|
158
85
|
end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require '
|
|
1
|
+
require 'test_helper'
|
|
2
2
|
|
|
3
3
|
class ConfirmableTest < ActiveSupport::TestCase
|
|
4
4
|
|
|
@@ -45,10 +45,10 @@ class ConfirmableTest < ActiveSupport::TestCase
|
|
|
45
45
|
test 'should not confirm a user already confirmed' do
|
|
46
46
|
user = create_user
|
|
47
47
|
assert user.confirm!
|
|
48
|
-
|
|
48
|
+
assert_blank user.errors[:email]
|
|
49
49
|
|
|
50
50
|
assert_not user.confirm!
|
|
51
|
-
|
|
51
|
+
assert_equal "was already confirmed", user.errors[:email].join
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
test 'should find and confirm an user automatically' do
|
|
@@ -60,14 +60,14 @@ class ConfirmableTest < ActiveSupport::TestCase
|
|
|
60
60
|
|
|
61
61
|
test 'should return a new record with errors when a invalid token is given' do
|
|
62
62
|
confirmed_user = User.confirm_by_token('invalid_confirmation_token')
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
assert_not confirmed_user.persisted?
|
|
64
|
+
assert_equal "is invalid", confirmed_user.errors[:confirmation_token].join
|
|
65
65
|
end
|
|
66
66
|
|
|
67
67
|
test 'should return a new record with errors when a blank token is given' do
|
|
68
68
|
confirmed_user = User.confirm_by_token('')
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
assert_not confirmed_user.persisted?
|
|
70
|
+
assert_equal "can't be blank", confirmed_user.errors[:confirmation_token].join
|
|
71
71
|
end
|
|
72
72
|
|
|
73
73
|
test 'should generate errors for a user email if user is already confirmed' do
|
|
@@ -76,14 +76,7 @@ class ConfirmableTest < ActiveSupport::TestCase
|
|
|
76
76
|
user.save
|
|
77
77
|
confirmed_user = User.confirm_by_token(user.confirmation_token)
|
|
78
78
|
assert confirmed_user.confirmed?
|
|
79
|
-
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
test 'should authenticate a confirmed user' do
|
|
83
|
-
user = create_user
|
|
84
|
-
user.confirm!
|
|
85
|
-
authenticated_user = User.authenticate(:email => user.email, :password => user.password)
|
|
86
|
-
assert_equal authenticated_user, user
|
|
79
|
+
assert_equal "was already confirmed", confirmed_user.errors[:email].join
|
|
87
80
|
end
|
|
88
81
|
|
|
89
82
|
test 'should send confirmation instructions by email' do
|
|
@@ -119,13 +112,13 @@ class ConfirmableTest < ActiveSupport::TestCase
|
|
|
119
112
|
|
|
120
113
|
test 'should return a new user if no email was found' do
|
|
121
114
|
confirmation_user = User.send_confirmation_instructions(:email => "invalid@email.com")
|
|
122
|
-
|
|
115
|
+
assert_not confirmation_user.persisted?
|
|
123
116
|
end
|
|
124
117
|
|
|
125
118
|
test 'should add error to new user email if no email was found' do
|
|
126
119
|
confirmation_user = User.send_confirmation_instructions(:email => "invalid@email.com")
|
|
127
120
|
assert confirmation_user.errors[:email]
|
|
128
|
-
assert_equal
|
|
121
|
+
assert_equal "not found", confirmation_user.errors[:email].join
|
|
129
122
|
end
|
|
130
123
|
|
|
131
124
|
test 'should send email instructions for the user confirm it\'s email' do
|
|
@@ -167,7 +160,7 @@ class ConfirmableTest < ActiveSupport::TestCase
|
|
|
167
160
|
user.confirm!
|
|
168
161
|
assert_not user.resend_confirmation_token
|
|
169
162
|
assert user.confirmed?
|
|
170
|
-
assert_equal 'already confirmed', user.errors[:email]
|
|
163
|
+
assert_equal 'was already confirmed', user.errors[:email].join
|
|
171
164
|
end
|
|
172
165
|
|
|
173
166
|
test 'confirm time should fallback to devise confirm in default configuration' do
|
|
@@ -208,7 +201,7 @@ class ConfirmableTest < ActiveSupport::TestCase
|
|
|
208
201
|
Devise.confirm_within = 0.days
|
|
209
202
|
user = create_user
|
|
210
203
|
user.confirmation_sent_at = Date.today
|
|
211
|
-
assert_not user.
|
|
204
|
+
assert_not user.active?
|
|
212
205
|
end
|
|
213
206
|
|
|
214
207
|
test 'should not be active without confirmation' do
|
|
@@ -1,12 +1,24 @@
|
|
|
1
|
-
require '
|
|
1
|
+
require 'test_helper'
|
|
2
2
|
require 'digest/sha1'
|
|
3
3
|
|
|
4
|
-
class
|
|
4
|
+
class DatabaseAuthenticatableTest < ActiveSupport::TestCase
|
|
5
5
|
|
|
6
|
-
def encrypt_password(user, pepper=User.pepper, stretches=User.stretches, encryptor
|
|
6
|
+
def encrypt_password(user, pepper=User.pepper, stretches=User.stretches, encryptor=User.encryptor_class)
|
|
7
7
|
encryptor.digest('123456', stretches, user.password_salt, pepper)
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
+
def swap_with_encryptor(klass, encryptor, options={})
|
|
11
|
+
klass.instance_variable_set(:@encryptor_class, nil)
|
|
12
|
+
|
|
13
|
+
swap klass, options.merge(:encryptor => encryptor) do
|
|
14
|
+
begin
|
|
15
|
+
yield
|
|
16
|
+
ensure
|
|
17
|
+
klass.instance_variable_set(:@encryptor_class, nil)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
10
22
|
test 'should respond to password and password confirmation' do
|
|
11
23
|
user = new_user
|
|
12
24
|
assert user.respond_to?(:password)
|
|
@@ -28,8 +40,10 @@ class AuthenticatableTest < ActiveSupport::TestCase
|
|
|
28
40
|
end
|
|
29
41
|
|
|
30
42
|
test 'should generate a base64 hash using SecureRandom for password salt' do
|
|
31
|
-
|
|
32
|
-
|
|
43
|
+
swap_with_encryptor User, :sha1 do
|
|
44
|
+
ActiveSupport::SecureRandom.expects(:base64).with(15).returns('friendly_token')
|
|
45
|
+
assert_equal 'friendly_token', new_user.password_salt
|
|
46
|
+
end
|
|
33
47
|
end
|
|
34
48
|
|
|
35
49
|
test 'should not generate salt if password is blank' do
|
|
@@ -71,24 +85,10 @@ class AuthenticatableTest < ActiveSupport::TestCase
|
|
|
71
85
|
end
|
|
72
86
|
end
|
|
73
87
|
|
|
74
|
-
test 'should fallback to devise stretches default configuration' do
|
|
75
|
-
swap Devise, :stretches => 1 do
|
|
76
|
-
user = new_user
|
|
77
|
-
assert_equal encrypt_password(user, nil, 1), user.encrypted_password
|
|
78
|
-
assert_not_equal encrypt_password(user, nil, 2), user.encrypted_password
|
|
79
|
-
end
|
|
80
|
-
end
|
|
81
|
-
|
|
82
88
|
test 'should respect encryptor configuration' do
|
|
83
|
-
User
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
begin
|
|
87
|
-
user = create_user
|
|
88
|
-
assert_equal user.encrypted_password, encrypt_password(user, User.pepper, User.stretches, ::Devise::Encryptors::Sha512)
|
|
89
|
-
ensure
|
|
90
|
-
User.instance_variable_set(:@encryptor_class, nil)
|
|
91
|
-
end
|
|
89
|
+
swap_with_encryptor User, :sha512 do
|
|
90
|
+
user = create_user
|
|
91
|
+
assert_equal user.encrypted_password, encrypt_password(user, User.pepper, User.stretches, ::Devise::Encryptors::Sha512)
|
|
92
92
|
end
|
|
93
93
|
end
|
|
94
94
|
|
|
@@ -98,38 +98,6 @@ class AuthenticatableTest < ActiveSupport::TestCase
|
|
|
98
98
|
assert_not user.valid_password?('654321')
|
|
99
99
|
end
|
|
100
100
|
|
|
101
|
-
test 'should authenticate a valid user with email and password and return it' do
|
|
102
|
-
user = create_user
|
|
103
|
-
User.any_instance.stubs(:confirmed?).returns(true)
|
|
104
|
-
authenticated_user = User.authenticate(:email => user.email, :password => user.password)
|
|
105
|
-
assert_equal authenticated_user, user
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
test 'should return nil when authenticating an invalid user by email' do
|
|
109
|
-
user = create_user
|
|
110
|
-
authenticated_user = User.authenticate(:email => 'another.email@email.com', :password => user.password)
|
|
111
|
-
assert_nil authenticated_user
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
test 'should return nil when authenticating an invalid user by password' do
|
|
115
|
-
user = create_user
|
|
116
|
-
authenticated_user = User.authenticate(:email => user.email, :password => 'another_password')
|
|
117
|
-
assert_nil authenticated_user
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
test 'should use authentication keys to retrieve users' do
|
|
121
|
-
swap Devise, :authentication_keys => [:username] do
|
|
122
|
-
user = create_user
|
|
123
|
-
assert_nil User.authenticate(:email => user.email, :password => user.password)
|
|
124
|
-
assert_not_nil User.authenticate(:username => user.username, :password => user.password)
|
|
125
|
-
end
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
test 'should allow overwriting find for authentication conditions' do
|
|
129
|
-
admin = Admin.create!(valid_attributes)
|
|
130
|
-
assert_not_nil Admin.authenticate(:email => admin.email, :password => admin.password)
|
|
131
|
-
end
|
|
132
|
-
|
|
133
101
|
test 'should respond to current password' do
|
|
134
102
|
assert new_user.respond_to?(:current_password)
|
|
135
103
|
end
|
|
@@ -146,7 +114,7 @@ class AuthenticatableTest < ActiveSupport::TestCase
|
|
|
146
114
|
assert_not user.update_with_password(:current_password => 'other',
|
|
147
115
|
:password => 'pass321', :password_confirmation => 'pass321')
|
|
148
116
|
assert user.reload.valid_password?('123456')
|
|
149
|
-
assert_match
|
|
117
|
+
assert_match "is invalid", user.errors[:current_password].join
|
|
150
118
|
end
|
|
151
119
|
|
|
152
120
|
test 'should add an error to current password when it is blank' do
|
|
@@ -154,7 +122,7 @@ class AuthenticatableTest < ActiveSupport::TestCase
|
|
|
154
122
|
assert_not user.update_with_password(:password => 'pass321',
|
|
155
123
|
:password_confirmation => 'pass321')
|
|
156
124
|
assert user.reload.valid_password?('123456')
|
|
157
|
-
assert_match
|
|
125
|
+
assert_match "can't be blank", user.errors[:current_password].join
|
|
158
126
|
end
|
|
159
127
|
|
|
160
128
|
test 'should ignore password and its confirmation if they are blank' do
|