devise 4.4.3 → 4.9.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (236) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +174 -4
  3. data/MIT-LICENSE +2 -1
  4. data/README.md +129 -65
  5. data/app/controllers/devise/confirmations_controller.rb +1 -0
  6. data/app/controllers/devise/passwords_controller.rb +3 -2
  7. data/app/controllers/devise/registrations_controller.rb +27 -9
  8. data/app/controllers/devise/sessions_controller.rb +2 -2
  9. data/app/controllers/devise/unlocks_controller.rb +1 -0
  10. data/app/controllers/devise_controller.rb +17 -3
  11. data/app/helpers/devise_helper.rb +21 -18
  12. data/app/mailers/devise/mailer.rb +5 -5
  13. data/app/views/devise/confirmations/new.html.erb +1 -1
  14. data/app/views/devise/passwords/edit.html.erb +3 -3
  15. data/app/views/devise/passwords/new.html.erb +1 -1
  16. data/app/views/devise/registrations/edit.html.erb +5 -5
  17. data/app/views/devise/registrations/new.html.erb +3 -3
  18. data/app/views/devise/sessions/new.html.erb +3 -3
  19. data/app/views/devise/shared/_error_messages.html.erb +15 -0
  20. data/app/views/devise/shared/_links.html.erb +8 -8
  21. data/app/views/devise/unlocks/new.html.erb +1 -1
  22. data/config/locales/en.yml +3 -2
  23. data/lib/devise/controllers/helpers.rb +10 -8
  24. data/lib/devise/controllers/responder.rb +35 -0
  25. data/lib/devise/controllers/sign_in_out.rb +9 -4
  26. data/lib/devise/controllers/url_helpers.rb +1 -1
  27. data/lib/devise/failure_app.rb +41 -8
  28. data/lib/devise/hooks/csrf_cleaner.rb +6 -1
  29. data/lib/devise/hooks/lockable.rb +2 -5
  30. data/lib/devise/hooks/timeoutable.rb +2 -2
  31. data/lib/devise/mapping.rb +1 -1
  32. data/lib/devise/models/authenticatable.rb +51 -48
  33. data/lib/devise/models/confirmable.rb +34 -40
  34. data/lib/devise/models/database_authenticatable.rb +54 -35
  35. data/lib/devise/models/lockable.rb +13 -5
  36. data/lib/devise/models/omniauthable.rb +2 -2
  37. data/lib/devise/models/recoverable.rb +8 -19
  38. data/lib/devise/models/registerable.rb +2 -0
  39. data/lib/devise/models/rememberable.rb +2 -2
  40. data/lib/devise/models/timeoutable.rb +1 -1
  41. data/lib/devise/models/trackable.rb +9 -2
  42. data/lib/devise/models/validatable.rb +4 -9
  43. data/lib/devise/models.rb +1 -0
  44. data/lib/devise/omniauth.rb +2 -5
  45. data/lib/devise/orm.rb +71 -0
  46. data/lib/devise/parameter_filter.rb +2 -0
  47. data/lib/devise/parameter_sanitizer.rb +13 -1
  48. data/lib/devise/rails/deprecated_constant_accessor.rb +39 -0
  49. data/lib/devise/rails/routes.rb +6 -6
  50. data/lib/devise/rails.rb +4 -0
  51. data/lib/devise/secret_key_finder.rb +2 -0
  52. data/lib/devise/strategies/authenticatable.rb +1 -1
  53. data/lib/devise/strategies/database_authenticatable.rb +6 -1
  54. data/lib/devise/test/controller_helpers.rb +5 -3
  55. data/lib/devise/test/integration_helpers.rb +1 -1
  56. data/lib/devise/test_helpers.rb +1 -1
  57. data/lib/devise/version.rb +1 -1
  58. data/lib/devise.rb +38 -11
  59. data/lib/generators/active_record/devise_generator.rb +26 -11
  60. data/lib/generators/devise/controllers_generator.rb +1 -1
  61. data/lib/generators/devise/devise_generator.rb +1 -1
  62. data/lib/generators/devise/install_generator.rb +1 -5
  63. data/lib/generators/devise/orm_helpers.rb +2 -2
  64. data/lib/generators/devise/views_generator.rb +1 -1
  65. data/lib/generators/mongoid/devise_generator.rb +5 -5
  66. data/lib/generators/templates/README +9 -1
  67. data/lib/generators/templates/controllers/omniauth_callbacks_controller.rb +1 -1
  68. data/lib/generators/templates/devise.rb +38 -8
  69. data/lib/generators/templates/simple_form_for/confirmations/new.html.erb +5 -1
  70. data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +10 -2
  71. data/lib/generators/templates/simple_form_for/passwords/new.html.erb +4 -1
  72. data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +12 -4
  73. data/lib/generators/templates/simple_form_for/registrations/new.html.erb +11 -3
  74. data/lib/generators/templates/simple_form_for/sessions/new.html.erb +7 -2
  75. data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +4 -1
  76. metadata +23 -316
  77. data/.gitignore +0 -10
  78. data/.travis.yml +0 -68
  79. data/.yardopts +0 -9
  80. data/CODE_OF_CONDUCT.md +0 -22
  81. data/CONTRIBUTING.md +0 -79
  82. data/Gemfile +0 -39
  83. data/Gemfile.lock +0 -193
  84. data/ISSUE_TEMPLATE.md +0 -19
  85. data/Rakefile +0 -37
  86. data/bin/test +0 -13
  87. data/devise.gemspec +0 -28
  88. data/devise.png +0 -0
  89. data/gemfiles/Gemfile.rails-4.1-stable +0 -32
  90. data/gemfiles/Gemfile.rails-4.1-stable.lock +0 -171
  91. data/gemfiles/Gemfile.rails-4.2-stable +0 -32
  92. data/gemfiles/Gemfile.rails-4.2-stable.lock +0 -192
  93. data/gemfiles/Gemfile.rails-5.0-stable +0 -33
  94. data/gemfiles/Gemfile.rails-5.0-stable.lock +0 -192
  95. data/gemfiles/Gemfile.rails-5.2-rc1 +0 -26
  96. data/gemfiles/Gemfile.rails-5.2-rc1.lock +0 -201
  97. data/guides/bug_report_templates/integration_test.rb +0 -106
  98. data/test/controllers/custom_registrations_controller_test.rb +0 -42
  99. data/test/controllers/custom_strategy_test.rb +0 -66
  100. data/test/controllers/helper_methods_test.rb +0 -24
  101. data/test/controllers/helpers_test.rb +0 -318
  102. data/test/controllers/inherited_controller_i18n_messages_test.rb +0 -53
  103. data/test/controllers/internal_helpers_test.rb +0 -129
  104. data/test/controllers/load_hooks_controller_test.rb +0 -21
  105. data/test/controllers/passwords_controller_test.rb +0 -34
  106. data/test/controllers/sessions_controller_test.rb +0 -108
  107. data/test/controllers/url_helpers_test.rb +0 -67
  108. data/test/delegator_test.rb +0 -21
  109. data/test/devise_test.rb +0 -109
  110. data/test/failure_app_test.rb +0 -340
  111. data/test/generators/active_record_generator_test.rb +0 -130
  112. data/test/generators/controllers_generator_test.rb +0 -50
  113. data/test/generators/devise_generator_test.rb +0 -41
  114. data/test/generators/install_generator_test.rb +0 -26
  115. data/test/generators/mongoid_generator_test.rb +0 -25
  116. data/test/generators/views_generator_test.rb +0 -105
  117. data/test/helpers/devise_helper_test.rb +0 -51
  118. data/test/integration/authenticatable_test.rb +0 -706
  119. data/test/integration/confirmable_test.rb +0 -326
  120. data/test/integration/database_authenticatable_test.rb +0 -97
  121. data/test/integration/http_authenticatable_test.rb +0 -114
  122. data/test/integration/lockable_test.rb +0 -242
  123. data/test/integration/mounted_engine_test.rb +0 -38
  124. data/test/integration/omniauthable_test.rb +0 -148
  125. data/test/integration/recoverable_test.rb +0 -349
  126. data/test/integration/registerable_test.rb +0 -365
  127. data/test/integration/rememberable_test.rb +0 -219
  128. data/test/integration/timeoutable_test.rb +0 -186
  129. data/test/integration/trackable_test.rb +0 -99
  130. data/test/mailers/confirmation_instructions_test.rb +0 -117
  131. data/test/mailers/email_changed_test.rb +0 -132
  132. data/test/mailers/mailer_test.rb +0 -20
  133. data/test/mailers/reset_password_instructions_test.rb +0 -98
  134. data/test/mailers/unlock_instructions_test.rb +0 -93
  135. data/test/mapping_test.rb +0 -136
  136. data/test/models/authenticatable_test.rb +0 -25
  137. data/test/models/confirmable_test.rb +0 -549
  138. data/test/models/database_authenticatable_test.rb +0 -283
  139. data/test/models/lockable_test.rb +0 -352
  140. data/test/models/omniauthable_test.rb +0 -9
  141. data/test/models/recoverable_test.rb +0 -263
  142. data/test/models/registerable_test.rb +0 -9
  143. data/test/models/rememberable_test.rb +0 -184
  144. data/test/models/serializable_test.rb +0 -60
  145. data/test/models/timeoutable_test.rb +0 -53
  146. data/test/models/trackable_test.rb +0 -62
  147. data/test/models/validatable_test.rb +0 -121
  148. data/test/models_test.rb +0 -155
  149. data/test/omniauth/config_test.rb +0 -61
  150. data/test/omniauth/url_helpers_test.rb +0 -53
  151. data/test/orm/active_record.rb +0 -24
  152. data/test/orm/mongoid.rb +0 -15
  153. data/test/parameter_sanitizer_test.rb +0 -77
  154. data/test/rails_app/Rakefile +0 -6
  155. data/test/rails_app/app/active_record/admin.rb +0 -8
  156. data/test/rails_app/app/active_record/shim.rb +0 -4
  157. data/test/rails_app/app/active_record/user.rb +0 -20
  158. data/test/rails_app/app/active_record/user_on_engine.rb +0 -9
  159. data/test/rails_app/app/active_record/user_on_main_app.rb +0 -9
  160. data/test/rails_app/app/active_record/user_with_validations.rb +0 -12
  161. data/test/rails_app/app/active_record/user_without_email.rb +0 -10
  162. data/test/rails_app/app/controllers/admins/sessions_controller.rb +0 -8
  163. data/test/rails_app/app/controllers/admins_controller.rb +0 -8
  164. data/test/rails_app/app/controllers/application_controller.rb +0 -13
  165. data/test/rails_app/app/controllers/application_with_fake_engine.rb +0 -32
  166. data/test/rails_app/app/controllers/custom/registrations_controller.rb +0 -33
  167. data/test/rails_app/app/controllers/home_controller.rb +0 -31
  168. data/test/rails_app/app/controllers/publisher/registrations_controller.rb +0 -4
  169. data/test/rails_app/app/controllers/publisher/sessions_controller.rb +0 -4
  170. data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +0 -16
  171. data/test/rails_app/app/controllers/users_controller.rb +0 -33
  172. data/test/rails_app/app/helpers/application_helper.rb +0 -5
  173. data/test/rails_app/app/mailers/users/from_proc_mailer.rb +0 -5
  174. data/test/rails_app/app/mailers/users/mailer.rb +0 -5
  175. data/test/rails_app/app/mailers/users/reply_to_mailer.rb +0 -6
  176. data/test/rails_app/app/mongoid/admin.rb +0 -31
  177. data/test/rails_app/app/mongoid/shim.rb +0 -25
  178. data/test/rails_app/app/mongoid/user.rb +0 -50
  179. data/test/rails_app/app/mongoid/user_on_engine.rb +0 -41
  180. data/test/rails_app/app/mongoid/user_on_main_app.rb +0 -41
  181. data/test/rails_app/app/mongoid/user_with_validations.rb +0 -37
  182. data/test/rails_app/app/mongoid/user_without_email.rb +0 -35
  183. data/test/rails_app/app/views/admins/index.html.erb +0 -1
  184. data/test/rails_app/app/views/admins/sessions/new.html.erb +0 -2
  185. data/test/rails_app/app/views/home/admin_dashboard.html.erb +0 -1
  186. data/test/rails_app/app/views/home/index.html.erb +0 -1
  187. data/test/rails_app/app/views/home/join.html.erb +0 -1
  188. data/test/rails_app/app/views/home/private.html.erb +0 -1
  189. data/test/rails_app/app/views/home/user_dashboard.html.erb +0 -1
  190. data/test/rails_app/app/views/layouts/application.html.erb +0 -24
  191. data/test/rails_app/app/views/users/edit_form.html.erb +0 -1
  192. data/test/rails_app/app/views/users/index.html.erb +0 -1
  193. data/test/rails_app/app/views/users/mailer/confirmation_instructions.erb +0 -1
  194. data/test/rails_app/app/views/users/sessions/new.html.erb +0 -1
  195. data/test/rails_app/bin/bundle +0 -3
  196. data/test/rails_app/bin/rails +0 -4
  197. data/test/rails_app/bin/rake +0 -4
  198. data/test/rails_app/config/application.rb +0 -48
  199. data/test/rails_app/config/boot.rb +0 -27
  200. data/test/rails_app/config/database.yml +0 -18
  201. data/test/rails_app/config/environment.rb +0 -7
  202. data/test/rails_app/config/environments/development.rb +0 -32
  203. data/test/rails_app/config/environments/production.rb +0 -88
  204. data/test/rails_app/config/environments/test.rb +0 -47
  205. data/test/rails_app/config/initializers/backtrace_silencers.rb +0 -9
  206. data/test/rails_app/config/initializers/devise.rb +0 -182
  207. data/test/rails_app/config/initializers/inflections.rb +0 -4
  208. data/test/rails_app/config/initializers/secret_token.rb +0 -5
  209. data/test/rails_app/config/initializers/session_store.rb +0 -3
  210. data/test/rails_app/config/routes.rb +0 -128
  211. data/test/rails_app/config.ru +0 -4
  212. data/test/rails_app/db/migrate/20100401102949_create_tables.rb +0 -77
  213. data/test/rails_app/db/schema.rb +0 -57
  214. data/test/rails_app/lib/shared_admin.rb +0 -23
  215. data/test/rails_app/lib/shared_user.rb +0 -32
  216. data/test/rails_app/lib/shared_user_without_email.rb +0 -28
  217. data/test/rails_app/lib/shared_user_without_omniauth.rb +0 -15
  218. data/test/rails_app/public/404.html +0 -26
  219. data/test/rails_app/public/422.html +0 -26
  220. data/test/rails_app/public/500.html +0 -26
  221. data/test/rails_app/public/favicon.ico +0 -0
  222. data/test/rails_test.rb +0 -11
  223. data/test/routes_test.rb +0 -281
  224. data/test/secret_key_finder_test.rb +0 -97
  225. data/test/support/action_controller/record_identifier.rb +0 -12
  226. data/test/support/assertions.rb +0 -30
  227. data/test/support/helpers.rb +0 -83
  228. data/test/support/http_method_compatibility.rb +0 -53
  229. data/test/support/integration.rb +0 -95
  230. data/test/support/locale/en.yml +0 -8
  231. data/test/support/mongoid.yml +0 -6
  232. data/test/support/webrat/integrations/rails.rb +0 -35
  233. data/test/test/controller_helpers_test.rb +0 -193
  234. data/test/test/integration_helpers_test.rb +0 -34
  235. data/test/test_helper.rb +0 -36
  236. data/test/test_models.rb +0 -35
