devise 1.2.rc → 1.2.rc2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of devise might be problematic. Click here for more details.

Files changed (101) hide show
  1. data/.gitignore +10 -0
  2. data/.travis.yml +1 -0
  3. data/CHANGELOG.rdoc +45 -1
  4. data/Gemfile +29 -0
  5. data/Gemfile.lock +158 -0
  6. data/MIT-LICENSE +1 -1
  7. data/README.rdoc +25 -8
  8. data/Rakefile +34 -0
  9. data/TODO +4 -0
  10. data/app/controllers/devise/omniauth_callbacks_controller.rb +3 -3
  11. data/app/controllers/devise/registrations_controller.rb +4 -4
  12. data/app/controllers/devise/sessions_controller.rb +3 -2
  13. data/app/helpers/devise_helper.rb +6 -0
  14. data/config/locales/en.yml +2 -0
  15. data/devise.gemspec +25 -0
  16. data/lib/devise.rb +31 -5
  17. data/lib/devise/controllers/helpers.rb +30 -29
  18. data/lib/devise/controllers/internal_helpers.rb +6 -1
  19. data/lib/devise/controllers/rememberable.rb +52 -0
  20. data/lib/devise/encryptors/authlogic_sha512.rb +1 -1
  21. data/lib/devise/failure_app.rb +20 -4
  22. data/lib/devise/hooks/forgetable.rb +1 -4
  23. data/lib/devise/hooks/rememberable.rb +5 -44
  24. data/lib/devise/hooks/timeoutable.rb +1 -1
  25. data/lib/devise/models.rb +4 -2
  26. data/lib/devise/models/authenticatable.rb +13 -3
  27. data/lib/devise/models/confirmable.rb +3 -3
  28. data/lib/devise/models/database_authenticatable.rb +5 -3
  29. data/lib/devise/models/encryptable.rb +9 -2
  30. data/lib/devise/models/lockable.rb +18 -13
  31. data/lib/devise/models/recoverable.rb +9 -1
  32. data/lib/devise/models/registerable.rb +1 -1
  33. data/lib/devise/models/rememberable.rb +2 -5
  34. data/lib/devise/models/token_authenticatable.rb +4 -4
  35. data/lib/devise/omniauth.rb +3 -18
  36. data/lib/devise/omniauth/test_helpers.rb +14 -40
  37. data/lib/devise/omniauth/url_helpers.rb +6 -2
  38. data/lib/devise/rails.rb +3 -2
  39. data/lib/devise/rails/warden_compat.rb +5 -0
  40. data/lib/devise/schema.rb +3 -2
  41. data/lib/devise/strategies/authenticatable.rb +15 -1
  42. data/lib/devise/strategies/database_authenticatable.rb +1 -1
  43. data/lib/devise/strategies/rememberable.rb +6 -5
  44. data/lib/devise/strategies/token_authenticatable.rb +1 -1
  45. data/lib/devise/test_helpers.rb +3 -3
  46. data/lib/devise/version.rb +1 -1
  47. data/lib/generators/active_record/devise_generator.rb +2 -2
  48. data/lib/generators/active_record/templates/migration.rb +1 -0
  49. data/lib/generators/devise/devise_generator.rb +3 -1
  50. data/lib/generators/devise/orm_helpers.rb +1 -2
  51. data/lib/generators/devise/views_generator.rb +8 -45
  52. data/lib/generators/mongoid/devise_generator.rb +2 -2
  53. data/lib/generators/templates/devise.rb +19 -7
  54. data/test/controllers/helpers_test.rb +35 -5
  55. data/test/devise_test.rb +10 -0
  56. data/test/failure_app_test.rb +32 -3
  57. data/test/generators/active_record_generator_test.rb +24 -0
  58. data/test/generators/devise_generator_test.rb +33 -0
  59. data/test/generators/install_generator_test.rb +3 -4
  60. data/test/generators/mongoid_generator_test.rb +22 -0
  61. data/test/generators/views_generator_test.rb +13 -15
  62. data/test/indifferent_hash.rb +33 -0
  63. data/test/integration/authenticatable_test.rb +7 -0
  64. data/test/integration/omniauthable_test.rb +67 -32
  65. data/test/integration/registerable_test.rb +30 -0
  66. data/test/integration/rememberable_test.rb +16 -6
  67. data/test/integration/token_authenticatable_test.rb +43 -5
  68. data/test/models/confirmable_test.rb +20 -3
  69. data/test/models/encryptable_test.rb +1 -1
  70. data/test/models/lockable_test.rb +36 -15
  71. data/test/models/recoverable_test.rb +20 -11
  72. data/test/models/token_authenticatable_test.rb +19 -1
  73. data/test/models_test.rb +7 -0
  74. data/test/omniauth/test_helpers_test.rb +25 -0
  75. data/test/omniauth/url_helpers_test.rb +7 -0
  76. data/test/rails_app/Rakefile +10 -0
  77. data/test/rails_app/app/controllers/application_controller.rb +0 -1
  78. data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +7 -0
  79. data/test/rails_app/app/views/admins/index.html.erb +1 -0
  80. data/test/rails_app/app/views/admins/sessions/new.html.erb +2 -0
  81. data/test/rails_app/app/views/home/index.html.erb +1 -0
  82. data/test/rails_app/app/views/home/private.html.erb +1 -0
  83. data/test/rails_app/app/views/layouts/application.html.erb +24 -0
  84. data/test/rails_app/app/views/users/index.html.erb +1 -0
  85. data/test/rails_app/app/views/users/mailer/confirmation_instructions.erb +1 -0
  86. data/test/rails_app/app/views/users/sessions/new.html.erb +1 -0
  87. data/test/rails_app/config.ru +4 -0
  88. data/test/rails_app/config/application.rb +5 -0
  89. data/test/rails_app/config/database.yml +18 -0
  90. data/test/rails_app/config/initializers/devise.rb +18 -2
  91. data/test/rails_app/public/404.html +26 -0
  92. data/test/rails_app/public/422.html +26 -0
  93. data/test/rails_app/public/500.html +26 -0
  94. data/test/rails_app/public/favicon.ico +0 -0
  95. data/test/rails_app/script/rails +10 -0
  96. data/test/schema_test.rb +33 -0
  97. data/test/support/locale/en.yml +4 -0
  98. data/test/test_helper.rb +5 -2
  99. data/test/test_helpers_test.rb +33 -0
  100. metadata +71 -20
  101. data/test/generators/generators_test_helper.rb +0 -4
