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
@@ -62,4 +62,14 @@ class DeviseTest < ActiveSupport::TestCase
62
62
  assert_nothing_raised(Exception) { Devise.add_module(:authenticatable_again, :model => 'devise/model/authenticatable') }
63
63
  assert defined?(Devise::Models::AuthenticatableAgain)
64
64
  end
65
+
66
+ test 'should complain when comparing empty or different sized passes' do
67
+ [nil, ""].each do |empty|
68
+ assert_not Devise.secure_compare(empty, "something")
69
+ assert_not Devise.secure_compare("something", empty)
70
+ assert_not Devise.secure_compare(empty, empty)
71
+ end
72
+ assert_not Devise.secure_compare("size_1", "size_four")
73
+ end
74
+
65
75
  end
@@ -13,7 +13,7 @@ class FailureTest < ActiveSupport::TestCase
13
13
  'REQUEST_METHOD' => 'GET',
14
14
  'warden.options' => { :scope => :user },
15
15
  'rack.session' => {},
16
- 'action_dispatch.request.formats' => Array(env_params.delete('formats') || :html),
16
+ 'action_dispatch.request.formats' => Array(env_params.delete('formats') || Mime::HTML),
17
17
  'rack.input' => "",
18
18
  'warden' => OpenStruct.new(:message => nil)
19
19
  }.merge!(env_params)
@@ -69,6 +69,13 @@ class FailureTest < ActiveSupport::TestCase
69
69
  assert_equal 302, @response.first
70
70
  end
71
71
  end
72
+
73
+ test 'redirects the correct format if it is a non-html format request' do
74
+ swap Devise, :navigational_formats => [:js] do
75
+ call_failure('formats' => :js)
76
+ assert_equal 'http://test.host/users/sign_in.js', @response.second["Location"]
77
+ end
78
+ end
72
79
  end
73
80
 
74
81
  context 'For HTTP request' do
@@ -120,7 +127,7 @@ class FailureTest < ActiveSupport::TestCase
120
127
  swap Devise, :http_authenticatable_on_xhr => false do
