loyal_devise 2.1.2 → 2.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (188) hide show
  1. data/.gitignore +2 -0
  2. data/.travis.yml +14 -9
  3. data/.yardopts +9 -0
  4. data/CHANGELOG.rdoc +60 -5
  5. data/CONTRIBUTING.md +4 -2
  6. data/Gemfile +7 -7
  7. data/Gemfile.lock +107 -101
  8. data/MIT-LICENSE +1 -1
  9. data/README.md +110 -48
  10. data/Rakefile +1 -0
  11. data/app/controllers/devise/confirmations_controller.rb +2 -4
  12. data/app/controllers/devise/omniauth_callbacks_controller.rb +0 -1
  13. data/app/controllers/devise/passwords_controller.rb +16 -5
  14. data/app/controllers/devise/registrations_controller.rb +13 -7
  15. data/app/controllers/devise/sessions_controller.rb +6 -6
  16. data/app/controllers/devise/unlocks_controller.rb +3 -4
  17. data/app/controllers/devise_controller.rb +12 -33
  18. data/app/helpers/devise_helper.rb +0 -1
  19. data/app/mailers/devise/mailer.rb +7 -8
  20. data/app/views/devise/mailer/confirmation_instructions.html.erb +1 -1
  21. data/app/views/devise/mailer/reset_password_instructions.html.erb +1 -1
  22. data/app/views/devise/registrations/edit.html.erb +5 -1
  23. data/config/locales/en.yml +48 -48
  24. data/devise.gemspec +6 -6
  25. data/devise.png +0 -0
  26. data/gemfiles/{Gemfile.rails-3.1.x → Gemfile.rails-3.2.x} +8 -12
  27. data/gemfiles/Gemfile.rails-3.2.x.lock +156 -0
  28. data/lib/devise.rb +34 -11
  29. data/lib/devise/controllers/helpers.rb +33 -7
  30. data/lib/devise/controllers/rememberable.rb +6 -3
  31. data/lib/devise/controllers/scoped_views.rb +1 -2
  32. data/lib/devise/controllers/url_helpers.rb +0 -1
  33. data/lib/devise/delegator.rb +0 -1
  34. data/lib/devise/failure_app.rb +8 -2
  35. data/lib/devise/hooks/activatable.rb +1 -2
  36. data/lib/devise/hooks/forgetable.rb +0 -1
  37. data/lib/devise/hooks/lockable.rb +1 -2
  38. data/lib/devise/hooks/rememberable.rb +1 -2
  39. data/lib/devise/hooks/timeoutable.rb +0 -1
  40. data/lib/devise/hooks/trackable.rb +0 -1
  41. data/lib/devise/mailers/helpers.rb +18 -14
  42. data/lib/devise/mapping.rb +6 -7
  43. data/lib/devise/models.rb +0 -1
  44. data/lib/devise/models/authenticatable.rb +50 -27
  45. data/lib/devise/models/confirmable.rb +37 -16
  46. data/lib/devise/models/database_authenticatable.rb +17 -3
  47. data/lib/devise/models/lockable.rb +1 -2
  48. data/lib/devise/models/omniauthable.rb +1 -2
  49. data/lib/devise/models/recoverable.rb +10 -6
  50. data/lib/devise/models/registerable.rb +0 -1
  51. data/lib/devise/models/rememberable.rb +1 -2
  52. data/lib/devise/models/timeoutable.rb +1 -2
  53. data/lib/devise/models/token_authenticatable.rb +0 -1
  54. data/lib/devise/models/trackable.rb +0 -1
  55. data/lib/devise/models/validatable.rb +0 -1
  56. data/lib/devise/modules.rb +1 -2
  57. data/lib/devise/omniauth.rb +0 -1
  58. data/lib/devise/omniauth/config.rb +0 -1
  59. data/lib/devise/omniauth/url_helpers.rb +0 -1
  60. data/lib/devise/orm/active_record.rb +1 -2
  61. data/lib/devise/orm/mongoid.rb +1 -2
  62. data/lib/devise/{param_filter.rb → parameter_filter.rb} +10 -12
  63. data/lib/devise/parameter_sanitizer.rb +59 -0
  64. data/lib/devise/rails.rb +0 -1
  65. data/lib/devise/rails/routes.rb +22 -18
  66. data/lib/devise/rails/warden_compat.rb +0 -30
  67. data/lib/devise/strategies/authenticatable.rb +8 -6
  68. data/lib/devise/strategies/base.rb +1 -2
  69. data/lib/devise/strategies/database_authenticatable.rb +1 -2
  70. data/lib/devise/strategies/rememberable.rb +1 -2
  71. data/lib/devise/strategies/token_authenticatable.rb +38 -4
  72. data/lib/devise/test_helpers.rb +0 -1
  73. data/lib/devise/time_inflector.rb +1 -2
  74. data/lib/devise/version.rb +1 -2
  75. data/lib/generators/active_record/devise_generator.rb +1 -5
  76. data/lib/generators/active_record/templates/migration.rb +0 -1
  77. data/lib/generators/active_record/templates/migration_existing.rb +0 -1
  78. data/lib/generators/devise/devise_generator.rb +0 -1
  79. data/lib/generators/devise/install_generator.rb +0 -1
  80. data/lib/generators/devise/orm_helpers.rb +1 -2
  81. data/lib/generators/devise/views_generator.rb +8 -3
  82. data/lib/generators/mongoid/devise_generator.rb +1 -2
  83. data/lib/generators/templates/README +1 -1
  84. data/lib/generators/templates/devise.rb +10 -5
  85. data/lib/generators/templates/markerb/confirmation_instructions.markerb +1 -1
  86. data/lib/generators/templates/simple_form_for/confirmations/new.html.erb +1 -0
  87. data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +6 -1
  88. data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +1 -0
  89. data/loyal_devise.gemspec +27 -0
  90. data/test/controllers/custom_strategy_test.rb +0 -1
  91. data/test/controllers/helpers_test.rb +0 -1
  92. data/test/controllers/internal_helpers_test.rb +13 -4
  93. data/test/controllers/passwords_controller_test.rb +32 -0
  94. data/test/controllers/sessions_controller_test.rb +28 -1
  95. data/test/controllers/url_helpers_test.rb +0 -1
  96. data/test/delegator_test.rb +0 -1
  97. data/test/devise_test.rb +12 -2
  98. data/test/failure_app_test.rb +3 -4
  99. data/test/generators/active_record_generator_test.rb +1 -4
  100. data/test/generators/devise_generator_test.rb +0 -1
  101. data/test/generators/install_generator_test.rb +0 -1
  102. data/test/generators/mongoid_generator_test.rb +0 -1
  103. data/test/generators/views_generator_test.rb +16 -2
  104. data/test/helpers/devise_helper_test.rb +1 -2
  105. data/test/integration/authenticatable_test.rb +92 -27
  106. data/test/integration/confirmable_test.rb +7 -7
  107. data/test/integration/database_authenticatable_test.rb +8 -7
  108. data/test/integration/http_authenticatable_test.rb +19 -2
  109. data/test/integration/lockable_test.rb +1 -2
  110. data/test/integration/omniauthable_test.rb +2 -3
  111. data/test/integration/recoverable_test.rb +40 -12
  112. data/test/integration/registerable_test.rb +17 -14
  113. data/test/integration/rememberable_test.rb +16 -10
  114. data/test/integration/timeoutable_test.rb +11 -2
  115. data/test/integration/token_authenticatable_test.rb +45 -2
  116. data/test/integration/trackable_test.rb +1 -2
  117. data/test/mailers/confirmation_instructions_test.rb +11 -3
  118. data/test/mailers/reset_password_instructions_test.rb +11 -3
  119. data/test/mailers/unlock_instructions_test.rb +11 -2
  120. data/test/mapping_test.rb +0 -1
  121. data/test/models/authenticatable_test.rb +6 -1
  122. data/test/models/confirmable_test.rb +53 -2
  123. data/test/models/database_authenticatable_test.rb +57 -21
  124. data/test/models/lockable_test.rb +1 -2
  125. data/test/models/omniauthable_test.rb +0 -1
  126. data/test/models/recoverable_test.rb +21 -5
  127. data/test/models/registerable_test.rb +0 -1
  128. data/test/models/rememberable_test.rb +4 -4
  129. data/test/models/serializable_test.rb +8 -8
  130. data/test/models/timeoutable_test.rb +0 -1
  131. data/test/models/token_authenticatable_test.rb +0 -1
  132. data/test/models/trackable_test.rb +0 -1
  133. data/test/models/validatable_test.rb +16 -6
  134. data/test/models_test.rb +7 -24
  135. data/test/omniauth/config_test.rb +1 -2
  136. data/test/omniauth/url_helpers_test.rb +4 -2
  137. data/test/orm/active_record.rb +1 -1
  138. data/test/orm/mongoid.rb +2 -4
  139. data/test/parameter_sanitizer_test.rb +51 -0
  140. data/test/rails_app/Rakefile +0 -4
  141. data/test/rails_app/app/active_record/admin.rb +0 -1
  142. data/test/rails_app/app/active_record/shim.rb +1 -2
  143. data/test/rails_app/app/active_record/user.rb +0 -1
  144. data/test/rails_app/app/controllers/admins/sessions_controller.rb +1 -2
  145. data/test/rails_app/app/controllers/admins_controller.rb +0 -1
  146. data/test/rails_app/app/controllers/application_controller.rb +1 -1
  147. data/test/rails_app/app/controllers/home_controller.rb +0 -1
  148. data/test/rails_app/app/controllers/publisher/registrations_controller.rb +1 -2
  149. data/test/rails_app/app/controllers/publisher/sessions_controller.rb +1 -2
  150. data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +1 -2
  151. data/test/rails_app/app/controllers/users_controller.rb +8 -1
  152. data/test/rails_app/app/helpers/application_helper.rb +0 -1
  153. data/test/rails_app/app/mailers/users/mailer.rb +4 -1
  154. data/test/rails_app/app/mongoid/admin.rb +4 -3
  155. data/test/rails_app/app/mongoid/shim.rb +3 -5
  156. data/test/rails_app/app/mongoid/user.rb +2 -3
  157. data/test/rails_app/app/views/users/edit_form.html.erb +1 -0
  158. data/test/rails_app/bin/bundle +3 -0
  159. data/test/rails_app/bin/rails +4 -0
  160. data/test/rails_app/bin/rake +4 -0
  161. data/test/rails_app/config/application.rb +1 -3
  162. data/test/rails_app/config/boot.rb +3 -4
  163. data/test/rails_app/config/environment.rb +2 -3
  164. data/test/rails_app/config/environments/development.rb +23 -8
  165. data/test/rails_app/config/environments/production.rb +68 -18
  166. data/test/rails_app/config/environments/test.rb +18 -16
  167. data/test/rails_app/config/initializers/backtrace_silencers.rb +0 -1
  168. data/test/rails_app/config/initializers/devise.rb +0 -1
  169. data/test/rails_app/config/initializers/inflections.rb +0 -1
  170. data/test/rails_app/config/initializers/secret_token.rb +8 -3
  171. data/test/rails_app/config/initializers/session_store.rb +1 -0
  172. data/test/rails_app/config/routes.rb +20 -17
  173. data/test/rails_app/db/migrate/20100401102949_create_tables.rb +0 -1
  174. data/test/rails_app/db/schema.rb +0 -1
  175. data/test/rails_app/lib/shared_admin.rb +0 -1
  176. data/test/rails_app/lib/shared_user.rb +0 -2
  177. data/test/routes_test.rb +22 -21
  178. data/test/support/assertions.rb +0 -1
  179. data/test/support/helpers.rb +1 -2
  180. data/test/support/integration.rb +0 -1
  181. data/test/support/webrat/integrations/rails.rb +0 -1
  182. data/test/test_helper.rb +8 -2
  183. data/test/test_helpers_test.rb +0 -1
  184. data/test/test_models.rb +26 -0
  185. metadata +65 -27
  186. data/gemfiles/Gemfile.rails-3.1.x.lock +0 -167
  187. data/test/indifferent_hash.rb +0 -34
  188. data/test/rails_app/script/rails +0 -10