@@ -7,7 +7,11 @@ module Devise
7
7
  class_eval <<-URL_HELPERS, __FILE__, __LINE__ + 1
8
8
  def #{mapping.name}_omniauth_authorize_path(provider, params = {})
9
9
  if Devise.omniauth_configs[provider.to_sym]
10
- "/#{mapping.path}/auth/\#{provider}\#{'?'+params.to_param if params.present?}"
10
+ script_name = request.env["SCRIPT_NAME"]
11
+
12
+ path = "\#{script_name}/#{mapping.path}/auth/\#{provider}\".squeeze("/")
13
+ path << '?' + params.to_param if params.present?
14
+ path
11
15
  else
12
16
  raise ArgumentError, "Could not find omniauth provider \#{provider.inspect}"
13
17
  end
@@ -26,4 +30,4 @@ module Devise
26
30
  end
27
31
  end
28
32
  end
29
- end
33
+ end
@@ -41,8 +41,9 @@ module Devise
41
41
  # Nothing to say
42
42
  else
43
43
  puts "[DEVISE] You are using #{Devise.encryptor} as encryptor. From version 1.2, " <<
44
- "you need to explicitly add `devise :encryptable, :encryptor => #{Devise.encryptor.to_sym}` " <<
45
- "to your models and comment the current value in the config/initializers/devise.rb"
44
+ "you need to explicitly add `devise :encryptable, :encryptor => :#{Devise.encryptor}` " <<
45
+ "to your models and comment the current value in the config/initializers/devise.rb. " <<
46
+ "You must also add t.encryptable to your existing migrations."
46
47
  end
