cloudfoundry-devise 1.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (210) hide show
  1. data/.gitignore +12 -0
  2. data/.travis.yml +13 -0
  3. data/CHANGELOG.rdoc +755 -0
  4. data/Gemfile +35 -0
  5. data/MIT-LICENSE +20 -0
  6. data/README.rdoc +366 -0
  7. data/Rakefile +34 -0
  8. data/app/controllers/devise/confirmations_controller.rb +46 -0
  9. data/app/controllers/devise/omniauth_callbacks_controller.rb +26 -0
  10. data/app/controllers/devise/passwords_controller.rb +50 -0
  11. data/app/controllers/devise/registrations_controller.rb +114 -0
  12. data/app/controllers/devise/sessions_controller.rb +49 -0
  13. data/app/controllers/devise/unlocks_controller.rb +34 -0
  14. data/app/helpers/devise_helper.rb +25 -0
  15. data/app/mailers/devise/mailer.rb +15 -0
  16. data/app/views/devise/confirmations/new.html.erb +12 -0
  17. data/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
  18. data/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
  19. data/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
  20. data/app/views/devise/passwords/edit.html.erb +16 -0
  21. data/app/views/devise/passwords/new.html.erb +12 -0
  22. data/app/views/devise/registrations/edit.html.erb +25 -0
  23. data/app/views/devise/registrations/new.html.erb +18 -0
  24. data/app/views/devise/sessions/new.html.erb +17 -0
  25. data/app/views/devise/shared/_links.erb +25 -0
  26. data/app/views/devise/unlocks/new.html.erb +12 -0
  27. data/cloudfoundry-devise.gemspec +25 -0
  28. data/config/locales/en.yml +59 -0
  29. data/lib/devise.rb +453 -0
  30. data/lib/devise/controllers/helpers.rb +260 -0
  31. data/lib/devise/controllers/internal_helpers.rb +161 -0
  32. data/lib/devise/controllers/rememberable.rb +52 -0
  33. data/lib/devise/controllers/scoped_views.rb +33 -0
  34. data/lib/devise/controllers/shared_helpers.rb +26 -0
  35. data/lib/devise/controllers/url_helpers.rb +53 -0
  36. data/lib/devise/delegator.rb +16 -0
  37. data/lib/devise/encryptors/authlogic_sha512.rb +19 -0
  38. data/lib/devise/encryptors/base.rb +20 -0
  39. data/lib/devise/encryptors/clearance_sha1.rb +17 -0
  40. data/lib/devise/encryptors/restful_authentication_sha1.rb +22 -0
  41. data/lib/devise/encryptors/sha1.rb +25 -0
  42. data/lib/devise/encryptors/sha512.rb +25 -0
  43. data/lib/devise/failure_app.rb +149 -0
  44. data/lib/devise/hooks/activatable.rb +11 -0
  45. data/lib/devise/hooks/forgetable.rb +9 -0
  46. data/lib/devise/hooks/rememberable.rb +6 -0
  47. data/lib/devise/hooks/timeoutable.rb +24 -0
  48. data/lib/devise/hooks/trackable.rb +9 -0
  49. data/lib/devise/mailers/helpers.rb +86 -0
  50. data/lib/devise/mapping.rb +175 -0
  51. data/lib/devise/models.rb +91 -0
  52. data/lib/devise/models/authenticatable.rb +181 -0
  53. data/lib/devise/models/confirmable.rb +220 -0
  54. data/lib/devise/models/database_authenticatable.rb +122 -0
  55. data/lib/devise/models/encryptable.rb +72 -0
  56. data/lib/devise/models/lockable.rb +169 -0
  57. data/lib/devise/models/omniauthable.rb +23 -0
  58. data/lib/devise/models/recoverable.rb +136 -0
  59. data/lib/devise/models/registerable.rb +21 -0
  60. data/lib/devise/models/rememberable.rb +114 -0
  61. data/lib/devise/models/serializable.rb +43 -0
  62. data/lib/devise/models/timeoutable.rb +45 -0
  63. data/lib/devise/models/token_authenticatable.rb +72 -0
  64. data/lib/devise/models/trackable.rb +30 -0
  65. data/lib/devise/models/validatable.rb +62 -0
  66. data/lib/devise/modules.rb +30 -0
  67. data/lib/devise/omniauth.rb +28 -0
  68. data/lib/devise/omniauth/config.rb +45 -0
  69. data/lib/devise/omniauth/url_helpers.rb +33 -0
  70. data/lib/devise/orm/active_record.rb +44 -0
  71. data/lib/devise/orm/mongoid.rb +31 -0
  72. data/lib/devise/param_filter.rb +41 -0
  73. data/lib/devise/path_checker.rb +18 -0
  74. data/lib/devise/rails.rb +73 -0
  75. data/lib/devise/rails/routes.rb +385 -0
  76. data/lib/devise/rails/warden_compat.rb +120 -0
  77. data/lib/devise/schema.rb +109 -0
  78. data/lib/devise/strategies/authenticatable.rb +155 -0
  79. data/lib/devise/strategies/base.rb +15 -0
  80. data/lib/devise/strategies/database_authenticatable.rb +21 -0
  81. data/lib/devise/strategies/rememberable.rb +53 -0
  82. data/lib/devise/strategies/token_authenticatable.rb +57 -0
  83. data/lib/devise/test_helpers.rb +90 -0
  84. data/lib/devise/version.rb +3 -0
  85. data/lib/generators/active_record/devise_generator.rb +71 -0
  86. data/lib/generators/active_record/templates/migration.rb +29 -0
  87. data/lib/generators/active_record/templates/migration_existing.rb +26 -0
  88. data/lib/generators/devise/devise_generator.rb +22 -0
  89. data/lib/generators/devise/install_generator.rb +24 -0
  90. data/lib/generators/devise/orm_helpers.rb +31 -0
  91. data/lib/generators/devise/views_generator.rb +98 -0
  92. data/lib/generators/mongoid/devise_generator.rb +60 -0
  93. data/lib/generators/templates/README +32 -0
  94. data/lib/generators/templates/devise.rb +215 -0
  95. data/lib/generators/templates/markerb/confirmation_instructions.markerb +5 -0
  96. data/lib/generators/templates/markerb/reset_password_instructions.markerb +8 -0
  97. data/lib/generators/templates/markerb/unlock_instructions.markerb +7 -0
  98. data/lib/generators/templates/simple_form_for/confirmations/new.html.erb +15 -0
  99. data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +19 -0
  100. data/lib/generators/templates/simple_form_for/passwords/new.html.erb +15 -0
  101. data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +22 -0
  102. data/lib/generators/templates/simple_form_for/registrations/new.html.erb +17 -0
  103. data/lib/generators/templates/simple_form_for/sessions/new.html.erb +15 -0
  104. data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +15 -0
  105. data/test/controllers/helpers_test.rb +254 -0
  106. data/test/controllers/internal_helpers_test.rb +96 -0
  107. data/test/controllers/sessions_controller_test.rb +16 -0
  108. data/test/controllers/url_helpers_test.rb +59 -0
  109. data/test/delegator_test.rb +19 -0
  110. data/test/devise_test.rb +72 -0
  111. data/test/encryptors_test.rb +30 -0
  112. data/test/failure_app_test.rb +207 -0
  113. data/test/generators/active_record_generator_test.rb +47 -0
  114. data/test/generators/devise_generator_test.rb +39 -0
  115. data/test/generators/install_generator_test.rb +13 -0
  116. data/test/generators/mongoid_generator_test.rb +23 -0
  117. data/test/generators/views_generator_test.rb +52 -0
  118. data/test/helpers/devise_helper_test.rb +51 -0
  119. data/test/indifferent_hash.rb +33 -0
  120. data/test/integration/authenticatable_test.rb +590 -0
  121. data/test/integration/confirmable_test.rb +262 -0
  122. data/test/integration/database_authenticatable_test.rb +82 -0
  123. data/test/integration/http_authenticatable_test.rb +82 -0
  124. data/test/integration/lockable_test.rb +212 -0
  125. data/test/integration/omniauthable_test.rb +133 -0
  126. data/test/integration/recoverable_test.rb +287 -0
  127. data/test/integration/registerable_test.rb +335 -0
  128. data/test/integration/rememberable_test.rb +158 -0
  129. data/test/integration/timeoutable_test.rb +98 -0
  130. data/test/integration/token_authenticatable_test.rb +148 -0
  131. data/test/integration/trackable_test.rb +92 -0
  132. data/test/mailers/confirmation_instructions_test.rb +95 -0
  133. data/test/mailers/reset_password_instructions_test.rb +83 -0
  134. data/test/mailers/unlock_instructions_test.rb +77 -0
  135. data/test/mapping_test.rb +128 -0
  136. data/test/models/confirmable_test.rb +334 -0
  137. data/test/models/database_authenticatable_test.rb +167 -0
  138. data/test/models/encryptable_test.rb +67 -0
  139. data/test/models/lockable_test.rb +225 -0
  140. data/test/models/recoverable_test.rb +198 -0
  141. data/test/models/rememberable_test.rb +168 -0
  142. data/test/models/serializable_test.rb +38 -0
  143. data/test/models/timeoutable_test.rb +42 -0
  144. data/test/models/token_authenticatable_test.rb +49 -0
  145. data/test/models/trackable_test.rb +5 -0
  146. data/test/models/validatable_test.rb +113 -0
  147. data/test/models_test.rb +109 -0
  148. data/test/omniauth/config_test.rb +57 -0
  149. data/test/omniauth/url_helpers_test.rb +58 -0
  150. data/test/orm/active_record.rb +9 -0
  151. data/test/orm/mongoid.rb +14 -0
  152. data/test/rails_app/Rakefile +10 -0
  153. data/test/rails_app/app/active_record/admin.rb +6 -0
  154. data/test/rails_app/app/active_record/shim.rb +2 -0
  155. data/test/rails_app/app/active_record/user.rb +6 -0
  156. data/test/rails_app/app/controllers/admins/sessions_controller.rb +6 -0
  157. data/test/rails_app/app/controllers/admins_controller.rb +6 -0
  158. data/test/rails_app/app/controllers/application_controller.rb +8 -0
  159. data/test/rails_app/app/controllers/home_controller.rb +25 -0
  160. data/test/rails_app/app/controllers/publisher/registrations_controller.rb +2 -0
  161. data/test/rails_app/app/controllers/publisher/sessions_controller.rb +2 -0
  162. data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +14 -0
  163. data/test/rails_app/app/controllers/users_controller.rb +23 -0
  164. data/test/rails_app/app/helpers/application_helper.rb +3 -0
  165. data/test/rails_app/app/mailers/users/mailer.rb +3 -0
  166. data/test/rails_app/app/mongoid/admin.rb +24 -0
  167. data/test/rails_app/app/mongoid/shim.rb +24 -0
  168. data/test/rails_app/app/mongoid/user.rb +45 -0
  169. data/test/rails_app/app/views/admins/index.html.erb +1 -0
  170. data/test/rails_app/app/views/admins/sessions/new.html.erb +2 -0
  171. data/test/rails_app/app/views/home/admin_dashboard.html.erb +1 -0
  172. data/test/rails_app/app/views/home/index.html.erb +1 -0
  173. data/test/rails_app/app/views/home/join.html.erb +1 -0
  174. data/test/rails_app/app/views/home/private.html.erb +1 -0
  175. data/test/rails_app/app/views/home/user_dashboard.html.erb +1 -0
  176. data/test/rails_app/app/views/layouts/application.html.erb +24 -0
  177. data/test/rails_app/app/views/users/index.html.erb +1 -0
  178. data/test/rails_app/app/views/users/mailer/confirmation_instructions.erb +1 -0
  179. data/test/rails_app/app/views/users/sessions/new.html.erb +1 -0
  180. data/test/rails_app/config.ru +4 -0
  181. data/test/rails_app/config/application.rb +41 -0
  182. data/test/rails_app/config/boot.rb +8 -0
  183. data/test/rails_app/config/database.yml +18 -0
  184. data/test/rails_app/config/environment.rb +5 -0
  185. data/test/rails_app/config/environments/development.rb +18 -0
  186. data/test/rails_app/config/environments/production.rb +33 -0
  187. data/test/rails_app/config/environments/test.rb +33 -0
  188. data/test/rails_app/config/initializers/backtrace_silencers.rb +7 -0
  189. data/test/rails_app/config/initializers/devise.rb +197 -0
  190. data/test/rails_app/config/initializers/inflections.rb +2 -0
  191. data/test/rails_app/config/initializers/secret_token.rb +2 -0
  192. data/test/rails_app/config/routes.rb +87 -0
  193. data/test/rails_app/db/migrate/20100401102949_create_tables.rb +71 -0
  194. data/test/rails_app/db/schema.rb +52 -0
  195. data/test/rails_app/lib/shared_admin.rb +10 -0
  196. data/test/rails_app/lib/shared_user.rb +26 -0
  197. data/test/rails_app/public/404.html +26 -0
  198. data/test/rails_app/public/422.html +26 -0
  199. data/test/rails_app/public/500.html +26 -0
  200. data/test/rails_app/public/favicon.ico +0 -0
  201. data/test/rails_app/script/rails +10 -0
  202. data/test/routes_test.rb +240 -0
  203. data/test/support/assertions.rb +27 -0
  204. data/test/support/helpers.rb +109 -0
  205. data/test/support/integration.rb +88 -0
  206. data/test/support/locale/en.yml +4 -0
  207. data/test/support/webrat/integrations/rails.rb +24 -0
  208. data/test/test_helper.rb +27 -0
  209. data/test/test_helpers_test.rb +134 -0
  210. metadata +295 -0