@@ -1,4 +1,3 @@
1
- # -*- encoding : utf-8 -*-
2
1
  require 'test_helper'
3
2
 
4
3
  class RoutesTest < ActionController::TestCase
@@ -1,4 +1,3 @@
1
- # -*- encoding : utf-8 -*-
2
1
  require 'test_helper'
3
2
 
4
3
  class DelegatorTest < ActiveSupport::TestCase
@@ -1,4 +1,3 @@
1
- # -*- encoding : utf-8 -*-
2
1
  require 'test_helper'
3
2
 
4
3
  module Devise
@@ -69,5 +68,16 @@ class DeviseTest < ActiveSupport::TestCase
69
68
  end
70
69
  assert_not Devise.secure_compare("size_1", "size_four")
71
70
  end
72
-
71
+
72
+ test 'Devise.email_regexp should match valid email addresses' do
73
+ valid_emails = ["test@example.com", "jo@jo.co", "f4$_m@you.com", "testing.example@example.com.ua"]
74
+ non_valid_emails = ["rex", "test@go,com", "test user@example.com", "test_user@example server.com"]
75
+
76
+ valid_emails.each do |email|
77
+ assert_match Devise.email_regexp, email
78
+ end
79
+ non_valid_emails.each do |email|
80
+ assert_no_match Devise.email_regexp, email
81
+ end
82
+ end
73
83
  end