47
48
  end
48
49
  end
@@ -47,6 +47,10 @@ unless Devise.rack_session?
47
47
  alias_method :regular_writer, :[]= unless method_defined?(:regular_writer)
48
48
  alias_method :regular_update, :update unless method_defined?(:regular_update)
49
49
 
50
+ def [](key)
51
+ super(convert_key(key))
52
+ end
53
+
50
54
  def []=(key, value)
51
55
  regular_writer(convert_key(key), value)
52
56
  end
@@ -91,6 +95,7 @@ unless Devise.rack_session?
91
95
  def symbolize_keys; to_hash.symbolize_keys end
92
96
 
93
97
  def to_options!; self end
98
+ def to_hash; Hash.new.update(self) end
94
99
 
95
100
  protected
96
101
 
@@ -3,7 +3,7 @@ module Devise
3
3
  # and overwrite the apply_schema method.
4
4
  module Schema
5
5
 
6
- # Creates email, encrypted_password and password_salt.
6
+ # Creates email when enabled (on by default), encrypted_password and password_salt.
7
7
  #
8
8
  # == Options
9
9
  # * :null - When true, allow columns to be null.
@@ -15,8 +15,9 @@ module Devise
15
15
  def database_authenticatable(options={})
16
16
  null = options[:null] || false
17
17
  default = options.key?(:default) ? options[:default] : ("" if null == false)
18
+ include_email = !self.respond_to?(:authentication_keys) || self.authentication_keys.include?(:email)
18
19
 
19
- apply_devise_schema :email, String, :null => null, :default => default
20
+ apply_devise_schema :email, String, :null => null, :default => default if include_email
20
21
  apply_devise_schema :encrypted_password, String, :null => null, :default => default, :limit => 128
21
22
  end
22
23
 
@@ -19,13 +19,27 @@ module Devise
19
19
  result = resource && resource.valid_for_authentication?(&block)
20
20
 
21
21
  case result
22
- when Symbol, String
22
+ when String, Symbol
23
23
  fail!(result)
24
+ false
25
+ when TrueClass
26
+ decorate(resource)
27
+ true
24
28
  else
25
29
  result
26
30
  end
27
31
  end
28
32
 
33
+ # Get values from params and set in the resource.
34
+ def decorate(resource)
35
+ resource.remember_me = remember_me? if resource.respond_to?(:remember_me=)
36
+ end
37
+
38
+ # Should this resource be marked to be remembered?
39
+ def remember_me?
40
+ valid_params? && Devise::TRUE_VALUES.include?(params_auth_hash[:remember_me])
41
+ end
42
+
29
43
  # Check if this is strategy is valid for http authentication by:
30
44
  #
31
45
  # * Validating if the model allows params authentication;
@@ -10,7 +10,7 @@ module Devise
10
10
  if validate(resource){ resource.valid_password?(password) }
11
11
  resource.after_database_authentication
12
12
  success!(resource)
13
- else
13
+ elsif !halted?
14
14
  fail(:invalid)
15
15
  end
16
16
  end
@@ -20,7 +20,7 @@ module Devise
20
20
 
21
21
  if validate(resource)
22
22
  success!(resource)
23
- else
23
+ elsif !halted?
24
24
  cookies.delete(remember_key)
25
25
  pass
26
26
  end
@@ -28,6 +28,11 @@ module Devise
28
28
 
29
29
  private
30
30
 
31
+ def decorate(resource)
32
+ super
33
+ resource.extend_remember_period = mapping.to.extend_remember_period if resource.respond_to?(:extend_remember_period=)
34
+ end
35
+
31
36
  def remember_me?
32
37
  true
33
38
  end
@@ -36,10 +41,6 @@ module Devise
36
41
  "remember_#{scope}_token"
37
42
  end
38
43
 
39
- def extend_remember_period?
40
- mapping.to.extend_remember_period
41
- end
42
-
43
44
  # Accessor for remember cookie
44
45
  def remember_cookie
45
46
  @remember_cookie ||= cookies.signed[remember_key]