@@ -1,121 +0,0 @@
1
- # encoding: UTF-8
2
- # frozen_string_literal: true
3
-
4
- require 'test_helper'
5
-
6
- class ValidatableTest < ActiveSupport::TestCase
7
- test 'should require email to be set' do
8
- user = new_user(email: nil)
9
- assert user.invalid?
10
- assert user.errors[:email]
11
- assert_equal 'can\'t be blank', user.errors[:email].join
12
- end
13
-
14
- test 'should require uniqueness of email if email has changed, allowing blank' do
15
- existing_user = create_user
16
-
17
- user = new_user(email: '')
18
- assert user.invalid?
19
- assert_no_match(/taken/, user.errors[:email].join)
20
-
21
- user.email = existing_user.email
22
- assert user.invalid?
23
- assert_match(/taken/, user.errors[:email].join)
24
-
25
- user.save(validate: false)
26
- assert user.valid?
27
- end
28
-
29
- test 'should require correct email format if email has changed, allowing blank' do
30
- user = new_user(email: '')
31
- assert user.invalid?
32
- assert_not_equal 'is invalid', user.errors[:email].join
33
-
34
- %w{invalid_email_format 123 $$$ () ☃}.each do |email|
35
- user.email = email
36
- assert user.invalid?, "should be invalid with email #{email}"
37
- assert_equal 'is invalid', user.errors[:email].join
38
- end
39
-
40
- user.save(validate: false)
41
- assert user.valid?
42
- end
43
-
44
- test 'should accept valid emails' do
45
- %w(a.b.c@example.com test_mail@gmail.com any@any.net email@test.br 123@mail.test 1☃3@mail.test).each do |email|
46
- user = new_user(email: email)
47
- assert user.valid?, "should be valid with email #{email}"
48
- assert_blank user.errors[:email]
49
- end
50
- end
51
-
52
- test 'should require password to be set when creating a new record' do
53
- user = new_user(password: '', password_confirmation: '')
54
- assert user.invalid?
55
- assert_equal 'can\'t be blank', user.errors[:password].join
56
- end
57
-
58
- test 'should require confirmation to be set when creating a new record' do
59
- user = new_user(password: 'new_password', password_confirmation: 'blabla')
60
- assert user.invalid?
61
-
62
- assert_equal 'doesn\'t match Password', user.errors[:password_confirmation].join
63
- end
64
-
65
- test 'should require password when updating/resetting password' do
66
- user = create_user
67
-
68
- user.password = ''
69
- user.password_confirmation = ''
70
-
71
- assert user.invalid?
72
- assert_equal 'can\'t be blank', user.errors[:password].join
73
- end
74
-
75
- test 'should require confirmation when updating/resetting password' do
76
- user = create_user
77
- user.password_confirmation = 'another_password'
78
- assert user.invalid?
79
-
80
- assert_equal 'doesn\'t match Password', user.errors[:password_confirmation].join
81
- end
82
-
83
- test 'should require a password with minimum of 7 characters' do
84
- user = new_user(password: '12345', password_confirmation: '12345')
85
- assert user.invalid?
86
- assert_equal 'is too short (minimum is 7 characters)', user.errors[:password].join
87
- end
88
-
89
- test 'should require a password with maximum of 72 characters long' do
90
- user = new_user(password: 'x'*73, password_confirmation: 'x'*73)
91
- assert user.invalid?
92
- assert_equal 'is too long (maximum is 72 characters)', user.errors[:password].join
93
- end
94
-
95
- test 'should not require password length when it\'s not changed' do
96
- user = create_user.reload
97
- user.password = user.password_confirmation = nil
98
- assert user.valid?
99
-
100
- user.password_confirmation = 'confirmation'
101
- assert user.invalid?
102
- refute (user.errors[:password].join =~ /is too long/)
103
- end
104
-
105
- test 'should complain about length even if password is not required' do
106
- user = new_user(password: 'x'*73, password_confirmation: 'x'*73)
107
- user.stubs(:password_required?).returns(false)
108
- assert user.invalid?
109
- assert_equal 'is too long (maximum is 72 characters)', user.errors[:password].join
110
- end
111
-
112
- test 'should not be included in objects with invalid API' do
113
- assert_raise RuntimeError do
114
- Class.new.send :include, Devise::Models::Validatable
115
- end
116
- end
117
-
118
- test 'required_fields should be an empty array' do
119
- assert_equal Devise::Models::Validatable.required_fields(User), []
120
- end
121
- end
data/test/models_test.rb DELETED
@@ -1,155 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
- require 'test_models'
5
-
6
- class ActiveRecordTest < ActiveSupport::TestCase
7
- def include_module?(klass, mod)
8
- klass.devise_modules.include?(mod) &&
9
- klass.included_modules.include?(Devise::Models::const_get(mod.to_s.classify))
10
- end
11
-
12
- def assert_include_modules(klass, *modules)
13
- modules.each do |mod|
14
- assert include_module?(klass, mod)
15
- end
16
-
17
- (Devise::ALL - modules).each do |mod|
18
- refute include_module?(klass, mod)
19
- end
20
- end
21
-
22
- test 'can cherry pick modules' do
23
- assert_include_modules Admin, :database_authenticatable, :registerable, :timeoutable, :recoverable, :lockable, :confirmable
24
- end
25
-
26
- test 'validations options are not applied too late' do
27
- validators = WithValidation.validators_on :password
28
- length = validators.find { |v| v.kind == :length }
29
- assert_equal 2, length.options[:minimum]
30
- assert_equal 6, length.options[:maximum]
31
- end
32
-
33
- test 'validations are applied just once' do
34
- validators = Several.validators_on :password
35
- assert_equal 1, validators.select{ |v| v.kind == :length }.length
36
- end
37
-
38
- test 'chosen modules are inheritable' do
39
- assert_include_modules Inheritable, :database_authenticatable, :registerable, :timeoutable, :recoverable, :lockable, :confirmable
40
- end
41
-
42
- test 'order of module inclusion' do
43
- correct_module_order = [:database_authenticatable, :recoverable, :registerable, :confirmable, :lockable, :timeoutable]
44
- incorrect_module_order = [:database_authenticatable, :timeoutable, :registerable, :recoverable, :lockable, :confirmable]
45
-
46
- assert_include_modules Admin, *incorrect_module_order
47
-
48
- # get module constants from symbol list
49
- module_constants = correct_module_order.collect { |mod| Devise::Models::const_get(mod.to_s.classify) }
50
-
51
- # confirm that they adhere to the order in ALL
52
- # get included modules, filter out the noise, and reverse the order
53
- assert_equal module_constants, (Admin.included_modules & module_constants).reverse
54
- end
55
-
56
- test 'raise error on invalid module' do
57
- assert_raise NameError do
58
- # Mix valid an invalid modules.
59
- Configurable.class_eval { devise :database_authenticatable, :doesnotexit }
60
- end
61
- end
62
-
63
- test 'set a default value for stretches' do
64
- assert_equal 15, Configurable.stretches
65
- end
66
-
67
- test 'set a default value for pepper' do
68
- assert_equal 'abcdef', Configurable.pepper
69
- end
70
-
71
- test 'set a default value for allow_unconfirmed_access_for' do
72
- assert_equal 5.days, Configurable.allow_unconfirmed_access_for
73
- end
74
-
75
- test 'set a default value for remember_for' do
76
- assert_equal 7.days, Configurable.remember_for
77
- end
78
-
79
- test 'set a default value for timeout_in' do
80
- assert_equal 15.minutes, Configurable.timeout_in
81
- end
82
-
83
- test 'set a default value for unlock_in' do
84
- assert_equal 10.days, Configurable.unlock_in
85
- end
86
-
87
- test 'set null fields on migrations' do
88
- # Ignore email sending since no email exists.
89
- klass = Class.new(Admin) do
90
- def send_devise_notification(*); end
91
- end
92
-
93
- klass.create!
94
- end
95
- end
96
-
97
- module StubModelFilters
98
- def stub_filter(name)
99
- define_singleton_method(name) { |*| nil }
100
- end
101
- end
102
-
103
- class CheckFieldsTest < ActiveSupport::TestCase
104
- test 'checks if the class respond_to the required fields' do
105
- Player = Class.new do
106
- extend Devise::Models
107
- extend StubModelFilters
108
-
109
- stub_filter :before_validation
110
- stub_filter :after_update
111
-
112
- devise :database_authenticatable
113
-
114
- attr_accessor :encrypted_password, :email
115
- end
116
-
117
- assert_nothing_raised do
118
- Devise::Models.check_fields!(Player)
119
- end
120
- end
121
-
122
- test 'raises Devise::Models::MissingAtrribute and shows the missing attribute if the class doesn\'t respond_to one of the attributes' do
123
- Clown = Class.new do
124
- extend Devise::Models
125
- extend StubModelFilters
126
-
127
- stub_filter :before_validation
128
- stub_filter :after_update
129
-
130
- devise :database_authenticatable
131
-
132
- attr_accessor :encrypted_password
133
- end
134
-
135
- assert_raise_with_message Devise::Models::MissingAttribute, "The following attribute(s) is (are) missing on your model: email" do
136
- Devise::Models.check_fields!(Clown)
137
- end
138
- end
139
-
140
- test 'raises Devise::Models::MissingAtrribute with all the missing attributes if there is more than one' do
141
- Magician = Class.new do
142
- extend Devise::Models
143
- extend StubModelFilters
144
-
145
- stub_filter :before_validation
146
- stub_filter :after_update
147
-
148
- devise :database_authenticatable
149
- end
150
-
151
- assert_raise_with_message Devise::Models::MissingAttribute, "The following attribute(s) is (are) missing on your model: encrypted_password, email" do
152
- Devise::Models.check_fields!(Magician)
153
- end
154
- end
155
- end
@@ -1,61 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class OmniAuthConfigTest < ActiveSupport::TestCase
6
- class MyStrategy
7
- include OmniAuth::Strategy
8
- end
9
-
10
- test 'strategy_name returns provider if no options given' do
11
- config = Devise::OmniAuth::Config.new :facebook, [{}]
12
- assert_equal :facebook, config.strategy_name
13
- end
14
-
15
- test 'strategy_name returns provider if no name option are given' do
16
- config = Devise::OmniAuth::Config.new :facebook, [{ other: :option }]
17
- assert_equal :facebook, config.strategy_name
18
- end
19
-
20
- test 'returns name option when have a name' do
21
- config = Devise::OmniAuth::Config.new :facebook, [{ name: :github }]
22
- assert_equal :github, config.strategy_name
23
- end
24
-
25
- test "finds contrib strategies" do
26
- config = Devise::OmniAuth::Config.new :facebook, [{}]
27
- assert_equal OmniAuth::Strategies::Facebook, config.strategy_class
28
- end
29
-
30
- class NamedTestStrategy
31
- include OmniAuth::Strategy
32
- option :name, :the_one
33
- end
34
-
35
- test "finds the strategy in OmniAuth's list by name" do
36
- config = Devise::OmniAuth::Config.new :the_one, [{}]
37
- assert_equal NamedTestStrategy, config.strategy_class
38
- end
39
-
40
- class UnNamedTestStrategy
41
- include OmniAuth::Strategy
42
- end
43
-
44
- test "finds the strategy in OmniAuth's list by class name" do
45
- config = Devise::OmniAuth::Config.new :un_named_test_strategy, [{}]
46
- assert_equal UnNamedTestStrategy, config.strategy_class
47
- end
48
-
49
- test 'raises an error if strategy cannot be found' do
50
- config = Devise::OmniAuth::Config.new :my_other_strategy, [{}]
51
- assert_raise Devise::OmniAuth::StrategyNotFound do
52
- config.strategy_class
53
- end
54
- end
55
-
56
- test 'allows the user to define a custom require path' do
57
- config = Devise::OmniAuth::Config.new :my_strategy, [{strategy_class: MyStrategy}]
58
- config_class = config.strategy_class
59
- assert_equal MyStrategy, config_class
60
- end
61
- end
@@ -1,53 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class OmniAuthRoutesTest < ActionController::TestCase
6
- tests ApplicationController
7
-
8
- def assert_path(action, provider, with_param=true)
9
- # Resource param
10
- assert_equal @controller.send(action, :user, provider),
11
- @controller.send("user_#{provider}_#{action}")
12
-
13
- # With an object
14
- assert_equal @controller.send(action, User.new, provider),
15
- @controller.send("user_#{provider}_#{action}")
16
-
17
- if with_param
18
- # Default url params
19
- assert_equal @controller.send(action, :user, provider, param: 123),
20
- @controller.send("user_#{provider}_#{action}", param: 123)
21
- end
22
- end
23
-
24
- test 'should alias omniauth_callback to mapped user auth_callback' do
25
- assert_path :omniauth_callback_path, :facebook
26
- end
27
-
28
- test 'should alias omniauth_authorize to mapped user auth_authorize' do
29
- assert_path :omniauth_authorize_path, :facebook, false
30
- end
31
-
32
- test 'should generate authorization path' do
33
- assert_match "/users/auth/facebook", @controller.omniauth_authorize_path(:user, :facebook)
34
-
35
- assert_raise NoMethodError do
36
- @controller.omniauth_authorize_path(:user, :github)
37
- end
38
- end
39
-
40
- test 'should generate authorization path for named open_id omniauth' do
41
- assert_match "/users/auth/google", @controller.omniauth_authorize_path(:user, :google)
42
- end
43
-
44
- test 'should generate authorization path with params' do
45
- assert_match "/users/auth/openid?openid_url=http%3A%2F%2Fyahoo.com",
46
- @controller.omniauth_authorize_path(:user, :openid, openid_url: "http://yahoo.com")
47
- end
48
-
49
- test 'should not add a "?" if no param was sent' do
50
- assert_equal "/users/auth/openid",
51
- @controller.omniauth_authorize_path(:user, :openid)
52
- end
53
- end
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- ActiveRecord::Migration.verbose = false
4
- ActiveRecord::Base.logger = Logger.new(nil)
5
- ActiveRecord::Base.include_root_in_json = true
6
-
7
- migrate_path = File.expand_path("../../rails_app/db/migrate/", __FILE__)
8
- if Devise::Test.rails52?
9
- ActiveRecord::MigrationContext.new(migrate_path).migrate
10
- else
11
- ActiveRecord::Migrator.migrate(migrate_path)
12
- end
13
-
14
- class ActiveSupport::TestCase
15
- if Devise::Test.rails5?
16
- self.use_transactional_tests = true
17
- else
18
- # Let `after_commit` work with transactional fixtures, however this is not needed for Rails 5.
19
- require 'test_after_commit'
20
- self.use_transactional_fixtures = true
21
- end
22
-
23
- self.use_instantiated_fixtures = false
24
- end
data/test/orm/mongoid.rb DELETED
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'mongoid/version'
4
-
5
- Mongoid.configure do |config|
6
- config.load!('test/support/mongoid.yml')
7
- config.use_utc = true
8
- config.include_root_in_json = true
9
- end
10
-
11
- class ActiveSupport::TestCase
12
- setup do
13
- Mongoid.default_session.drop
14
- end
15
- end
@@ -1,77 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
- require 'devise/parameter_sanitizer'
5
-
6
- class ParameterSanitizerTest < ActiveSupport::TestCase
7
- def sanitizer(params)
8
- params = ActionController::Parameters.new(params)
9
- Devise::ParameterSanitizer.new(User, :user, params)
10
- end
11
-
12
- test 'permits the default parameters for sign in' do
13
- sanitizer = sanitizer('user' => { 'email' => 'jose' })
14
- sanitized = sanitizer.sanitize(:sign_in)
15
-
16
- assert_equal({ 'email' => 'jose' }, sanitized)
17
- end
18
-
19
- test 'permits the default parameters for sign up' do
20
- sanitizer = sanitizer('user' => { 'email' => 'jose', 'role' => 'invalid' })
21
- sanitized = sanitizer.sanitize(:sign_up)
22
-
23
- assert_equal({ 'email' => 'jose' }, sanitized)
24
- end
25
-
26
- test 'permits the default parameters for account update' do
27
- sanitizer = sanitizer('user' => { 'email' => 'jose', 'role' => 'invalid' })
28
- sanitized = sanitizer.sanitize(:account_update)
29
-
30
- assert_equal({ 'email' => 'jose' }, sanitized)
31
- end
32
-
33
- test 'permits news parameters for an existing action' do
34
- sanitizer = sanitizer('user' => { 'username' => 'jose' })
35
- sanitizer.permit(:sign_in, keys: [:username])
36
- sanitized = sanitizer.sanitize(:sign_in)
37
-
38
- assert_equal({ 'username' => 'jose' }, sanitized)
39
- end
40
-
41
- test 'permits news parameters for an existing action with a block' do
42
- sanitizer = sanitizer('user' => { 'username' => 'jose' })
43
- sanitizer.permit(:sign_in) do |user|
44
- user.permit(:username)
45
- end
46
-
47
- sanitized = sanitizer.sanitize(:sign_in)
48
-
49
- assert_equal({ 'username' => 'jose' }, sanitized)
50
- end
51
-
52
- test 'permit parameters for new actions' do
53
- sanitizer = sanitizer('user' => { 'email' => 'jose@omglol', 'name' => 'Jose' })
54
- sanitizer.permit(:invite_user, keys: [:email, :name])
55
-
56
- sanitized = sanitizer.sanitize(:invite_user)
57
-
58
- assert_equal({ 'email' => 'jose@omglol', 'name' => 'Jose' }, sanitized)
59
- end
60
-
61
- test 'fails when we do not have any permitted parameters for the action' do
62
- sanitizer = sanitizer('user' => { 'email' => 'jose', 'password' => 'invalid' })
63
-
64
- assert_raise NotImplementedError do
65
- sanitizer.sanitize(:unknown)
66
- end
67
- end
68
-
69
- test 'removes permitted parameters' do
70
- sanitizer = sanitizer('user' => { 'email' => 'jose@omglol', 'username' => 'jose' })
71
-
72
- sanitizer.permit(:sign_in, keys: [:username], except: [:email])
73
- sanitized = sanitizer.sanitize(:sign_in)
74
-
75
- assert_equal({ 'username' => 'jose' }, sanitized)
76
- end
77
- end
@@ -1,6 +0,0 @@
1
- # Add your own tasks in files placed in lib/tasks ending in .rake,
2
- # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
-
4
- require File.expand_path('../config/application', __FILE__)
5
-
6
- Rails.application.load_tasks
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'shared_admin'
4
-
5
- class Admin < ActiveRecord::Base
6
- include Shim
7
- include SharedAdmin
8
- end
@@ -1,4 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Shim
4
- end
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'shared_user'
4
-
5
- class User < ActiveRecord::Base
6
- include Shim
7
- include SharedUser
8
- include ActiveModel::Serializers::Xml if Devise::Test.rails5?
9
-
10
- validates :sign_in_count, presence: true
11
-
12
- cattr_accessor :validations_performed
13
-
14
- after_validation :after_validation_callback
15
-
16
- def after_validation_callback
17
- # used to check in our test if the validations were called
18
- @@validations_performed = true
19
- end
20
- end
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'shared_user_without_omniauth'
4
-
5
- class UserOnEngine < ActiveRecord::Base
6
- self.table_name = 'users'
7
- include Shim
8
- include SharedUserWithoutOmniauth
9
- end
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'shared_user_without_omniauth'
4
-
5
- class UserOnMainApp < ActiveRecord::Base
6
- self.table_name = 'users'
7
- include Shim
8
- include SharedUserWithoutOmniauth
9
- end
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'shared_user'
4
-
5
- class UserWithValidations < ActiveRecord::Base
6
- self.table_name = 'users'
7
- include Shim
8
- include SharedUser
9
-
10
- validates :email, presence: true
11
- end
12
-
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "shared_user_without_email"
4
-
5
- class UserWithoutEmail < ActiveRecord::Base
6
- self.table_name = 'users'
7
- include Shim
8
- include SharedUserWithoutEmail
9
- end
10
-
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Admins::SessionsController < Devise::SessionsController
4
- def new
5
- flash[:special] = "Welcome to #{controller_path.inspect} controller!"
6
- super
7
- end
8
- end
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class AdminsController < ApplicationController
4
- before_action :authenticate_admin!
5
-
6
- def index
7
- end
8
- end
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Filters added to this controller apply to all controllers in the application.
4
- # Likewise, all the methods added will be available for all controllers.
5
-
6
- class ApplicationController < ActionController::Base
7
- protect_from_forgery
8
- before_action :current_user, unless: :devise_controller?
9
- before_action :authenticate_user!, if: :devise_controller?
10
- respond_to(*Mime::SET.map(&:to_sym))
11
-
12
- devise_group :commenter, contains: [:user, :admin]
13
- end
@@ -1,32 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class ApplicationWithFakeEngine < ApplicationController
4
- private
5
-
6
- helper_method :fake_engine
7
- def fake_engine
8
- @fake_engine ||= FakeEngine.new
9
- end
10
- end
11
-
12
- class FakeEngine
13
- def user_on_engine_confirmation_path
14
- '/user_on_engine/confirmation'
15
- end
16
-
17
- def new_user_on_engine_session_path
18
- '/user_on_engine/confirmation/new'
19
- end
20
-
21
- def new_user_on_engine_registration_path
22
- '/user_on_engine/registration/new'
23
- end
24
-
25
- def new_user_on_engine_password_path
26
- '/user_on_engine/password/new'
27
- end
28
-
29
- def new_user_on_engine_unlock_path
30
- '/user_on_engine/unlock/new'
31
- end
32
- end