@@ -1,4 +1,3 @@
1
- # -*- encoding : utf-8 -*-
2
1
  require 'test_helper'
3
2
  require 'ostruct'
4
3
 
@@ -81,9 +80,9 @@ class FailureTest < ActiveSupport::TestCase
81
80
 
82
81
  test 'setup a default message' do
83
82
  call_failure
84
- assert_match /You are being/, @response.last.body
85
- assert_match /redirected/, @response.last.body
86
- assert_match /users\/sign_in/, @response.last.body
83
+ assert_match(/You are being/, @response.last.body)
84
+ assert_match(/redirected/, @response.last.body)
85
+ assert_match(/users\/sign_in/, @response.last.body)
87
86
  end
88
87
 
89
88
  test 'works for any navigational format' do
@@ -1,4 +1,3 @@
1
- # -*- encoding : utf-8 -*-
2
1
  require "test_helper"
3
2
 
4
3
  if DEVISE_ORM == :active_record
@@ -11,13 +10,11 @@ if DEVISE_ORM == :active_record
11
10
 
12
11
  test "all files are properly created with rails31 migration syntax" do
13
12
  run_generator %w(monster)
14
- assert_file "app/models/monster.rb", /devise/, /attr_accessible (:[a-z_]+(, )?)+/
15
13
  assert_migration "db/migrate/devise_create_monsters.rb", /def change/