@@ -20,7 +20,7 @@ module Devise
20
20
  if validate(resource)
21
21
  resource.after_token_authentication
22
22
  success!(resource)
23
- else
23
+ elsif !halted?
24
24
  fail(:invalid_token)
25
25
  end
26
26
  end
@@ -1,7 +1,7 @@
1
1
  module Devise
2
2
  # Devise::TestHelpers provides a facility to test controllers in isolation
3
3
  # when using ActionController::TestCase allowing you to quickly sign_in or
4
- # sign_out an user. Do not use Devise::TestHelpers in integration tests.
4
+ # sign_out a user. Do not use Devise::TestHelpers in integration tests.
5
5
  #
6
6
  # Notice you should not test Warden specific behavior (like Warden callbacks)
7
7
  # using Devise::TestHelpers since it is a stub of the actual behavior. Such
@@ -44,9 +44,9 @@ module Devise
44
44
  env = @controller.request.env
45
45
  env["PATH_INFO"] = "/#{result[:action]}"
46
46
  env["warden.options"] = result
47
- Warden::Manager._before_failure.each{ |hook| hook.call(env, result) }
47
+ Warden::Manager._run_callbacks(:before_failure, env, result)
48
48
 
49
- status, headers, body = Devise::FailureApp.call(env).to_a
49
+ status, headers, body = Devise.warden_config[:failure_app].call(env).to_a
50
50
  @controller.send :render, :status => status, :text => body,
51
51
  :content_type => headers["Content-Type"], :location => headers["Location"]
52
52
 
@@ -1,3 +1,3 @@
1
1
  module Devise
2
- VERSION = "1.2.rc".freeze
2
+ VERSION = "1.2.rc2".freeze
3
3
  end
@@ -10,7 +10,7 @@ module ActiveRecord
10
10
  source_root File.expand_path("../templates", __FILE__)
11
11
 
12
12
  def generate_model
13
- invoke "active_record:model", [name], :migration => false unless model_exists?
13
+ invoke "active_record:model", [name], :migration => false unless model_exists? && behavior == :invoke
14
14
  end
15
15
 
16
16
  def copy_devise_migration
@@ -18,7 +18,7 @@ module ActiveRecord
18
18
  end
19
19
 
20
20
  def inject_devise_content
21
- inject_into_class model_path, class_name, model_contents + <<-CONTENT
21
+ inject_into_class(model_path, class_name, model_contents + <<CONTENT) if model_exists?
22
22
  # Setup accessible (or protected) attributes for your model
23
23
  attr_accessible :email, :password, :password_confirmation, :remember_me
24
24
  CONTENT
@@ -22,6 +22,7 @@ class DeviseCreate<%= table_name.camelize %> < ActiveRecord::Migration
22
22
  add_index :<%= table_name %>, :reset_password_token, :unique => true
23
23
  # add_index :<%= table_name %>, :confirmation_token, :unique => true
24
24
  # add_index :<%= table_name %>, :unlock_token, :unique => true
25
+ # add_index :<%= table_name %>, :authentication_token, :unique => true
25
26
  end
26
27
 
27
28
  def self.down
@@ -10,7 +10,9 @@ module Devise
10
10
  hook_for :orm
11
11
 
12
12
  def add_devise_routes
13
- route "devise_for :#{table_name}"
13
+ devise_route = "devise_for :#{plural_name}"
14
+ devise_route += %Q(, :class_name => "#{class_name}") if class_name.include?("::")
15
+ route devise_route
14
16
  end
15
17
  end
16
18
  end
@@ -12,8 +12,7 @@ CONTENT
12
12
  end
13
13
 
14
14
  def model_exists?
15
- return @model_exists if instance_variable_defined?(:@model_exists)
16
- @model_exists = File.exists?(File.join(destination_root, model_path))
15
+ File.exists?(File.join(destination_root, model_path))
17
16
  end
18
17
 
19
18
  def model_path
@@ -1,3 +1,5 @@
1
+ require 'tmpdir'
2
+
1
3
  module Devise
