loyal_devise 2.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (208) hide show
  1. data/.gitignore +10 -0
  2. data/.travis.yml +15 -0
  3. data/CHANGELOG.rdoc +881 -0
  4. data/CONTRIBUTING.md +12 -0
  5. data/Gemfile +31 -0
  6. data/Gemfile.lock +154 -0
  7. data/MIT-LICENSE +20 -0
  8. data/README.md +388 -0
  9. data/Rakefile +34 -0
  10. data/app/controllers/devise/confirmations_controller.rb +44 -0
  11. data/app/controllers/devise/omniauth_callbacks_controller.rb +31 -0
  12. data/app/controllers/devise/passwords_controller.rb +57 -0
  13. data/app/controllers/devise/registrations_controller.rb +120 -0
  14. data/app/controllers/devise/sessions_controller.rb +51 -0
  15. data/app/controllers/devise/unlocks_controller.rb +45 -0
  16. data/app/controllers/devise_controller.rb +193 -0
  17. data/app/helpers/devise_helper.rb +26 -0
  18. data/app/mailers/devise/mailer.rb +16 -0
  19. data/app/views/devise/_links.erb +3 -0
  20. data/app/views/devise/confirmations/new.html.erb +12 -0
  21. data/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
  22. data/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
  23. data/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
  24. data/app/views/devise/passwords/edit.html.erb +16 -0
  25. data/app/views/devise/passwords/new.html.erb +12 -0
  26. data/app/views/devise/registrations/edit.html.erb +25 -0
  27. data/app/views/devise/registrations/new.html.erb +18 -0
  28. data/app/views/devise/sessions/new.html.erb +17 -0
  29. data/app/views/devise/shared/_links.erb +25 -0
  30. data/app/views/devise/unlocks/new.html.erb +12 -0
  31. data/config/locales/en.yml +59 -0
  32. data/devise.gemspec +26 -0
  33. data/gemfiles/Gemfile.rails-3.1.x +35 -0
  34. data/gemfiles/Gemfile.rails-3.1.x.lock +167 -0
  35. data/lib/devise/controllers/helpers.rb +273 -0
  36. data/lib/devise/controllers/rememberable.rb +53 -0
  37. data/lib/devise/controllers/scoped_views.rb +18 -0
  38. data/lib/devise/controllers/url_helpers.rb +68 -0
  39. data/lib/devise/delegator.rb +17 -0
  40. data/lib/devise/failure_app.rb +188 -0
  41. data/lib/devise/hooks/activatable.rb +12 -0
  42. data/lib/devise/hooks/forgetable.rb +10 -0
  43. data/lib/devise/hooks/lockable.rb +8 -0
  44. data/lib/devise/hooks/rememberable.rb +7 -0
  45. data/lib/devise/hooks/timeoutable.rb +26 -0
  46. data/lib/devise/hooks/trackable.rb +10 -0
  47. data/lib/devise/mailers/helpers.rb +92 -0
  48. data/lib/devise/mapping.rb +173 -0
  49. data/lib/devise/models/authenticatable.rb +269 -0
  50. data/lib/devise/models/confirmable.rb +271 -0
  51. data/lib/devise/models/database_authenticatable.rb +127 -0
  52. data/lib/devise/models/lockable.rb +194 -0
  53. data/lib/devise/models/omniauthable.rb +28 -0
  54. data/lib/devise/models/recoverable.rb +141 -0
  55. data/lib/devise/models/registerable.rb +26 -0
  56. data/lib/devise/models/rememberable.rb +126 -0
  57. data/lib/devise/models/timeoutable.rb +50 -0
  58. data/lib/devise/models/token_authenticatable.rb +90 -0
  59. data/lib/devise/models/trackable.rb +36 -0
  60. data/lib/devise/models/validatable.rb +67 -0
  61. data/lib/devise/models.rb +129 -0
  62. data/lib/devise/modules.rb +30 -0
  63. data/lib/devise/omniauth/config.rb +46 -0
  64. data/lib/devise/omniauth/url_helpers.rb +19 -0
  65. data/lib/devise/omniauth.rb +29 -0
  66. data/lib/devise/orm/active_record.rb +4 -0
  67. data/lib/devise/orm/mongoid.rb +4 -0
  68. data/lib/devise/param_filter.rb +42 -0
  69. data/lib/devise/rails/routes.rb +447 -0
  70. data/lib/devise/rails/warden_compat.rb +44 -0
  71. data/lib/devise/rails.rb +55 -0
  72. data/lib/devise/strategies/authenticatable.rb +177 -0
  73. data/lib/devise/strategies/base.rb +21 -0
  74. data/lib/devise/strategies/database_authenticatable.rb +21 -0
  75. data/lib/devise/strategies/rememberable.rb +56 -0
  76. data/lib/devise/strategies/token_authenticatable.rb +57 -0
  77. data/lib/devise/test_helpers.rb +132 -0
  78. data/lib/devise/time_inflector.rb +15 -0
  79. data/lib/devise/version.rb +4 -0
  80. data/lib/devise.rb +445 -0
  81. data/lib/generators/active_record/devise_generator.rb +80 -0
  82. data/lib/generators/active_record/templates/migration.rb +20 -0
  83. data/lib/generators/active_record/templates/migration_existing.rb +27 -0
  84. data/lib/generators/devise/devise_generator.rb +25 -0
  85. data/lib/generators/devise/install_generator.rb +25 -0
  86. data/lib/generators/devise/orm_helpers.rb +33 -0
  87. data/lib/generators/devise/views_generator.rb +117 -0
  88. data/lib/generators/mongoid/devise_generator.rb +58 -0
  89. data/lib/generators/templates/README +35 -0
  90. data/lib/generators/templates/devise.rb +241 -0
  91. data/lib/generators/templates/markerb/confirmation_instructions.markerb +5 -0
  92. data/lib/generators/templates/markerb/reset_password_instructions.markerb +8 -0
  93. data/lib/generators/templates/markerb/unlock_instructions.markerb +7 -0
  94. data/lib/generators/templates/simple_form_for/confirmations/new.html.erb +15 -0
  95. data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +19 -0
  96. data/lib/generators/templates/simple_form_for/passwords/new.html.erb +15 -0
  97. data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +22 -0
  98. data/lib/generators/templates/simple_form_for/registrations/new.html.erb +17 -0
  99. data/lib/generators/templates/simple_form_for/sessions/new.html.erb +15 -0
  100. data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +15 -0
  101. data/test/controllers/custom_strategy_test.rb +63 -0
  102. data/test/controllers/helpers_test.rb +254 -0
  103. data/test/controllers/internal_helpers_test.rb +111 -0
  104. data/test/controllers/sessions_controller_test.rb +58 -0
  105. data/test/controllers/url_helpers_test.rb +60 -0
  106. data/test/delegator_test.rb +20 -0
  107. data/test/devise_test.rb +73 -0
  108. data/test/failure_app_test.rb +222 -0
  109. data/test/generators/active_record_generator_test.rb +76 -0
  110. data/test/generators/devise_generator_test.rb +40 -0
  111. data/test/generators/install_generator_test.rb +14 -0
  112. data/test/generators/mongoid_generator_test.rb +24 -0
  113. data/test/generators/views_generator_test.rb +53 -0
  114. data/test/helpers/devise_helper_test.rb +52 -0
  115. data/test/indifferent_hash.rb +34 -0
  116. data/test/integration/authenticatable_test.rb +634 -0
  117. data/test/integration/confirmable_test.rb +299 -0
  118. data/test/integration/database_authenticatable_test.rb +83 -0
  119. data/test/integration/http_authenticatable_test.rb +98 -0
  120. data/test/integration/lockable_test.rb +243 -0
  121. data/test/integration/omniauthable_test.rb +134 -0
  122. data/test/integration/recoverable_test.rb +307 -0
  123. data/test/integration/registerable_test.rb +346 -0
  124. data/test/integration/rememberable_test.rb +159 -0
  125. data/test/integration/timeoutable_test.rb +141 -0
  126. data/test/integration/token_authenticatable_test.rb +162 -0
  127. data/test/integration/trackable_test.rb +93 -0
  128. data/test/mailers/confirmation_instructions_test.rb +103 -0
  129. data/test/mailers/reset_password_instructions_test.rb +84 -0
  130. data/test/mailers/unlock_instructions_test.rb +78 -0
  131. data/test/mapping_test.rb +128 -0
  132. data/test/models/authenticatable_test.rb +8 -0
  133. data/test/models/confirmable_test.rb +392 -0
  134. data/test/models/database_authenticatable_test.rb +190 -0
  135. data/test/models/lockable_test.rb +274 -0
  136. data/test/models/omniauthable_test.rb +8 -0
  137. data/test/models/recoverable_test.rb +206 -0
  138. data/test/models/registerable_test.rb +8 -0
  139. data/test/models/rememberable_test.rb +175 -0
  140. data/test/models/serializable_test.rb +49 -0
  141. data/test/models/timeoutable_test.rb +47 -0
  142. data/test/models/token_authenticatable_test.rb +56 -0
  143. data/test/models/trackable_test.rb +14 -0
  144. data/test/models/validatable_test.rb +117 -0
  145. data/test/models_test.rb +180 -0
  146. data/test/omniauth/config_test.rb +58 -0
  147. data/test/omniauth/url_helpers_test.rb +52 -0
  148. data/test/orm/active_record.rb +10 -0
  149. data/test/orm/mongoid.rb +15 -0
  150. data/test/rails_app/Rakefile +10 -0
  151. data/test/rails_app/app/active_record/admin.rb +7 -0
  152. data/test/rails_app/app/active_record/shim.rb +3 -0
  153. data/test/rails_app/app/active_record/user.rb +7 -0
  154. data/test/rails_app/app/controllers/admins/sessions_controller.rb +7 -0
  155. data/test/rails_app/app/controllers/admins_controller.rb +12 -0
  156. data/test/rails_app/app/controllers/application_controller.rb +9 -0
  157. data/test/rails_app/app/controllers/home_controller.rb +26 -0
  158. data/test/rails_app/app/controllers/publisher/registrations_controller.rb +3 -0
  159. data/test/rails_app/app/controllers/publisher/sessions_controller.rb +3 -0
  160. data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +15 -0
  161. data/test/rails_app/app/controllers/users_controller.rb +24 -0
  162. data/test/rails_app/app/helpers/application_helper.rb +4 -0
  163. data/test/rails_app/app/mailers/users/mailer.rb +9 -0
  164. data/test/rails_app/app/mongoid/admin.rb +28 -0
  165. data/test/rails_app/app/mongoid/shim.rb +25 -0
  166. data/test/rails_app/app/mongoid/user.rb +43 -0
  167. data/test/rails_app/app/views/admins/index.html.erb +1 -0
  168. data/test/rails_app/app/views/admins/sessions/new.html.erb +2 -0
  169. data/test/rails_app/app/views/home/admin_dashboard.html.erb +1 -0
  170. data/test/rails_app/app/views/home/index.html.erb +1 -0
  171. data/test/rails_app/app/views/home/join.html.erb +1 -0
  172. data/test/rails_app/app/views/home/private.html.erb +1 -0
  173. data/test/rails_app/app/views/home/user_dashboard.html.erb +1 -0
  174. data/test/rails_app/app/views/layouts/application.html.erb +24 -0
  175. data/test/rails_app/app/views/users/index.html.erb +1 -0
  176. data/test/rails_app/app/views/users/mailer/confirmation_instructions.erb +1 -0
  177. data/test/rails_app/app/views/users/sessions/new.html.erb +1 -0
  178. data/test/rails_app/config/application.rb +42 -0
  179. data/test/rails_app/config/boot.rb +9 -0
  180. data/test/rails_app/config/database.yml +18 -0
  181. data/test/rails_app/config/environment.rb +6 -0
  182. data/test/rails_app/config/environments/development.rb +19 -0
  183. data/test/rails_app/config/environments/production.rb +34 -0
  184. data/test/rails_app/config/environments/test.rb +34 -0
  185. data/test/rails_app/config/initializers/backtrace_silencers.rb +8 -0
  186. data/test/rails_app/config/initializers/devise.rb +179 -0
  187. data/test/rails_app/config/initializers/inflections.rb +3 -0
  188. data/test/rails_app/config/initializers/secret_token.rb +3 -0
  189. data/test/rails_app/config/routes.rb +101 -0
  190. data/test/rails_app/config.ru +4 -0
  191. data/test/rails_app/db/migrate/20100401102949_create_tables.rb +75 -0
  192. data/test/rails_app/db/schema.rb +53 -0
  193. data/test/rails_app/lib/shared_admin.rb +15 -0
  194. data/test/rails_app/lib/shared_user.rb +27 -0
  195. data/test/rails_app/public/404.html +26 -0
  196. data/test/rails_app/public/422.html +26 -0
  197. data/test/rails_app/public/500.html +26 -0
  198. data/test/rails_app/public/favicon.ico +0 -0
  199. data/test/rails_app/script/rails +10 -0
  200. data/test/routes_test.rb +249 -0
  201. data/test/support/assertions.rb +41 -0
  202. data/test/support/helpers.rb +92 -0
  203. data/test/support/integration.rb +93 -0
  204. data/test/support/locale/en.yml +4 -0
  205. data/test/support/webrat/integrations/rails.rb +25 -0
  206. data/test/test_helper.rb +28 -0
  207. data/test/test_helpers_test.rb +152 -0
  208. metadata +407 -0