16
14
  end
17
15
 
18
16
  test "all files for namespaced model are properly created" do
19
17
  run_generator %w(admin/monster)
20
- assert_file "app/models/admin/monster.rb", /devise/, /attr_accessible (:[a-z_]+(, )?)+/
21
18
  assert_migration "db/migrate/devise_create_admin_monsters.rb", /def change/
22
19
  end
23
20
 
@@ -69,7 +66,7 @@ if DEVISE_ORM == :active_record
69
66
  simulate_inside_engine(RailsEngine::Engine, RailsEngine) do
70
67
  run_generator ["monster"]
71
68
 
72
- assert_file "app/models/rails_engine/monster.rb", /devise/,/attr_accessible (:[a-z_]+(, )?)+/
69
+ assert_file "app/models/rails_engine/monster.rb", /devise/
73
70
  end
74
71
  end
75
72
  end
@@ -1,4 +1,3 @@
1
- # -*- encoding : utf-8 -*-
2
1
  require 'test_helper'
3
2
 
4
3
  require "generators/devise/devise_generator"
@@ -1,4 +1,3 @@
1
- # -*- encoding : utf-8 -*-
2
1
  require "test_helper"
3
2
 
4
3
  class InstallGeneratorTest < Rails::Generators::TestCase
@@ -1,4 +1,3 @@
1
- # -*- encoding : utf-8 -*-
2
1
  require "test_helper"
3
2
 
4
3
  if DEVISE_ORM == :mongoid
@@ -1,4 +1,3 @@
1
- # -*- encoding : utf-8 -*-
2
1
  require "test_helper"
3
2
 
4
3
  class ViewsGeneratorTest < Rails::Generators::TestCase
@@ -9,14 +8,17 @@ class ViewsGeneratorTest < Rails::Generators::TestCase
9
8
  test "Assert all views are properly created with no params" do
10
9
  run_generator
11
10
  assert_files
11
+ assert_shared_links
12
12
  end