2
4
  module Generators
3
5
  class ViewsGenerator < Rails::Generators::Base
@@ -8,56 +10,17 @@ module Devise
8
10
  :desc => "The scope to copy views to"
9
11
 
10
12
  class_option :template_engine, :type => :string, :aliases => "-t",
11
- :desc => "Template engine for the views. Available options are 'erb' and 'haml'."
13
+ :desc => "Template engine for the views. Available options are 'erb', 'haml' and 'slim'."
12
14
 
13
15
  def copy_views
14
- case options[:template_engine].to_s
15
- when "haml"
16
- verify_haml_existence
17
- verify_haml_version
18
- create_and_copy_haml_views
16
+ template = options[:template_engine].to_s
17
+ case template
18
+ when "haml", "slim"
19
+ warn "#{template} templates have been removed from Devise gem"
19
20
  else
20
21
  directory "devise", "app/views/#{scope || :devise}"
21
22
  end
22
23
  end
23
-
24
- protected
25
-
26
- def verify_haml_existence
27
- begin
28
- require 'haml'
29
- rescue LoadError
30
- say "HAML is not installed, or it is not specified in your Gemfile."
31
- exit
32
- end
33
- end
34
-
35
- def verify_haml_version
36
- unless Haml.version[:major] == 2 and Haml.version[:minor] >= 3 or Haml.version[:major] >= 3
37
- say "To generate HAML templates, you need to install HAML 2.3 or above."
38
- exit
39
- end
40
- end
41
-
42
- def create_and_copy_haml_views
43
- require 'tmpdir'
44
- html_root = "#{self.class.source_root}/devise"
45
-
46
- Dir.mktmpdir("devise-haml.") do |haml_root|
47
- Dir["#{html_root}/**/*"].each do |path|
48
- relative_path = path.sub(html_root, "")
49
- source_path = (haml_root + relative_path).sub(/erb$/, "haml")
50
-
51
- if File.directory?(path)
52
- FileUtils.mkdir_p(source_path)
53
- else
54
- `html2haml -r #{path} #{source_path}`
55
- end
56
- end
57
-
58
- directory haml_root, "app/views/#{scope || :devise}"
59
- end
60
- end
61
24
  end
62
25
  end
63
- end
26
+ end
@@ -6,11 +6,11 @@ module Mongoid
6
6
  include Devise::Generators::OrmHelpers
7
7
 
8
8
  def generate_model
9
- invoke "mongoid:model", [name] unless model_exists?
9
+ invoke "mongoid:model", [name] unless model_exists? && behavior == :invoke
10
10
  end
11
11
 
12
12
  def inject_devise_content
13
- inject_into_file model_path, model_contents, :after => "include Mongoid::Document\n"
13
+ inject_into_file model_path, model_contents, :after => "include Mongoid::Document\n" if model_exists?
14
14
  end
15
15
  end
16
16
  end
@@ -34,7 +34,7 @@ Devise.setup do |config|
34
34
  # Configure which authentication keys should be case-insensitive.
35
35
  # These keys will be downcased upon creating or modifying a user and when used
36
36
  # to authenticate or find a user. Default is :email.
37
- # config.case_insensitive_keys = [ :email ]
37
+ config.case_insensitive_keys = [ :email ]
38
38
 
39
39
  # Tell if authentication through request.params is enabled. True by default.
40
40
  # config.params_authenticatable = true
@@ -53,6 +53,9 @@ Devise.setup do |config|
53
53
  # using other encryptors, it sets how many times you want the password re-encrypted.
54
54
  config.stretches = 10
55
55
 
56
+ # Setup a pepper to generate the encrypted password.
57
+ # config.pepper = <%= ActiveSupport::SecureRandom.hex(64).inspect %>
58
+
56
59
  # ==> Configuration for :confirmable
57
60
  # The time you want to give your user to confirm his account. During this time
58
61
  # he will be able to access your application without confirming. Default is 0.days
@@ -62,6 +65,9 @@ Devise.setup do |config|
62
65
  # (ie 2 days).
