loyal_devise 2.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +10 -0
- data/.travis.yml +15 -0
- data/CHANGELOG.rdoc +881 -0
- data/CONTRIBUTING.md +12 -0
- data/Gemfile +31 -0
- data/Gemfile.lock +154 -0
- data/MIT-LICENSE +20 -0
- data/README.md +388 -0
- data/Rakefile +34 -0
- data/app/controllers/devise/confirmations_controller.rb +44 -0
- data/app/controllers/devise/omniauth_callbacks_controller.rb +31 -0
- data/app/controllers/devise/passwords_controller.rb +57 -0
- data/app/controllers/devise/registrations_controller.rb +120 -0
- data/app/controllers/devise/sessions_controller.rb +51 -0
- data/app/controllers/devise/unlocks_controller.rb +45 -0
- data/app/controllers/devise_controller.rb +193 -0
- data/app/helpers/devise_helper.rb +26 -0
- data/app/mailers/devise/mailer.rb +16 -0
- data/app/views/devise/_links.erb +3 -0
- data/app/views/devise/confirmations/new.html.erb +12 -0
- data/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
- data/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
- data/app/views/devise/mailer/unlock_instructions.html.erb +7 -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 +25 -0
- data/app/views/devise/unlocks/new.html.erb +12 -0
- data/config/locales/en.yml +59 -0
- data/devise.gemspec +26 -0
- data/gemfiles/Gemfile.rails-3.1.x +35 -0
- data/gemfiles/Gemfile.rails-3.1.x.lock +167 -0
- data/lib/devise/controllers/helpers.rb +273 -0
- data/lib/devise/controllers/rememberable.rb +53 -0
- data/lib/devise/controllers/scoped_views.rb +18 -0
- data/lib/devise/controllers/url_helpers.rb +68 -0
- data/lib/devise/delegator.rb +17 -0
- data/lib/devise/failure_app.rb +188 -0
- data/lib/devise/hooks/activatable.rb +12 -0
- data/lib/devise/hooks/forgetable.rb +10 -0
- data/lib/devise/hooks/lockable.rb +8 -0
- data/lib/devise/hooks/rememberable.rb +7 -0
- data/lib/devise/hooks/timeoutable.rb +26 -0
- data/lib/devise/hooks/trackable.rb +10 -0
- data/lib/devise/mailers/helpers.rb +92 -0
- data/lib/devise/mapping.rb +173 -0
- data/lib/devise/models/authenticatable.rb +269 -0
- data/lib/devise/models/confirmable.rb +271 -0
- data/lib/devise/models/database_authenticatable.rb +127 -0
- data/lib/devise/models/lockable.rb +194 -0
- data/lib/devise/models/omniauthable.rb +28 -0
- data/lib/devise/models/recoverable.rb +141 -0
- data/lib/devise/models/registerable.rb +26 -0
- data/lib/devise/models/rememberable.rb +126 -0
- data/lib/devise/models/timeoutable.rb +50 -0
- data/lib/devise/models/token_authenticatable.rb +90 -0
- data/lib/devise/models/trackable.rb +36 -0
- data/lib/devise/models/validatable.rb +67 -0
- data/lib/devise/models.rb +129 -0
- data/lib/devise/modules.rb +30 -0
- data/lib/devise/omniauth/config.rb +46 -0
- data/lib/devise/omniauth/url_helpers.rb +19 -0
- data/lib/devise/omniauth.rb +29 -0
- data/lib/devise/orm/active_record.rb +4 -0
- data/lib/devise/orm/mongoid.rb +4 -0
- data/lib/devise/param_filter.rb +42 -0
- data/lib/devise/rails/routes.rb +447 -0
- data/lib/devise/rails/warden_compat.rb +44 -0
- data/lib/devise/rails.rb +55 -0
- data/lib/devise/strategies/authenticatable.rb +177 -0
- data/lib/devise/strategies/base.rb +21 -0
- data/lib/devise/strategies/database_authenticatable.rb +21 -0
- data/lib/devise/strategies/rememberable.rb +56 -0
- data/lib/devise/strategies/token_authenticatable.rb +57 -0
- data/lib/devise/test_helpers.rb +132 -0
- data/lib/devise/time_inflector.rb +15 -0
- data/lib/devise/version.rb +4 -0
- data/lib/devise.rb +445 -0
- data/lib/generators/active_record/devise_generator.rb +80 -0
- data/lib/generators/active_record/templates/migration.rb +20 -0
- data/lib/generators/active_record/templates/migration_existing.rb +27 -0
- data/lib/generators/devise/devise_generator.rb +25 -0
- data/lib/generators/devise/install_generator.rb +25 -0
- data/lib/generators/devise/orm_helpers.rb +33 -0
- data/lib/generators/devise/views_generator.rb +117 -0
- data/lib/generators/mongoid/devise_generator.rb +58 -0
- data/lib/generators/templates/README +35 -0
- data/lib/generators/templates/devise.rb +241 -0
- data/lib/generators/templates/markerb/confirmation_instructions.markerb +5 -0
- data/lib/generators/templates/markerb/reset_password_instructions.markerb +8 -0
- data/lib/generators/templates/markerb/unlock_instructions.markerb +7 -0
- data/lib/generators/templates/simple_form_for/confirmations/new.html.erb +15 -0
- data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +19 -0
- data/lib/generators/templates/simple_form_for/passwords/new.html.erb +15 -0
- data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +22 -0
- data/lib/generators/templates/simple_form_for/registrations/new.html.erb +17 -0
- data/lib/generators/templates/simple_form_for/sessions/new.html.erb +15 -0
- data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +15 -0
- data/test/controllers/custom_strategy_test.rb +63 -0
- data/test/controllers/helpers_test.rb +254 -0
- data/test/controllers/internal_helpers_test.rb +111 -0
- data/test/controllers/sessions_controller_test.rb +58 -0
- data/test/controllers/url_helpers_test.rb +60 -0
- data/test/delegator_test.rb +20 -0
- data/test/devise_test.rb +73 -0
- data/test/failure_app_test.rb +222 -0
- data/test/generators/active_record_generator_test.rb +76 -0
- data/test/generators/devise_generator_test.rb +40 -0
- data/test/generators/install_generator_test.rb +14 -0
- data/test/generators/mongoid_generator_test.rb +24 -0
- data/test/generators/views_generator_test.rb +53 -0
- data/test/helpers/devise_helper_test.rb +52 -0
- data/test/indifferent_hash.rb +34 -0
- data/test/integration/authenticatable_test.rb +634 -0
- data/test/integration/confirmable_test.rb +299 -0
- data/test/integration/database_authenticatable_test.rb +83 -0
- data/test/integration/http_authenticatable_test.rb +98 -0
- data/test/integration/lockable_test.rb +243 -0
- data/test/integration/omniauthable_test.rb +134 -0
- data/test/integration/recoverable_test.rb +307 -0
- data/test/integration/registerable_test.rb +346 -0
- data/test/integration/rememberable_test.rb +159 -0
- data/test/integration/timeoutable_test.rb +141 -0
- data/test/integration/token_authenticatable_test.rb +162 -0
- data/test/integration/trackable_test.rb +93 -0
- data/test/mailers/confirmation_instructions_test.rb +103 -0
- data/test/mailers/reset_password_instructions_test.rb +84 -0
- data/test/mailers/unlock_instructions_test.rb +78 -0
- data/test/mapping_test.rb +128 -0
- data/test/models/authenticatable_test.rb +8 -0
- data/test/models/confirmable_test.rb +392 -0
- data/test/models/database_authenticatable_test.rb +190 -0
- data/test/models/lockable_test.rb +274 -0
- data/test/models/omniauthable_test.rb +8 -0
- data/test/models/recoverable_test.rb +206 -0
- data/test/models/registerable_test.rb +8 -0
- data/test/models/rememberable_test.rb +175 -0
- data/test/models/serializable_test.rb +49 -0
- data/test/models/timeoutable_test.rb +47 -0
- data/test/models/token_authenticatable_test.rb +56 -0
- data/test/models/trackable_test.rb +14 -0
- data/test/models/validatable_test.rb +117 -0
- data/test/models_test.rb +180 -0
- data/test/omniauth/config_test.rb +58 -0
- data/test/omniauth/url_helpers_test.rb +52 -0
- data/test/orm/active_record.rb +10 -0
- data/test/orm/mongoid.rb +15 -0
- data/test/rails_app/Rakefile +10 -0
- data/test/rails_app/app/active_record/admin.rb +7 -0
- data/test/rails_app/app/active_record/shim.rb +3 -0
- data/test/rails_app/app/active_record/user.rb +7 -0
- data/test/rails_app/app/controllers/admins/sessions_controller.rb +7 -0
- data/test/rails_app/app/controllers/admins_controller.rb +12 -0
- data/test/rails_app/app/controllers/application_controller.rb +9 -0
- data/test/rails_app/app/controllers/home_controller.rb +26 -0
- data/test/rails_app/app/controllers/publisher/registrations_controller.rb +3 -0
- data/test/rails_app/app/controllers/publisher/sessions_controller.rb +3 -0
- data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +15 -0
- data/test/rails_app/app/controllers/users_controller.rb +24 -0
- data/test/rails_app/app/helpers/application_helper.rb +4 -0
- data/test/rails_app/app/mailers/users/mailer.rb +9 -0
- data/test/rails_app/app/mongoid/admin.rb +28 -0
- data/test/rails_app/app/mongoid/shim.rb +25 -0
- data/test/rails_app/app/mongoid/user.rb +43 -0
- data/test/rails_app/app/views/admins/index.html.erb +1 -0
- data/test/rails_app/app/views/admins/sessions/new.html.erb +2 -0
- data/test/rails_app/app/views/home/admin_dashboard.html.erb +1 -0
- data/test/rails_app/app/views/home/index.html.erb +1 -0
- data/test/rails_app/app/views/home/join.html.erb +1 -0
- data/test/rails_app/app/views/home/private.html.erb +1 -0
- data/test/rails_app/app/views/home/user_dashboard.html.erb +1 -0
- data/test/rails_app/app/views/layouts/application.html.erb +24 -0
- data/test/rails_app/app/views/users/index.html.erb +1 -0
- data/test/rails_app/app/views/users/mailer/confirmation_instructions.erb +1 -0
- data/test/rails_app/app/views/users/sessions/new.html.erb +1 -0
- data/test/rails_app/config/application.rb +42 -0
- data/test/rails_app/config/boot.rb +9 -0
- data/test/rails_app/config/database.yml +18 -0
- data/test/rails_app/config/environment.rb +6 -0
- data/test/rails_app/config/environments/development.rb +19 -0
- data/test/rails_app/config/environments/production.rb +34 -0
- data/test/rails_app/config/environments/test.rb +34 -0
- data/test/rails_app/config/initializers/backtrace_silencers.rb +8 -0
- data/test/rails_app/config/initializers/devise.rb +179 -0
- data/test/rails_app/config/initializers/inflections.rb +3 -0
- data/test/rails_app/config/initializers/secret_token.rb +3 -0
- data/test/rails_app/config/routes.rb +101 -0
- data/test/rails_app/config.ru +4 -0
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +75 -0
- data/test/rails_app/db/schema.rb +53 -0
- data/test/rails_app/lib/shared_admin.rb +15 -0
- data/test/rails_app/lib/shared_user.rb +27 -0
- data/test/rails_app/public/404.html +26 -0
- data/test/rails_app/public/422.html +26 -0
- data/test/rails_app/public/500.html +26 -0
- data/test/rails_app/public/favicon.ico +0 -0
- data/test/rails_app/script/rails +10 -0
- data/test/routes_test.rb +249 -0
- data/test/support/assertions.rb +41 -0
- data/test/support/helpers.rb +92 -0
- data/test/support/integration.rb +93 -0
- data/test/support/locale/en.yml +4 -0
- data/test/support/webrat/integrations/rails.rb +25 -0
- data/test/test_helper.rb +28 -0
- data/test/test_helpers_test.rb +152 -0
- 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,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
|
data/test/test_helper.rb
ADDED
@@ -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
|