13
13
 
14
- test "Assert all views are properly created with scope param param" do
14
+ test "Assert all views are properly created with scope param" do
15
15
  run_generator %w(users)
16
16
  assert_files "users"
17
+ assert_shared_links "users"
17
18
 
18
19
  run_generator %w(admins)
19
20
  assert_files "admins"
21
+ assert_shared_links "admins"
20
22
  end
21
23
 
22
24
  test "Assert views with simple form" do
@@ -50,4 +52,16 @@ class ViewsGeneratorTest < Rails::Generators::TestCase
50
52
  assert_file "app/views/#{scope}/shared/_links.erb"
51
53
  assert_file "app/views/#{scope}/unlocks/new.html.erb"
52
54
  end
55
+
56
+ def assert_shared_links(scope = nil)
57
+ scope = "devise" if scope.nil?
58
+ link = /<%= render \"#{scope}\/shared\/links\" %>/
59
+
60
+ assert_file "app/views/#{scope}/passwords/edit.html.erb", link
61
+ assert_file "app/views/#{scope}/passwords/new.html.erb", link
62
+ assert_file "app/views/#{scope}/confirmations/new.html.erb", link
63
+ assert_file "app/views/#{scope}/registrations/new.html.erb", link
64
+ assert_file "app/views/#{scope}/sessions/new.html.erb", link
65
+ assert_file "app/views/#{scope}/unlocks/new.html.erb", link
66
+ end
53
67
  end
@@ -1,7 +1,6 @@
1
- # -*- encoding : utf-8 -*-
2
1
  require 'test_helper'
3
2
 
4
- class DeviseHelperTest < ActionController::IntegrationTest
3
+ class DeviseHelperTest < ActionDispatch::IntegrationTest
5
4
  setup do
6
5
  model_labels = { :models => { :user => "utilisateur" } }
7
6
 
@@ -1,7 +1,6 @@
1
- # -*- encoding : utf-8 -*-
2
1
  require 'test_helper'
3
2
 
4
- class AuthenticationSanityTest < ActionController::IntegrationTest
3
+ class AuthenticationSanityTest < ActionDispatch::IntegrationTest
5
4
  test 'home should be accessible without sign in' do
6
5
  visit '/'
7
6
  assert_response :success
@@ -135,7 +134,7 @@ class AuthenticationSanityTest < ActionController::IntegrationTest
135
134
  end
136
135
  end
137
136
 
138
- class AuthenticationRoutesRestrictions < ActionController::IntegrationTest
137
+ class AuthenticationRoutesRestrictions < ActionDispatch::IntegrationTest
139
138
  test 'not signed in should not be able to access private route (authenticate denied)' do
140
139
  get private_path
141
140
  assert_redirected_to new_admin_session_path
@@ -192,7 +191,7 @@ class AuthenticationRoutesRestrictions < ActionController::IntegrationTest
192
191
  get dashboard_path
193
192
 
194
193
  assert_response :success
195
- assert_template 'home/admin'
194
+ assert_template 'home/admin_dashboard'
196
195
  assert_contain 'Admin dashboard'
197
196
  end
198
197
 
@@ -204,7 +203,7 @@ class AuthenticationRoutesRestrictions < ActionController::IntegrationTest
204
203
  get dashboard_path
205
204
 
206
205
  assert_response :success
207
- assert_template 'home/user'
206
+ assert_template 'home/user_dashboard'
208
207
  assert_contain 'User dashboard'
209
208
  end
210
209
 
@@ -255,7 +254,7 @@ class AuthenticationRoutesRestrictions < ActionController::IntegrationTest
255
254
  end
256
255
  end
257
256
 
258
- class AuthenticationRedirectTest < ActionController::IntegrationTest
257
+ class AuthenticationRedirectTest < ActionDispatch::IntegrationTest
259
258
  test 'redirect from warden shows sign in or sign up message' do
260
259
  get admins_path
261
260
 
@@ -318,7 +317,7 @@ class AuthenticationRedirectTest < ActionController::IntegrationTest
318
317
  end
319
318
  end
320
319
 
321
- class AuthenticationSessionTest < ActionController::IntegrationTest
320
+ class AuthenticationSessionTest < ActionDispatch::IntegrationTest
322
321
  test 'destroyed account is signed out' do