@@ -0,0 +1,92 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'active_support/test_case'
3
+
4
+ class ActiveSupport::TestCase
5
+ VALID_AUTHENTICATION_TOKEN = 'AbCdEfGhIjKlMnOpQrSt'.freeze
6
+
7
+ def setup_mailer
8
+ ActionMailer::Base.deliveries = []
9
+ end
10
+
11
+ def store_translations(locale, translations, &block)
12
+ begin
13
+ I18n.backend.store_translations(locale, translations)
14
+ yield
15
+ ensure
16
+ I18n.reload!
17
+ end
18
+ end
19
+
20
+ def generate_unique_email
21
+ @@email_count ||= 0
22
+ @@email_count += 1
23
+ "test#{@@email_count}@example.com"
24
+ end
25
+
26
+ def valid_attributes(attributes={})
27
+ { :username => "usertest",
28
+ :email => generate_unique_email,
29
+ :password => '12345678',
30
+ :password_confirmation => '12345678' }.update(attributes)
31
+ end
32
+
33
+ def new_user(attributes={})
34
+ User.new(valid_attributes(attributes))
35
+ end
36
+
37
+ def create_user(attributes={})
38
+ User.create!(valid_attributes(attributes))
39
+ end
40
+
41
+ def create_admin(attributes={})
42
+ valid_attributes = valid_attributes(attributes)
43
+ valid_attributes.delete(:username)
44
+ Admin.create!(valid_attributes)
45
+ end
46
+
47
+ # Execute the block setting the given values and restoring old values after
48
+ # the block is executed.
49
+ def swap(object, new_values)
50
+ old_values = {}
51
+ new_values.each do |key, value|
52
+ old_values[key] = object.send key
53
+ object.send :"#{key}=", value
54
+ end
55
+ clear_cached_variables(new_values)
56
+ yield
57
+ ensure
58
+ clear_cached_variables(new_values)
59
+ old_values.each do |key, value|
60
+ object.send :"#{key}=", value
61
+ end
62
+ end
63
+
64
+ def clear_cached_variables(options)
65
+ if options.key?(:case_insensitive_keys) || options.key?(:strip_whitespace_keys)
66
+ Devise.mappings.each do |_, mapping|
67
+ mapping.to.instance_variable_set(:@devise_param_filter, nil)
68
+ end
69
+ end
70
+ end
71
+
72
+ def swap_module_method_existence(klass, method)
73
+ klass.module_eval %Q[
74
+ class << self
75
+ alias #{method}_referenced #{method}
76
+ undef #{method}
77
+ end
78
+ ]
79
+
80
+ begin
81
+ yield if block_given?
82
+ ensure
83
+
84
+ klass.module_eval %Q[
85
+ class << self
86
+ alias #{method} #{method}_referenced
87
+ undef #{method}_referenced
88
+ end
89
+ ]
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,93 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'action_dispatch/testing/integration'
3
+
4
+ class ActionDispatch::IntegrationTest
5
+ def warden
6
+ request.env['warden']
7
+ end
8
+
9
+ def create_user(options={})
10
+ @user ||= begin
11
+ user = User.create!(
12
+ :username => 'usertest',
13
+ :email => options[:email] || 'user@test.com',
14
+ :password => options[:password] || '12345678',
15
+ :password_confirmation => options[:password] || '12345678',
16
+ :created_at => Time.now.utc
17
+ )
18
+ user.update_attribute(:confirmation_sent_at, options[:confirmation_sent_at]) if options[:confirmation_sent_at]
19
+ user.confirm! unless options[:confirm] == false
20
+ user.lock_access! if options[:locked] == true
21
+ user
22
+ end
23
+ end
24
+
25
+ def create_admin(options={})
26
+ @admin ||= begin
27
+ admin = Admin.create!(
28
+ :email => options[:email] || 'admin@test.com',
29
+ :password => '123456', :password_confirmation => '123456',
30
+ :active => options[:active]
31
+ )
32
+ admin.confirm! unless options[:confirm] == false
33
+ admin
34
+ end
35
+ end
36
+
37
+ def sign_in_as_user(options={}, &block)
38
+ user = create_user(options)
39
+ visit_with_option options[:visit], new_user_session_path
40
+ fill_in 'email', :with => options[:email] || 'user@test.com'
41
+ fill_in 'password', :with => options[:password] || '12345678'
42
+ check 'remember me' if options[:remember_me] == true
43
+ yield if block_given?
44
+ click_button 'Sign In'
45
+ user
46
+ end
47
+
48
+ def sign_in_as_admin(options={}, &block)
49
+ admin = create_admin(options)
50
+ visit_with_option options[:visit], new_admin_session_path
51
+ fill_in 'email', :with => 'admin@test.com'
52
+ fill_in 'password', :with => '123456'
53
+ yield if block_given?
54
+ click_button 'Sign In'
55
+ admin
56
+ end
57
+
58
+ # Fix assert_redirect_to in integration sessions because they don't take into
59
+ # account Middleware redirects.
60
+ #
61
+ def assert_redirected_to(url)
62
+ assert [301, 302].include?(@integration_session.status),
63
+ "Expected status to be 301 or 302, got #{@integration_session.status}"
64
+
65
+ assert_url url, @integration_session.headers["Location"]
66
+ end
67
+
68
+ def assert_current_url(expected)
69
+ assert_url expected, current_url
70
+ end
71
+
72
+ def assert_url(expected, actual)
73
+ assert_equal prepend_host(expected), prepend_host(actual)
74
+ end
75
+
76
+ protected
77
+
78
+ def visit_with_option(given, default)
79
+ case given
80
+ when String
81
+ visit given
82
+ when FalseClass
83
+ # Do nothing
84
+ else
85
+ visit default
86
+ end
87
+ end
88
+
89
+ def prepend_host(url)
90
+ url = "http://#{request.host}#{url}" if url[0] == ?/
91
+ url
92
+ end
93
+ end
@@ -0,0 +1,4 @@
1
+ en:
2
+ errors:
3
+ messages:
4
+ taken: "has already been taken"
@@ -0,0 +1,25 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'webrat/core/elements/form'
3
+ require 'action_dispatch/testing/integration'
4
+
5
+ module Webrat
6
+ Form.class_eval do
7
+ def self.parse_rails_request_params(params)
8
+ Rack::Utils.parse_nested_query(params)
9
+ end
10
+ end
11
+
12
+ module Logging
13
+ # Avoid RAILS_DEFAULT_LOGGER deprecation warning
14
+ def logger # :nodoc:
15
+ ::Rails.logger
16
+ end
17
+ end
18
+ end
19
+
20
+ module ActionDispatch #:nodoc:
21
+ IntegrationTest.class_eval do
22
+ include Webrat::Methods
23
+ include Webrat::Matchers
24
+ end
25
+ end
@@ -0,0 +1,28 @@
1
+ # -*- encoding : utf-8 -*-
2
+ ENV["RAILS_ENV"] = "test"
3
+ DEVISE_ORM = (ENV["DEVISE_ORM"] || :active_record).to_sym
4
+
5
+ $:.unshift File.dirname(__FILE__)
6
+ puts "\n==> Devise.orm = #{DEVISE_ORM.inspect}"
7
+
8
+ require "rails_app/config/environment"
9
+ require "rails/test_help"
10
+ require "orm/#{DEVISE_ORM}"
11
+
12
+ I18n.load_path << File.expand_path("../support/locale/en.yml", __FILE__)
13
+
14
+ require 'mocha'
15
+ require 'webrat'
16
+ Webrat.configure do |config|
17
+ config.mode = :rails
18
+ config.open_error_files = false
19
+ end
20
+
21
+ # Add support to load paths so we can overwrite broken webrat setup
22
+ $:.unshift File.expand_path('../support', __FILE__)
23
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
24
+
25
+ # For generators
26
+ require "rails/generators/test_case"
27
+ require "generators/devise/install_generator"
28
+ require "generators/devise/views_generator"
@@ -0,0 +1,152 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'test_helper'
3
+
4
+ class TestHelpersTest < ActionController::TestCase
5
+ tests UsersController
6
+ include Devise::TestHelpers
7
+
8
+ class CustomFailureApp < Devise::FailureApp
9
+ def redirect
10
+ self.status = 306
11
+ end
12
+ end
13
+
14
+ test "redirects if attempting to access a page unauthenticated" do
15
+ get :index
16
+ assert_redirected_to new_user_session_path
17
+ assert_equal "You need to sign in or sign up before continuing.", flash[:alert]
18
+ end
19
+
20
+ test "redirects if attempting to access a page with an unconfirmed account" do
21
+ swap Devise, :allow_unconfirmed_access_for => 0 do
22
+ user = create_user
23
+ assert !user.active_for_authentication?
24
+
25
+ sign_in user
26
+ get :index
27
+ assert_redirected_to new_user_session_path
28
+ end
29
+ end
30
+
31
+ test "returns nil if accessing current_user with an unconfirmed account" do
32
+ swap Devise, :allow_unconfirmed_access_for => 0 do
33
+ user = create_user
34
+ assert !user.active_for_authentication?
35
+
36
+ sign_in user
37
+ get :accept, :id => user
38
+ assert_nil assigns(:current_user)
39
+ end
40
+ end
41
+
42
+ test "does not redirect with valid user" do
43
+ user = create_user
44
+ user.confirm!
45
+
46
+ sign_in user
47
+ get :index
48
+ assert_response :success
49
+ end
50
+
51
+ test "does not redirect with valid user after failed first attempt" do
52
+ get :index
53
+ assert_response :redirect
54
+
55
+ user = create_user
56
+ user.confirm!
57
+
58
+ sign_in user
59
+ get :index
60
+ assert_response :success
61
+ end
62
+
63
+ test "redirects if valid user signed out" do
64
+ user = create_user
65
+ user.confirm!
66
+
67
+ sign_in user
68
+ get :index
69
+
70
+ sign_out user
71
+ get :index
72
+ assert_redirected_to new_user_session_path
73
+ end
74
+
75
+ test "respects custom failure app" do
76
+ begin
77
+ Devise.warden_config.failure_app = CustomFailureApp
78
+ get :index
79
+ assert_response 306
80
+ ensure
81
+ Devise.warden_config.failure_app = Devise::FailureApp
82
+ end
83
+ end
84
+
85
+ test "returns the body of a failure app" do
86
+ get :index
87
+ assert_equal response.body, "<html><body>You are being <a href=\"http://test.host/users/sign_in\">redirected</a>.</body></html>"
88
+ end
89
+
90
+ test "defined Warden after_authentication callback should not be called when sign_in is called" do
91
+ begin
92
+ Warden::Manager.after_authentication do |user, auth, opts|
93
+ flunk "callback was called while it should not"
94
+ end
95
+
96
+ user = create_user
97
+ user.confirm!
98
+ sign_in user
99
+ ensure
100
+ Warden::Manager._after_set_user.pop
101
+ end
102
+ end
103
+
104
+ test "defined Warden before_logout callback should not be called when sign_out is called" do
105
+ begin
106
+ Warden::Manager.before_logout do |user, auth, opts|
107
+ flunk "callback was called while it should not"
108
+ end
109
+ user = create_user
110
+ user.confirm!
111
+
112
+ sign_in user
113
+ sign_out user
114
+ ensure
115
+ Warden::Manager._before_logout.pop
116
+ end
117
+ end
118
+
119
+ test "before_failure call should work" do
120
+ begin
121
+ executed = false
122
+ Warden::Manager.before_failure do |env,opts|
123
+ executed = true
124
+ end
125
+
126
+ user = create_user
127
+ sign_in user
128
+
129
+ get :index
130
+ assert executed
131
+ ensure
132
+ Warden::Manager._before_failure.pop
133
+ end
134
+ end
135
+
136
+ test "allows to sign in with different users" do
137
+ first_user = create_user
138
+ first_user.confirm!
139
+
140
+ sign_in first_user
141
+ get :index
142
+ assert_match /User ##{first_user.id}/, @response.body
143
+ sign_out first_user
144
+
145
+ second_user = create_user
146
+ second_user.confirm!
147
+
148
+ sign_in second_user
149
+ get :index
150
+ assert_match /User ##{second_user.id}/, @response.body
151
+ end
152
+ end