@@ -0,0 +1,5 @@
1
+ require 'test_helper'
2
+
3
+ class TrackableTest < ActiveSupport::TestCase
4
+
5
+ end
@@ -0,0 +1,113 @@
1
+ # encoding: UTF-8
2
+ require 'test_helper'
3
+
4
+ class ValidatableTest < ActiveSupport::TestCase
5
+ test 'should require email to be set' do
6
+ user = new_user(:email => nil)
7
+ assert user.invalid?
8
+ assert user.errors[:email]
9
+ assert_equal 'can\'t be blank', user.errors[:email].join
10
+ end
11
+
12
+ test 'should require uniqueness of email if email has changed, allowing blank' do
13
+ existing_user = create_user
14
+
15
+ user = new_user(:email => '')
16
+ assert user.invalid?
17
+ assert_no_match(/taken/, user.errors[:email].join)
18
+
19
+ user.email = existing_user.email
20
+ assert user.invalid?
21
+ assert_match(/taken/, user.errors[:email].join)
22
+
23
+ user.save(:validate => false)
24
+ assert user.valid?
25
+ end
26
+
27
+ test 'should require correct email format if email has changed, allowing blank' do
28
+ user = new_user(:email => '')
29
+ assert user.invalid?
30
+ assert_not_equal 'is invalid', user.errors[:email].join
31
+
32
+ %w{invalid_email_format 123 $$$ () ☃ bla@bla.}.each do |email|
33
+ user.email = email
34
+ assert user.invalid?, 'should be invalid with email ' << email
35
+ assert_equal 'is invalid', user.errors[:email].join
36
+ end
37
+
38
+ user.save(:validate => false)
39
+ assert user.valid?
40
+ end
41
+
42
+ test 'should accept valid emails' do
43
+ %w(a.b.c@example.com test_mail@gmail.com any@any.net email@test.br 123@mail.test 1☃3@mail.test).each do |email|
44
+ user = new_user(:email => email)
45
+ assert user.valid?, 'should be valid with email ' << email
46
+ assert_blank user.errors[:email]
47
+ end
48
+ end
49
+
50
+ test 'should require password to be set when creating a new record' do
51
+ user = new_user(:password => '', :password_confirmation => '')
52
+ assert user.invalid?
53
+ assert_equal 'can\'t be blank', user.errors[:password].join
54
+ end
55
+
56
+ test 'should require confirmation to be set when creating a new record' do
57
+ user = new_user(:password => 'new_password', :password_confirmation => 'blabla')
58
+ assert user.invalid?
59
+ assert_equal 'doesn\'t match confirmation', user.errors[:password].join
60
+ end
61
+
62
+ test 'should require password when updating/reseting password' do
63
+ user = create_user
64
+
65
+ user.password = ''
66
+ user.password_confirmation = ''
67
+
68
+ assert user.invalid?
69
+ assert_equal 'can\'t be blank', user.errors[:password].join
70
+ end
71
+
72
+ test 'should require confirmation when updating/reseting password' do
73
+ user = create_user
74
+ user.password_confirmation = 'another_password'
75
+ assert user.invalid?
76
+ assert_equal 'doesn\'t match confirmation', user.errors[:password].join
77
+ end
78
+
79
+ test 'should require a password with minimum of 6 characters' do
80
+ user = new_user(:password => '12345', :password_confirmation => '12345')
81
+ assert user.invalid?
82
+ assert_equal 'is too short (minimum is 6 characters)', user.errors[:password].join
83
+ end
84
+
85
+ test 'should require a password with maximum of 128 characters long' do
86
+ user = new_user(:password => 'x'*129, :password_confirmation => 'x'*129)
87
+ assert user.invalid?
88
+ assert_equal 'is too long (maximum is 128 characters)', user.errors[:password].join
89
+ end
90
+
91
+ test 'should not require password length when it\'s not changed' do
92
+ user = create_user.reload
93
+ user.password = user.password_confirmation = nil
94
+ assert user.valid?
95
+
96
+ user.password_confirmation = 'confirmation'
97
+ assert user.invalid?
98
+ assert_not (user.errors[:password].join =~ /is too long/)
99
+ end
100
+
101
+ test 'should complain about length even if possword is not required' do
102
+ user = new_user(:password => 'x'*129, :password_confirmation => 'x'*129)
103
+ user.stubs(:password_required?).returns(false)
104
+ assert user.invalid?
105
+ assert_equal 'is too long (maximum is 128 characters)', user.errors[:password].join
106
+ end
107
+
108
+ test 'shuold not be included in objects with invalid API' do
109
+ assert_raise RuntimeError do
110
+ Class.new.send :include, Devise::Models::Validatable
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,109 @@
1
+ require 'test_helper'
2
+
3
+ class Configurable < User
4
+ devise :database_authenticatable, :encryptable, :confirmable, :rememberable, :timeoutable, :lockable,
5
+ :stretches => 15, :pepper => 'abcdef', :confirm_within => 5.days,
6
+ :remember_for => 7.days, :timeout_in => 15.minutes, :unlock_in => 10.days
7
+ end
8
+
9
+ class WithValidation < Admin
10
+ devise :database_authenticatable, :validatable, :password_length => 2..6
11
+ end
12
+
13
+ class UserWithValidation < User
14
+ validates_presence_of :username
15
+ end
16
+
17
+ class Several < Admin
18
+ devise :validatable
19
+ devise :lockable
20
+ end
21
+
22
+ class Inheritable < Admin
23
+ end
24
+
25
+ class ActiveRecordTest < ActiveSupport::TestCase
26
+ def include_module?(klass, mod)
27
+ klass.devise_modules.include?(mod) &&
28
+ klass.included_modules.include?(Devise::Models::const_get(mod.to_s.classify))
29
+ end
30
+
31
+ def assert_include_modules(klass, *modules)
32
+ modules.each do |mod|
33
+ assert include_module?(klass, mod)
34
+ end
35
+
36
+ (Devise::ALL - modules).each do |mod|
37
+ assert_not include_module?(klass, mod)
38
+ end
39
+ end
40
+
41
+ test 'can cherry pick modules' do
42
+ assert_include_modules Admin, :database_authenticatable, :registerable, :timeoutable, :recoverable, :lockable, :encryptable
43
+ end
44
+
45
+ test 'validations options are not applied too late' do
46
+ validators = WithValidation.validators_on :password
47
+ length = validators.find { |v| v.kind == :length }
48
+ assert_equal 2, length.options[:minimum]
49
+ assert_equal 6, length.options[:maximum]
50
+ end
51
+
52
+ test 'validations are applied just once' do
53
+ validators = Several.validators_on :password
54
+ assert_equal 1, validators.select{ |v| v.kind == :length }.length
55
+ end
56
+
57
+ test 'chosen modules are inheritable' do
58
+ assert_include_modules Inheritable, :database_authenticatable, :registerable, :timeoutable, :recoverable, :lockable, :encryptable
59
+ end
60
+
61
+ test 'order of module inclusion' do
62
+ correct_module_order = [:database_authenticatable, :encryptable, :recoverable, :registerable, :lockable, :timeoutable]
63
+ incorrect_module_order = [:database_authenticatable, :timeoutable, :registerable, :recoverable, :lockable, :encryptable]
64
+
65
+ assert_include_modules Admin, *incorrect_module_order
66
+
67
+ # get module constants from symbol list
68
+ module_constants = correct_module_order.collect { |mod| Devise::Models::const_get(mod.to_s.classify) }
69
+
70
+ # confirm that they adhere to the order in ALL
71
+ # get included modules, filter out the noise, and reverse the order
72
+ assert_equal module_constants, (Admin.included_modules & module_constants).reverse
73
+ end
74
+
75
+ test 'raise error on invalid module' do
76
+ assert_raise NameError do
77
+ # Mix valid an invalid modules.
78
+ Configurable.class_eval { devise :database_authenticatable, :doesnotexit }
79
+ end
80
+ end
81
+
82
+ test 'set a default value for stretches' do
83
+ assert_equal 15, Configurable.stretches
84
+ end
85
+
86
+ test 'set a default value for pepper' do
87
+ assert_equal 'abcdef', Configurable.pepper
88
+ end
89
+
90
+ test 'set a default value for confirm_within' do
91
+ assert_equal 5.days, Configurable.confirm_within
92
+ end
93
+
94
+ test 'set a default value for remember_for' do
95
+ assert_equal 7.days, Configurable.remember_for
96
+ end
97
+
98
+ test 'set a default value for timeout_in' do
99
+ assert_equal 15.minutes, Configurable.timeout_in
100
+ end
101
+
102
+ test 'set a default value for unlock_in' do
103
+ assert_equal 10.days, Configurable.unlock_in
104
+ end
105
+
106
+ test 'set null fields on migrations' do
107
+ Admin.create!
108
+ end
109
+ end
@@ -0,0 +1,57 @@
1
+ require 'test_helper'
2
+
3
+ class OmniAuthConfigTest < ActiveSupport::TestCase
4
+ class MyStrategy
5
+ include OmniAuth::Strategy
6
+ end
7
+
8
+ test 'strategy_name returns provider if no options given' do
9
+ config = Devise::OmniAuth::Config.new :facebook, [{}]
10
+ assert_equal :facebook, config.strategy_name
11
+ end
12
+
13
+ test 'strategy_name returns provider if no name option are given' do
14
+ config = Devise::OmniAuth::Config.new :facebook, [{ :other => :option }]
15
+ assert_equal :facebook, config.strategy_name
16
+ end
17
+
18
+ test 'returns name option when have a name' do
19
+ config = Devise::OmniAuth::Config.new :facebook, [{ :name => :github }]
20
+ assert_equal :github, config.strategy_name
21
+ end
22
+
23
+ test "finds contrib strategies" do
24
+ config = Devise::OmniAuth::Config.new :facebook, [{}]
25
+ assert_equal OmniAuth::Strategies::Facebook, config.strategy_class
26
+ end
27
+
28
+ test "finds the strategy in OmniAuth's list by name" do
29
+ NamedTestStrategy = Class.new
30
+ NamedTestStrategy.send :include, OmniAuth::Strategy
31
+ NamedTestStrategy.option :name, :the_one
32
+
33
+ config = Devise::OmniAuth::Config.new :the_one, [{}]
34
+ assert_equal NamedTestStrategy, config.strategy_class
35
+ end
36
+
37
+ test "finds the strategy in OmniAuth's list by class name" do
38
+ UnNamedTestStrategy = Class.new
39
+ UnNamedTestStrategy.send :include, OmniAuth::Strategy
40
+
41
+ config = Devise::OmniAuth::Config.new :un_named_test_strategy, [{}]
42
+ assert_equal UnNamedTestStrategy, config.strategy_class
43
+ end
44
+
45
+ test 'raises an error if strategy cannot be found' do
46
+ config = Devise::OmniAuth::Config.new :my_other_strategy, [{}]
47
+ assert_raise Devise::OmniAuth::StrategyNotFound do
48
+ config.strategy_class
49
+ end
50
+ end
51
+
52
+ test 'allows the user to define a custom require path' do
53
+ config = Devise::OmniAuth::Config.new :my_strategy, [{:strategy_class => MyStrategy}]
54
+ config_class = config.strategy_class
55
+ assert_equal MyStrategy, config_class
56
+ end
57
+ end
@@ -0,0 +1,58 @@
1
+ require 'test_helper'
2
+
3
+ class OmniAuthRoutesTest < ActionController::TestCase
4
+ tests ApplicationController
5
+
6
+ def assert_path(action, provider, with_param=true)
7
+ # Resource param
8
+ assert_equal @controller.send(action, :user, provider),
9
+ @controller.send("user_#{action}", provider)
10
+
11
+ # With an object
12
+ assert_equal @controller.send(action, User.new, provider),
13
+ @controller.send("user_#{action}", provider)
14
+
15
+ if with_param
16
+ # Default url params
17
+ assert_equal @controller.send(action, :user, provider, :param => 123),
18
+ @controller.send("user_#{action}", provider, :param => 123)
19
+ end
20
+ end
21
+
22
+ test 'should alias omniauth_callback to mapped user auth_callback' do
23
+ assert_path :omniauth_callback_path, :facebook
24
+ end
25
+
26
+ test 'should alias omniauth_authorize to mapped user auth_authorize' do
27
+ assert_path :omniauth_authorize_path, :facebook, false
28
+ end
29
+
30
+ test 'should generate authorization path' do
31
+ assert_match "/users/auth/facebook", @controller.omniauth_authorize_path(:user, :facebook)
32
+
33
+ assert_raise ArgumentError do
34
+ @controller.omniauth_authorize_path(:user, :github)
35
+ end
36
+ end
37
+
38
+ test 'should generate authorization path for named open_id omniauth' do
39
+ assert_match "/users/auth/google", @controller.omniauth_authorize_path(:user, :google)
40
+ end
41
+
42
+ test 'should generate authorization path with params' do
43
+ assert_match "/users/auth/openid?openid_url=http%3A%2F%2Fyahoo.com",
44
+ @controller.omniauth_authorize_path(:user, :openid, :openid_url => "http://yahoo.com")
45
+ end
46
+
47
+ test 'should not add a "?" if no param was sent' do
48
+ assert_equal "/users/auth/openid",
49
+ @controller.omniauth_authorize_path(:user, :openid)
50
+ end
51
+
52
+ test 'should set script name in the path if present' do
53
+ @request.env['SCRIPT_NAME'] = '/q'
54
+
55
+ assert_equal "/q/users/auth/facebook",
56
+ @controller.omniauth_authorize_path(:user, :facebook)
57
+ end
58
+ end
@@ -0,0 +1,9 @@
1
+ ActiveRecord::Migration.verbose = false
2
+ ActiveRecord::Base.logger = Logger.new(nil)
3
+
4
+ ActiveRecord::Migrator.migrate(File.expand_path("../../rails_app/db/migrate/", __FILE__))
5
+
6
+ class ActiveSupport::TestCase
7
+ self.use_transactional_fixtures = true
8
+ self.use_instantiated_fixtures = false
9
+ end
@@ -0,0 +1,14 @@
1
+ require 'mongoid/version'
2
+
3
+ Mongoid.configure do |config|
4
+ config.master = Mongo::Connection.new('127.0.0.1', 27017).db("devise-test-suite")
5
+ config.use_utc = true
6
+ config.include_root_in_json = true
7
+ end
8
+
9
+ class ActiveSupport::TestCase
10
+ setup do
11
+ User.delete_all
12
+ Admin.delete_all
13
+ end
14
+ end
@@ -0,0 +1,10 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ require 'rake'
7
+ require 'rake/testtask'
8
+ require 'rake/rdoctask'
9
+
10
+ Rails.application.load_tasks
@@ -0,0 +1,6 @@
1
+ require 'shared_admin'
2
+
3
+ class Admin < ActiveRecord::Base
4
+ include Shim
5
+ include SharedAdmin
6
+ end
@@ -0,0 +1,2 @@
1
+ module Shim
2
+ end
@@ -0,0 +1,6 @@
1
+ require 'shared_user'
2
+
3
+ class User < ActiveRecord::Base
4
+ include Shim
5
+ include SharedUser
6
+ end
@@ -0,0 +1,6 @@
1
+ class Admins::SessionsController < Devise::SessionsController
2
+ def new
3
+ flash[:special] = "Welcome to #{controller_path.inspect} controller!"
4
+ super
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ class AdminsController < ApplicationController
2
+ before_filter :authenticate_admin!
3
+
4
+ def index
5
+ end
6
+ end
@@ -0,0 +1,8 @@
1
+ # Filters added to this controller apply to all controllers in the application.
2
+ # Likewise, all the methods added will be available for all controllers.
3
+
4
+ class ApplicationController < ActionController::Base
5
+ protect_from_forgery
6
+ before_filter :current_user
7
+ before_filter :authenticate_user!, :if => :devise_controller?
8
+ end
@@ -0,0 +1,25 @@
1
+ class HomeController < ApplicationController
2
+ def index
3
+ end
4
+
5
+ def private
6
+ end
7
+
8
+ def user_dashboard
9
+ end
10
+
11
+ def admin_dashboard
12
+ end
13
+
14
+ def join
15
+ end
16
+
17
+ def set
18
+ session["devise.foo_bar"] = "something"
19
+ head :ok
20
+ end
21
+
22
+ def unauthenticated
23
+ render :text => "unauthenticated", :status => :unauthorized
24
+ end
25
+ end