323
322
  sign_in_as_user
324
323
  get '/users'
@@ -334,22 +333,34 @@ class AuthenticationSessionTest < ActionController::IntegrationTest
334
333
  assert_equal "Cart", @controller.user_session[:cart]
335
334
  end
336
335
 
337
- test 'does not explode when invalid user class is stored in session' do
338
- klass = User
339
- paths = ActiveSupport::Dependencies.autoload_paths.dup
340
-
336
+ test 'does not explode when class name is still stored in session' do
337
+ # In order to test that old sessions do not break with the new scoped
338
+ # deserialization, we need to serialize the session the old way. This is
339
+ # done by removing the newly used scoped serialization method
340
+ # (#user_serialize) and bringing back the old uncsoped #serialize method
341
+ # that includes the record's class name in the serialization.
341
342
  begin
343
+ Warden::SessionSerializer.class_eval do
344
+ alias_method :original_serialize, :serialize
345
+ alias_method :original_user_serialize, :user_serialize
346
+ remove_method :user_serialize
347
+
348
+ def serialize(record)
349
+ klass = record.class
350
+ array = klass.serialize_into_session(record)
351
+ array.unshift(klass.name)
352
+ end
353
+ end
354
+
342
355
  sign_in_as_user
343
356
  assert warden.authenticated?(:user)
344
-
345
- Object.send :remove_const, :User
346
- ActiveSupport::Dependencies.autoload_paths.clear
347
-
348
- visit "/users"
349
- assert_not warden.authenticated?(:user)
350
357
  ensure
351
- Object.const_set(:User, klass)
352
- ActiveSupport::Dependencies.autoload_paths.replace(paths)
358
+ Warden::SessionSerializer.class_eval do
359
+ alias_method :serialize, :original_serialize
360
+ remove_method :original_serialize
361
+ alias_method :user_serialize, :original_user_serialize
362
+ remove_method :original_user_serialize
363
+ end
353
364
  end
354
365
  end
355
366
 
@@ -365,7 +376,7 @@ class AuthenticationSessionTest < ActionController::IntegrationTest
365
376
  end
366
377
  end
367
378
 
368
- class AuthenticationWithScopedViewsTest < ActionController::IntegrationTest
379
+ class AuthenticationWithScopedViewsTest < ActionDispatch::IntegrationTest
369
380
  test 'renders the scoped view if turned on and view is available' do
370
381
  swap Devise, :scoped_views => true do
371
382
  assert_raise Webrat::NotFoundError do
@@ -406,7 +417,7 @@ class AuthenticationWithScopedViewsTest < ActionController::IntegrationTest
406
417
  end
407
418
  end
408
419
 
409
- class AuthenticationOthersTest < ActionController::IntegrationTest
420
+ class AuthenticationOthersTest < ActionDispatch::IntegrationTest
410
421
  test 'handles unverified requests gets rid of caches' do
411
422
  swap UsersController, :allow_forgery_protection => true do
412
423
  post exhibit_user_url(1)
@@ -457,7 +468,7 @@ class AuthenticationOthersTest < ActionController::IntegrationTest
457
468
  assert_match '<?xml version="1.0" encoding="UTF-8"?>', response.body
458
469
  assert_match /<user>.*<\/user>/m, response.body
459
470
  assert_match '<email></email>', response.body
460
- assert_match '<password nil="true"></password>', response.body
471
+ assert_match '<password nil="true"', response.body
461
472
  end
462
473
 
463
474
  test 'sign in stub in json format' do
@@ -505,22 +516,53 @@ class AuthenticationOthersTest < ActionController::IntegrationTest
505
516
  assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>)
506
517
  end
507
518
 
508
- test 'sign out with xml format returns ok response' do
519
+ test 'sign out with html redirects' do
520
+ sign_in_as_user
521
+ get destroy_user_session_path
522
+ assert_response :redirect
523
+ assert_current_url '/'
524
+
525
+ sign_in_as_user
526
+ get destroy_user_session_path(:format => 'html')
527
+ assert_response :redirect
528
+ assert_current_url '/'
529
+ end
530
+
531
+ test 'sign out with xml format returns no content' do
509
532
  sign_in_as_user
510
533
  get destroy_user_session_path(:format => 'xml')
511
534
  assert_response :no_content