121
128
  call_failure('formats' => :json, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')
122
129
  assert_equal 302, @response.first
123
- assert_equal 'http://test.host/users/sign_in', @response.second["Location"]
130
+ assert_equal 'http://test.host/users/sign_in.json', @response.second["Location"]
124
131
  end
125
132
  end
126
133
  end
@@ -144,7 +151,7 @@ class FailureTest < ActiveSupport::TestCase
144
151
  end
145
152
 
146
153
  context 'With recall' do
147
- test 'calls the original controller' do
154
+ test 'calls the original controller if invalid email or password' do
148
155
  env = {
149
156
  "warden.options" => { :recall => "devise/sessions#new", :attempted_path => "/users/sign_in" },
150
157
  "devise.mapping" => Devise.mappings[:user],
@@ -154,5 +161,27 @@ class FailureTest < ActiveSupport::TestCase
154
161
  assert @response.third.body.include?('<h2>Sign in</h2>')
155
162
  assert @response.third.body.include?('Invalid email or password.')
156
163
  end
164
+
165
+ test 'calls the original controller if not confirmed email' do
166
+ env = {
167
+ "warden.options" => { :recall => "devise/sessions#new", :attempted_path => "/users/sign_in", :message => :unconfirmed },
168
+ "devise.mapping" => Devise.mappings[:user],
169
+ "warden" => stub_everything
170
+ }
171
+ call_failure(env)
172
+ assert @response.third.body.include?('<h2>Sign in</h2>')
173
+ assert @response.third.body.include?('You have to confirm your account before continuing.')
174
+ end
175
+
176
+ test 'calls the original controller if inactive account' do
177
+ env = {
178
+ "warden.options" => { :recall => "devise/sessions#new", :attempted_path => "/users/sign_in", :message => :inactive },
179
+ "devise.mapping" => Devise.mappings[:user],
180
+ "warden" => stub_everything
181
+ }
182
+ call_failure(env)
183
+ assert @response.third.body.include?('<h2>Sign in</h2>')
184
+ assert @response.third.body.include?('Your account was not activated yet.')
185
+ end
157
186
  end
158
187
  end
@@ -0,0 +1,24 @@
1
+ require "test_helper"
2
+
3
+ if DEVISE_ORM == :active_record
4
+ require "generators/active_record/devise_generator"
5
+
6
+ class ActiveRecordGeneratorTest < Rails::Generators::TestCase
7
+ tests ActiveRecord::Generators::DeviseGenerator
8
+ destination File.expand_path("../../tmp", __FILE__)
9
+ setup :prepare_destination
10
+
11
+ test "all files are properly created" do
12
+ run_generator %w(monster)
13
+ assert_file "app/models/monster.rb", /devise/, /attr_accessible (:[a-z_]+(, )?)+/
14
+ assert_migration "db/migrate/devise_create_monsters.rb"
15
+ end
16
+
17
+ test "all files are properly deleted" do
18
+ run_generator %w(monster)
19
+ run_generator %w(monster), :behavior => :revoke
20
+ assert_no_file "app/models/monster.rb"
21
+ assert_no_migration "db/migrate/devise_create_monsters.rb"
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,33 @@
1
+ require 'test_helper'
2
+
3
+ require "generators/devise/devise_generator"
4
+
5
+ class DeviseGeneratorTest < Rails::Generators::TestCase
6
+ tests Devise::Generators::DeviseGenerator
7
+ destination File.expand_path("../../tmp", __FILE__)
8
+
9
+ setup do
10
+ prepare_destination
11
+ copy_routes
12
+ end
13
+
14
+ test "route generation for simple model names" do
15
+ run_generator %w(monster name:string)
16
+ assert_file "config/routes.rb", /devise_for :monsters/
17
+ end
18
+
19
+ test "route generation for namespaced model names" do
20
+ run_generator %w(monster/goblin name:string)
21
+ match = /devise_for :goblins, :class_name => "Monster::Goblin"/
22
+ assert_file "config/routes.rb", match
23
+ end
24
+
25
+ def copy_routes
26
+ routes = File.expand_path("../../rails_app/config/routes.rb", __FILE__)
27
+ destination = File.join(destination_root, "config")
28
+
29
+ FileUtils.mkdir_p(destination)
30
+ FileUtils.cp routes, destination
31
+ end
32
+
33
+ end
@@ -1,14 +1,13 @@
1
- require File.join(File.dirname(__FILE__),"generators_test_helper.rb")
1
+ require "test_helper"
2
2
 
3
3
  class InstallGeneratorTest < Rails::Generators::TestCase
4
4
  tests Devise::Generators::InstallGenerator
5
- destination File.expand_path("../tmp", File.dirname(__FILE__))
5
+ destination File.expand_path("../../tmp", __FILE__)
6
6
  setup :prepare_destination
7
7
 
8
8
  test "Assert all files are properly created" do
9
9
  run_generator
10
- assert_file "config/initializers/devise.rb"
10
+ assert_file "config/initializers/devise.rb"
11
11
  assert_file "config/locales/devise.en.yml"
12
12
  end
13
-
14
13
  end
@@ -0,0 +1,22 @@
1
+ require "test_helper"
2
+
3
+ if DEVISE_ORM == :mongo_id
4
+ require "generators/mongo_id/devise_generator"
5
+
6
+ class MongoidGeneratorTest < Rails::Generators::TestCase
7
+ tests Mongoid::Generators::DeviseGenerator
8
+ destination File.expand_path("../../tmp", __FILE__)
9
+ setup :prepare_destination
10
+
11
+ test "all files are properly created" do
12
+ run_generator %w(monster)
13
+ assert_file "app/models/monster.rb", /devise/
14
+ end
15
+
16
+ test "all files are properly deleted" do
17
+ run_generator %w(monster)
18
+ run_generator %w(monster), :behavior => :revoke
19
+ assert_no_file "app/models/monster.rb"
20
+ end
21
+ end
22
+ end
@@ -1,8 +1,8 @@
1
- require File.join(File.dirname(__FILE__),"generators_test_helper.rb")
1
+ require "test_helper"
2
2
 
3
3
  class ViewsGeneratorTest < Rails::Generators::TestCase
4
4
  tests Devise::Generators::ViewsGenerator
5
- destination File.expand_path("../tmp", File.dirname(__FILE__))
5
+ destination File.expand_path("../../tmp", __FILE__)
6
6
  setup :prepare_destination
7
7
 
8
8
  test "Assert all views are properly created with no params" do
@@ -20,18 +20,16 @@ class ViewsGeneratorTest < Rails::Generators::TestCase
20
20
 
21
21
  def assert_files(scope = nil, template_engine = nil)
22
22
  scope = "devise" if scope.nil?
23
- assert_file "app/views/#{scope}/confirmations/new.html.erb"
24
- assert_file "app/views/#{scope}/mailer/confirmation_instructions.html.erb"
25
- assert_file "app/views/#{scope}/mailer/reset_password_instructions.html.erb"
26
- assert_file "app/views/#{scope}/mailer/unlock_instructions.html.erb"
27
- assert_file "app/views/#{scope}/passwords/edit.html.erb"
28
- assert_file "app/views/#{scope}/passwords/new.html.erb"
29
- assert_file "app/views/#{scope}/registrations/new.html.erb"
30
- assert_file "app/views/#{scope}/registrations/edit.html.erb"
31
- assert_file "app/views/#{scope}/sessions/new.html.erb"
32
- assert_file "app/views/#{scope}/shared/_links.erb"
33
- assert_file "app/views/#{scope}/unlocks/new.html.erb"
34
-
23
+ assert_file "app/views/#{scope}/confirmations/new.html.erb"
24
+ assert_file "app/views/#{scope}/mailer/confirmation_instructions.html.erb"
25
+ assert_file "app/views/#{scope}/mailer/reset_password_instructions.html.erb"
26
+ assert_file "app/views/#{scope}/mailer/unlock_instructions.html.erb"
27
+ assert_file "app/views/#{scope}/passwords/edit.html.erb"
28
+ assert_file "app/views/#{scope}/passwords/new.html.erb"
29
+ assert_file "app/views/#{scope}/registrations/new.html.erb"
30
+ assert_file "app/views/#{scope}/registrations/edit.html.erb"
31
+ assert_file "app/views/#{scope}/sessions/new.html.erb"
32
+ assert_file "app/views/#{scope}/shared/_links.erb"
33
+ assert_file "app/views/#{scope}/unlocks/new.html.erb"
35
34
  end
36
-
37
35
  end
@@ -0,0 +1,33 @@
1
+ require 'test_helper'
2
+
3
+ class IndifferentHashTest < ActiveSupport::TestCase
4
+ setup do
5
+ @hash = Devise::IndifferentHash.new
6
+ end
7
+
8
+ test "it overwrites getter and setter" do
9
+ @hash[:foo] = "bar"
10
+ assert_equal "bar", @hash["foo"]
11
+ assert_equal "bar", @hash[:foo]
12
+
13
+ @hash["foo"] = "baz"
14
+ assert_equal "baz", @hash["foo"]
15
+ assert_equal "baz", @hash[:foo]
16
+ end
17
+
18
+ test "it overwrites update" do
19
+ @hash.update :foo => "bar"
20
+ assert_equal "bar", @hash["foo"]
21
+ assert_equal "bar", @hash[:foo]
22
+
23
+ @hash.update "foo" => "baz"
24
+ assert_equal "baz", @hash["foo"]
25
+ assert_equal "baz", @hash[:foo]
26
+ end
27
+
28
+ test "it returns a Hash on to_hash" do
29
+ @hash[:foo] = "bar"
30
+ assert_equal Hash["foo", "bar"], @hash.to_hash
31
+ assert_kind_of Hash, @hash.to_hash
32
+ end
33
+ end if defined?(Devise::IndifferentHash)
@@ -205,6 +205,13 @@ class AuthenticationRedirectTest < ActionController::IntegrationTest
205
205
  assert_nil session[:"user_return_to"]
206
206
  end
207
207
 
208
+ test 'sign in with xml format returns xml response' do
209
+ create_user
210
+ post user_session_path(:format => 'xml', :user => {:email => "user@test.com", :password => '123456'})
211
+ assert_response :success
212
+ assert_match /<\?xml version="1.0" encoding="UTF-8"\?>/, response.body
213
+ end
214
+
208
215
  test 'redirect to configured home path for a given scope after sign in' do
209
216
  sign_in_as_admin
210
217
  assert_equal "/admin_area/home", @request.path
@@ -2,32 +2,42 @@ require 'test_helper'
2
2
 
3
3
  class OmniauthableIntegrationTest < ActionController::IntegrationTest
4
4
  FACEBOOK_INFO = {
5
- :id => '12345',
6
- :link => 'http://facebook.com/josevalim',
7
- :email => 'user@example.com',
8
- :first_name => 'Jose',
9
- :last_name => 'Valim',
10
- :website => 'http://blog.plataformatec.com.br'
11
- }
12
-
13
- ACCESS_TOKEN = {
14
- :access_token => "plataformatec"
5
+ "id" => '12345',
6
+ "link" => 'http://facebook.com/josevalim',
7
+ "email" => 'user@example.com',
8
+ "first_name" => 'Jose',
9
+ "last_name" => 'Valim',
10
+ "website" => 'http://blog.plataformatec.com.br'
15
11
  }
16
12
 
17
13
  setup do
14
+ OmniAuth.config.test_mode = true
18
15
  stub_facebook!
19
- Devise::OmniAuth.short_circuit_authorizers!
20
16
  end
21
17
 
22
18
  teardown do
23
- Devise::OmniAuth.unshort_circuit_authorizers!
24
- Devise::OmniAuth.reset_stubs!
19
+ OmniAuth.config.test_mode = false
25
20
  end
26
21
 
27
22
  def stub_facebook!
28
- Devise::OmniAuth.stub!(:facebook) do |b|
29
- b.post('/oauth/access_token') { [200, {}, ACCESS_TOKEN.to_json] }
30
- b.get('/me?access_token=plataformatec') { [200, {}, FACEBOOK_INFO.to_json] }
23
+ OmniAuth.config.mock_auth[:facebook] = {
24
+ "uid" => '12345',
25
+ "provider" => 'facebook',
26
+ "user_info" => {"nickname" => 'josevalim'},
27
+ "credentials" => {"token" => 'plataformatec'},
28
+ "extra" => {"user_hash" => FACEBOOK_INFO}
29
+ }
30
+ end
31
+
32
+ def stub_action!(name)
33
+ Users::OmniauthCallbacksController.class_eval do
34
+ alias_method :__old_facebook, :facebook
35
+ alias_method :facebook, name
36
+ end
37
+ yield
38
+ ensure
39
+ Users::OmniauthCallbacksController.class_eval do
40
+ alias_method :facebook, :__old_facebook
31
41
  end
32
42
  end
33
43
 
@@ -40,11 +50,11 @@ class OmniauthableIntegrationTest < ActionController::IntegrationTest
40
50
  assert_equal "12345", json["uid"]
41
51
  assert_equal "facebook", json["provider"]
42
52
  assert_equal "josevalim", json["user_info"]["nickname"]
43
- assert_equal FACEBOOK_INFO, json["extra"]["user_hash"].symbolize_keys
53
+ assert_equal FACEBOOK_INFO, json["extra"]["user_hash"]
44
54
  assert_equal "plataformatec", json["credentials"]["token"]
45
55
  end
46
56
 
47
- test "cleans up session on sign up" do
57
+ test "cleans up session on sign up" do
48
58
  assert_no_difference "User.count" do
49
59
  visit "/users/sign_in"
50
60
  click_link "Sign in with Facebook"
@@ -65,7 +75,7 @@ class OmniauthableIntegrationTest < ActionController::IntegrationTest
65
75
  assert_not session["devise.facebook_data"]
66
76
  end
67
77
 
68
- test "cleans up session on cancel" do
78
+ test "cleans up session on cancel" do
69
79
  assert_no_difference "User.count" do
70
80
  visit "/users/sign_in"
71
81
  click_link "Sign in with Facebook"
@@ -76,7 +86,7 @@ class OmniauthableIntegrationTest < ActionController::IntegrationTest
76
86
  assert !session["devise.facebook_data"]
77
87
  end
78
88
 
79
- test "cleans up session on sign in" do
89
+ test "cleans up session on sign in" do
80
90
  assert_no_difference "User.count" do
81
91
  visit "/users/sign_in"
82
92
  click_link "Sign in with Facebook"
@@ -87,21 +97,46 @@ class OmniauthableIntegrationTest < ActionController::IntegrationTest
87
97
  assert !session["devise.facebook_data"]
88
98
  end
89
99
 
90
- test "handles callback error parameter according to the specification" do
91
- visit "/users/auth/facebook/callback?error=access_denied"
92
- assert_current_url "/users/sign_in"
93
- assert_contain 'Could not authorize you from Facebook because "Access denied".'
94
- end
100
+ test "sign in and send remember token if configured" do
101
+ visit "/users/sign_in"
102
+ click_link "Sign in with Facebook"
103
+ assert_nil warden.cookies["remember_user_token"]
95
104
 
96
- test "handles other exceptions from omniauth" do
97
- Devise::OmniAuth.stub!(:facebook) do |b|
98
- b.post('/oauth/access_token') { [401, {}, {}.to_json] }
105
+ stub_action!(:sign_in_facebook) do
106
+ create_user
107
+ visit "/users/sign_in"
108
+ click_link "Sign in with Facebook"
109
+ assert warden.authenticated?(:user)
110
+ assert warden.cookies["remember_user_token"]
99
111
  end
112
+ end
100
113
 
114
+ test "generates a proper link when SCRIPT_NAME is set" do
115
+ header 'SCRIPT_NAME', '/q'
101
116
  visit "/users/sign_in"
102
- click_link "Sign in with facebook"
117
+ click_link "Sign in with Facebook"
103
118
 
104
- assert_current_url "/users/sign_in"
105
- assert_contain 'Could not authorize you from Facebook because "Invalid credentials".'
119
+ assert_equal '/q/users/auth/facebook', current_url
106
120
  end
107
- end
121
+
122
+ # The following two tests are commented because OmniAuth's test
123
+ # support is not yet able to support failure scenarios.
124
+ #
125
+ # test "handles callback error parameter according to the specification" do
126
+ # visit "/users/auth/facebook/callback?error=access_denied"
127
+ # assert_current_url "/users/sign_in"
128
+ # assert_contain 'Could not authorize you from Facebook because "Access denied".'
129
+ # end
130
+
131
+ # test "handles other exceptions from omniauth" do
132
+ # Devise::OmniAuth.stub!(:facebook) do |b|
133
+ # b.post('/oauth/access_token') { [401, {}, {}.to_json] }
134
+ # end
135
+
136
+ # visit "/users/sign_in"
137
+ # click_link "Sign in with facebook"
138
+
139
+ # assert_current_url "/users/sign_in"
140
+ # assert_contain 'Could not authorize you from Facebook because "Invalid credentials".'
141
+ # end
142
+ end
@@ -15,11 +15,27 @@ class RegistrationTest < ActionController::IntegrationTest
15
15
 
16
16
  assert_contain 'Welcome! You have signed up successfully.'
17
17
  assert warden.authenticated?(:admin)
18
+ assert_current_url "/admin_area/home"
18
19
 
19
20
  admin = Admin.last :order => "id"
20
21
  assert_equal admin.email, 'new_user@test.com'
21
22
  end
22
23
 
24
+ test 'a guest admin should be able to sign in and be redirected to a custom location' do
25
+ Devise::RegistrationsController.any_instance.stubs(:after_sign_up_path_for).returns("/?custom=1")
26
+ get new_admin_session_path
27
+ click_link 'Sign up'
28
+
29
+ fill_in 'email', :with => 'new_user@test.com'
30
+ fill_in 'password', :with => 'new_user123'
31
+ fill_in 'password confirmation', :with => 'new_user123'
32
+ click_button 'Sign up'
33
+
34
+ assert_contain 'Welcome! You have signed up successfully.'
35
+ assert warden.authenticated?(:admin)
36
+ assert_current_url "/?custom=1"
37
+ end
38
+
23
39
  test 'a guest user should be able to sign up successfully and be blocked by confirmation' do
24
40
  get new_user_registration_path
25
41
 
@@ -30,6 +46,7 @@ class RegistrationTest < ActionController::IntegrationTest
30
46
 
31
47
  assert_contain 'You have signed up successfully. However, we could not sign you in because your account is unconfirmed.'
32
48
  assert_not_contain 'You have to confirm your account before continuing'
49
+ assert_current_url "/"
33
50
 
34
51
  assert_not warden.authenticated?(:user)
35
52
 
@@ -38,6 +55,19 @@ class RegistrationTest < ActionController::IntegrationTest
38
55
  assert_not user.confirmed?
39
56
  end
40
57
 
58
+ test 'a guest user should be blocked by confirmation and redirected to a custom path' do
59
+ Devise::RegistrationsController.any_instance.stubs(:after_inactive_sign_up_path_for).returns("/?custom=1")
60
+ get new_user_registration_path
61
+
62
+ fill_in 'email', :with => 'new_user@test.com'
63
+ fill_in 'password', :with => 'new_user123'
64
+ fill_in 'password confirmation', :with => 'new_user123'
65
+ click_button 'Sign up'
66
+
67
+ assert_current_url "/?custom=1"
68
+ assert_not warden.authenticated?(:user)
69
+ end
70
+
41
71
  test 'a guest user cannot sign up with invalid information' do
42
72
  get new_user_registration_path
43
73