63
66
  # config.confirm_within = 2.days
64
67
 
68
+ # Defines which key will be used when confirming an account
69
+ # config.confirmation_keys = [ :email ]
70
+
65
71
  # ==> Configuration for :rememberable
66
72
  # The time the user will be remembered without asking for credentials again.
67
73
  # config.remember_for = 2.weeks
@@ -81,7 +87,7 @@ Devise.setup do |config|
81
87
  # config.password_length = 6..20
82
88
 
83
89
  # Regex to use to validate the email address
84
- # config.email_regexp = /^([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})$/i
90
+ # config.email_regexp = /\A([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})\z/i
85
91
 
86
92
  # ==> Configuration for :timeoutable
87
93
  # The time you want to timeout the user session without activity. After this
@@ -94,6 +100,9 @@ Devise.setup do |config|
94
100
  # :none = No lock strategy. You should handle locking by yourself.
95
101
  # config.lock_strategy = :failed_attempts
96
102
 
103
+ # Defines which key will be used when locking and unlocking an account
104
+ # config.unlock_keys = [ :email ]
105
+
97
106
  # Defines which strategy will be used to unlock an account.
98
107
  # :email = Sends an unlock link to the user email
99
108
  # :time = Re-enables login after a certain amount of time (see :unlock_in below)
@@ -108,6 +117,11 @@ Devise.setup do |config|
108
117
  # Time interval to unlock the account if :time is enabled as unlock_strategy.
109
118
  # config.unlock_in = 1.hour
110
119
 
120
+ # ==> Configuration for :recoverable
121
+ #
122
+ # Defines which key will be used when recovering the password for an account
123
+ # config.reset_password_keys = [ :email ]
124
+
111
125
  # ==> Configuration for :encryptable
112
126
  # Allow you to use another encryption algorithm besides bcrypt (default). You can use
113
127
  # :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1,
@@ -116,9 +130,6 @@ Devise.setup do |config|
116
130
  # REST_AUTH_SITE_KEY to pepper)
117
131
  # config.encryptor = :sha512
118
132
 
119
- # Setup a pepper to generate the encrypted password.
120
- # config.pepper = <%= ActiveSupport::SecureRandom.hex(64).inspect %>
121
-
122
133
  # ==> Configuration for :token_authenticatable
123
134
  # Defines name of the authentication token params key
124
135
  # config.token_authentication_key = :auth_token
@@ -150,8 +161,9 @@ Devise.setup do |config|
150
161
  # If you have any extra navigational formats, like :iphone or :mobile, you
151
162
  # should add them to the navigational formats lists.
152
163
  #
153
- # The :"*/*" format below is required to match Internet Explorer requests.
154
- # config.navigational_formats = [:"*/*", :html]
164
+ # The :"*/*" and "*/*" formats below is required to match Internet
165
+ # Explorer requests.
166
+ # config.navigational_formats = [:"*/*", "*/*", :html]
155
167
 
156
168
  # The default HTTP method used to sign out a resource. Default is :get.
157
169
  # config.sign_out_via = :get
@@ -1,7 +1,7 @@
1
1
  require 'test_helper'
2
2
  require 'ostruct'
3
3
 
4
- class ControllerAuthenticableTest < ActionController::TestCase
4
+ class ControllerAuthenticatableTest < ActionController::TestCase
5
5
  tests ApplicationController
6
6
 
7
7
  def setup
@@ -13,16 +13,16 @@ class ControllerAuthenticableTest < ActionController::TestCase
13
13
  assert_equal @mock_warden, @controller.warden
14
14
  end
15
15
 
16
- test 'proxy signed_in? to authenticated' do
16
+ test 'proxy signed_in?(scope) to authenticate?' do
17
17
  @mock_warden.expects(:authenticate?).with(:scope => :my_scope)
18
18
  @controller.signed_in?(:my_scope)
19
19
  end
20
20
 
21
- test 'proxy anybody_signed_in? to signed_in?' do
21
+ test 'proxy signed_in?(nil) to authenticate?' do
22
22
  Devise.mappings.keys.each do |scope| # :user, :admin, :manager