512
535
  assert_not warden.authenticated?(:user)
513
536
  end
514
537
 
515
- test 'sign out with json format returns empty json response' do
538
+ test 'sign out with json format returns no content' do
516
539
  sign_in_as_user
517
540
  get destroy_user_session_path(:format => 'json')
518
541
  assert_response :no_content
519
542
  assert_not warden.authenticated?(:user)
520
543
  end
544
+
545
+ test 'sign out with non-navigational format via XHR does not redirect' do
546
+ swap Devise, :navigational_formats => ['*/*', :html] do
547
+ sign_in_as_user
548
+ xml_http_request :get, destroy_user_session_path, {}, { "HTTP_ACCEPT" => "application/json,text/javascript,*/*" } # NOTE: Bug is triggered by combination of XHR and */*.
549
+ assert_response :no_content
550
+ assert_not warden.authenticated?(:user)
551
+ end
552
+ end
553
+
554
+ # Belt and braces ... Perhaps this test is not necessary?
555
+ test 'sign out with navigational format via XHR does redirect' do
556
+ swap Devise, :navigational_formats => ['*/*', :html] do
557
+ sign_in_as_user
558
+ xml_http_request :get, destroy_user_session_path, {}, { "HTTP_ACCEPT" => "text/html,*/*" }
559
+ assert_response :redirect
560
+ assert_not warden.authenticated?(:user)
561
+ end
562
+ end
521
563
  end
522
564
 
523
- class AuthenticationKeysTest < ActionController::IntegrationTest
565
+ class AuthenticationKeysTest < ActionDispatch::IntegrationTest
524
566
  test 'missing authentication keys cause authentication to abort' do
525
567
  swap Devise, :authentication_keys => [:subdomain] do
526
568
  sign_in_as_user
@@ -537,7 +579,7 @@ class AuthenticationKeysTest < ActionController::IntegrationTest
537
579
  end
538
580
  end
539
581
 
540
- class AuthenticationRequestKeysTest < ActionController::IntegrationTest
582
+ class AuthenticationRequestKeysTest < ActionDispatch::IntegrationTest
541
583
  test 'request keys are used on authentication' do
542
584
  host! 'foo.bar.baz'
543
585
 
@@ -578,7 +620,7 @@ class AuthenticationRequestKeysTest < ActionController::IntegrationTest
578
620
  end
579
621
  end
580
622
 
581
- class AuthenticationSignOutViaTest < ActionController::IntegrationTest
623
+ class AuthenticationSignOutViaTest < ActionDispatch::IntegrationTest
582
624
  def sign_in!(scope)
583
625
  sign_in_as_admin(:visit => send("new_#{scope}_session_path"))
584
626
  assert warden.authenticated?(scope)
@@ -632,3 +674,26 @@ class AuthenticationSignOutViaTest < ActionController::IntegrationTest
632
674
  assert warden.authenticated?(:sign_out_via_delete_or_post)
633
675
  end
634
676
  end
677
+
678
+ class DoubleAuthenticationRedirectTest < ActionDispatch::IntegrationTest
679
+ test 'signed in as user redirects when visiting user sign in page' do
680
+ sign_in_as_user
681
+ get new_user_session_path(:format => :html)
682
+ assert_redirected_to '/'
683
+ end
684
+
685
+ test 'signed in as admin redirects when visiting admin sign in page' do
686
+ sign_in_as_admin
687
+ get new_admin_session_path(:format => :html)
688
+ assert_redirected_to '/admin_area/home'
689
+ end
690
+
691
+ test 'signed in as both user and admin redirects when visiting admin sign in page' do
692
+ sign_in_as_user
693
+ sign_in_as_admin
694
+ get new_user_session_path(:format => :html)
695
+ assert_redirected_to '/'
696
+ get new_admin_session_path(:format => :html)
697
+ assert_redirected_to '/admin_area/home'
698
+ end
699
+ end
@@ -1,7 +1,6 @@
1
- # -*- encoding : utf-8 -*-
2
1
  require 'test_helper'
3
2
 
4
- class ConfirmationTest < ActionController::IntegrationTest
3
+ class ConfirmationTest < ActionDispatch::IntegrationTest
5
4
 
6
5
  def visit_user_confirmation_with_token(confirmation_token)
7
6
  visit user_confirmation_path(:confirmation_token => confirmation_token)
@@ -168,7 +167,7 @@ class ConfirmationTest < ActionController::IntegrationTest
168
167
  end
169
168
 
170
169
  test 'resent confirmation token with invalid E-Mail in XML format should return invalid response' do
171
- user = create_user(:confirm => false)
170
+ create_user(:confirm => false)
172
171
  post user_confirmation_path(:format => 'xml'), :user => { :email => 'invalid.test@test.com' }
173
172
  assert_response :unprocessable_entity
174
173
  assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
@@ -182,7 +181,7 @@ class ConfirmationTest < ActionController::IntegrationTest
182
181
  end
183
182
 
184
183
  test 'confirm account with invalid confirmation token in XML format should return invalid response' do
185
- user = create_user(:confirm => false)
184
+ create_user(:confirm => false)
186
185
  get user_confirmation_path(:confirmation_token => 'invalid_confirmation', :format => 'xml')
187
186
  assert_response :unprocessable_entity
188
187
  assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
@@ -227,7 +226,7 @@ class ConfirmationTest < ActionController::IntegrationTest
227
226
  end
228
227
  end
229
228
 
230
- class ConfirmationOnChangeTest < ActionController::IntegrationTest
229
+ class ConfirmationOnChangeTest < ActionDispatch::IntegrationTest
231
230
  def create_second_admin(options={})
232
231
  @admin = nil
233
232
  create_admin(options)
@@ -269,13 +268,14 @@ class ConfirmationOnChangeTest < ActionController::IntegrationTest
269
268
  admin = create_admin
270
269
  admin.update_attributes(:email => 'first_test@example.com')
271
270
  assert_equal 'first_test@example.com', admin.unconfirmed_email
271
+
272
272
  confirmation_token = admin.confirmation_token
273
273
  admin.update_attributes(:email => 'second_test@example.com')
274
274
  assert_equal 'second_test@example.com', admin.unconfirmed_email
275
275
 
276
276
  visit_admin_confirmation_with_token(confirmation_token)
277
277
  assert_have_selector '#error_explanation'
278
- assert_contain /Confirmation token(.*)invalid/
278
+ assert_contain(/Confirmation token(.*)invalid/)
279
279
 
280
280
  visit_admin_confirmation_with_token(admin.confirmation_token)
281
281
  assert_contain 'Your account was successfully confirmed.'
@@ -293,7 +293,7 @@ class ConfirmationOnChangeTest < ActionController::IntegrationTest
293
293
 
294
294
  visit_admin_confirmation_with_token(admin.confirmation_token)
295
295
  assert_have_selector '#error_explanation'
296
- assert_contain /Email.*already.*taken/
296
+ assert_contain(/Email.*already.*taken/)
297
297
  assert admin.reload.pending_reconfirmation?
298
298
  end
299
299
  end
@@ -1,7 +1,6 @@
1
- # -*- encoding : utf-8 -*-
2
1
  require 'test_helper'
3
2
 
4
- class DatabaseAuthenticationTest < ActionController::IntegrationTest
3
+ class DatabaseAuthenticationTest < ActionDispatch::IntegrationTest
5
4
  test 'sign in with email of different case should succeed when email is in the list of case insensitive keys' do
6
5
  create_user(:email => 'Foo@Bar.com')
7
6
 
@@ -54,12 +53,14 @@ class DatabaseAuthenticationTest < ActionController::IntegrationTest
54
53
  end
55
54
 
56
55
  test 'sign in with invalid email should return to sign in form with error message' do
57
- sign_in_as_admin do
58
- fill_in 'email', :with => 'wrongemail@test.com'
59
- end
56
+ store_translations :en, :devise => { :failure => { :admin => { :not_found_in_database => 'Invalid email address' } } } do
57
+ sign_in_as_admin do
58
+ fill_in 'email', :with => 'wrongemail@test.com'
59
+ end
60
60
 
61
- assert_contain 'Invalid email or password'
62
- assert_not warden.authenticated?(:admin)
61
+ assert_contain 'Invalid email address'
62
+ assert_not warden.authenticated?(:admin)
63
+ end
63
64
  end
64
65
 
65
66
  test 'sign in with invalid pasword should return to sign in form with error message' do