23
- @controller.expects(:signed_in?).with(scope)
23
+ @mock_warden.expects(:authenticate?).with(:scope => scope)
24
24
  end
25
- @controller.anybody_signed_in?
25
+ @controller.signed_in?
26
26
  end
27
27
 
28
28
  test 'proxy current_user to authenticate with user scope' do
@@ -90,16 +90,32 @@ class ControllerAuthenticableTest < ActionController::TestCase
90
90
 
91
91
  test 'sign in proxy to set_user on warden' do
92
92
  user = User.new
93
+ @mock_warden.expects(:user).returns(nil)
93
94
  @mock_warden.expects(:set_user).with(user, :scope => :user).returns(true)
94
95
  @controller.sign_in(:user, user)
95
96
  end
96
97
 
97
98
  test 'sign in accepts a resource as argument' do
98
99
  user = User.new
100
+ @mock_warden.expects(:user).returns(nil)
99
101
  @mock_warden.expects(:set_user).with(user, :scope => :user).returns(true)
100
102
  @controller.sign_in(user)
101
103
  end
102
104
 
105
+ test 'does not sign in again if the user is already in' do
106
+ user = User.new
107
+ @mock_warden.expects(:user).returns(user)
108
+ @mock_warden.expects(:set_user).never
109
+ @controller.sign_in(user)
110
+ end
111
+
112
+ test 'sign in again when the user is already in only if force is given' do
113
+ user = User.new
114
+ @mock_warden.expects(:user).returns(user)
115
+ @mock_warden.expects(:set_user).with(user, :scope => :user).returns(true)
116
+ @controller.sign_in(user, :force => true)
117
+ end
118
+
103
119
  test 'sign in accepts bypass as option' do
104
120
  user = User.new
105
121
  @mock_warden.expects(:session_serializer).returns(serializer = mock())
@@ -120,11 +136,13 @@ class ControllerAuthenticableTest < ActionController::TestCase
120
136
  end
121
137
 
122
138
  test 'sign out without args proxy to sign out all scopes' do
139
+ @mock_warden.expects(:user).times(Devise.mappings.size)
123
140
  @mock_warden.expects(:logout).with().returns(true)
124
141
  @controller.sign_out
125
142
  end
126
143
 
127
144
  test 'sign out everybody proxy to logout on warden' do
145
+ @mock_warden.expects(:user).times(Devise.mappings.size)
128
146
  @mock_warden.expects(:logout).with().returns(true)
129
147
  @controller.sign_out_all_scopes
130
148
  end
@@ -185,6 +203,17 @@ class ControllerAuthenticableTest < ActionController::TestCase
185
203
  @controller.sign_in_and_redirect(admin)
186
204
  end
187
205
 
206
+ test 'redirect_location returns the stored location if set' do
207
+ user = User.new
208
+ @controller.session[:"user_return_to"] = "/foo.bar"
209
+ assert_equal '/foo.bar', @controller.redirect_location('user', user)
210
+ end
211
+
212
+ test 'redirect_location returns the after sign in path by default' do
213
+ user = User.new
214
+ assert_equal @controller.after_sign_in_path_for(:user), @controller.redirect_location('user', user)
215
+ end
216
+
188
217
  test 'sign out and redirect uses the configured after sign out path when signing out only the current scope' do
189
218
  swap Devise, :sign_out_all_scopes => false do
190
219
  @mock_warden.expects(:user).with(:admin).returns(true)
@@ -197,6 +226,7 @@ class ControllerAuthenticableTest < ActionController::TestCase
197
226
 
198
227
  test 'sign out and redirect uses the configured after sign out path when signing out all scopes' do
199
228
  swap Devise, :sign_out_all_scopes => true do
229
+ @mock_warden.expects(:user).times(Devise.mappings.size)
200
230
  @mock_warden.expects(:logout).with().returns(true)
201
231
  @controller.expects(:redirect_to).with(admin_root_path)
202
232
  @controller.instance_eval "def after_sign_out_path_for(resource); admin_root_path; end"