mongoid-devise 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +333 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +260 -0
- data/Rakefile +53 -0
- data/TODO +2 -0
- data/app/controllers/confirmations_controller.rb +33 -0
- data/app/controllers/passwords_controller.rb +42 -0
- data/app/controllers/registrations_controller.rb +55 -0
- data/app/controllers/sessions_controller.rb +45 -0
- data/app/controllers/unlocks_controller.rb +33 -0
- data/app/models/devise_mailer.rb +68 -0
- data/app/views/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/passwords/edit.html.erb +16 -0
- data/app/views/passwords/new.html.erb +12 -0
- data/app/views/registrations/edit.html.erb +25 -0
- data/app/views/registrations/new.html.erb +17 -0
- data/app/views/sessions/new.html.erb +17 -0
- data/app/views/shared/_devise_links.erb +19 -0
- data/app/views/unlocks/new.html.erb +12 -0
- data/generators/devise/USAGE +5 -0
- data/generators/devise/devise_generator.rb +15 -0
- data/generators/devise/lib/route_devise.rb +32 -0
- data/generators/devise/templates/migration.rb +23 -0
- data/generators/devise/templates/model.rb +9 -0
- data/generators/devise_install/USAGE +3 -0
- data/generators/devise_install/devise_install_generator.rb +15 -0
- data/generators/devise_install/templates/README +18 -0
- data/generators/devise_install/templates/devise.rb +102 -0
- data/generators/devise_views/USAGE +3 -0
- data/generators/devise_views/devise_views_generator.rb +21 -0
- data/init.rb +2 -0
- data/lib/devise.rb +253 -0
- data/lib/devise/controllers/helpers.rb +200 -0
- data/lib/devise/controllers/internal_helpers.rb +129 -0
- data/lib/devise/controllers/url_helpers.rb +41 -0
- data/lib/devise/encryptors/authlogic_sha512.rb +21 -0
- data/lib/devise/encryptors/base.rb +20 -0
- data/lib/devise/encryptors/bcrypt.rb +21 -0
- data/lib/devise/encryptors/clearance_sha1.rb +19 -0
- data/lib/devise/encryptors/restful_authentication_sha1.rb +22 -0
- data/lib/devise/encryptors/sha1.rb +27 -0
- data/lib/devise/encryptors/sha512.rb +27 -0
- data/lib/devise/failure_app.rb +65 -0
- data/lib/devise/hooks/activatable.rb +15 -0
- data/lib/devise/hooks/rememberable.rb +30 -0
- data/lib/devise/hooks/timeoutable.rb +18 -0
- data/lib/devise/hooks/trackable.rb +18 -0
- data/lib/devise/locales/en.yml +35 -0
- data/lib/devise/mapping.rb +131 -0
- data/lib/devise/models.rb +112 -0
- data/lib/devise/models/activatable.rb +16 -0
- data/lib/devise/models/authenticatable.rb +146 -0
- data/lib/devise/models/confirmable.rb +172 -0
- data/lib/devise/models/http_authenticatable.rb +21 -0
- data/lib/devise/models/lockable.rb +160 -0
- data/lib/devise/models/recoverable.rb +80 -0
- data/lib/devise/models/registerable.rb +8 -0
- data/lib/devise/models/rememberable.rb +94 -0
- data/lib/devise/models/timeoutable.rb +28 -0
- data/lib/devise/models/token_authenticatable.rb +89 -0
- data/lib/devise/models/trackable.rb +16 -0
- data/lib/devise/models/validatable.rb +48 -0
- data/lib/devise/orm/active_record.rb +41 -0
- data/lib/devise/orm/data_mapper.rb +83 -0
- data/lib/devise/orm/mongo_mapper.rb +51 -0
- data/lib/devise/orm/mongoid.rb +60 -0
- data/lib/devise/rails.rb +14 -0
- data/lib/devise/rails/routes.rb +125 -0
- data/lib/devise/rails/warden_compat.rb +25 -0
- data/lib/devise/schema.rb +65 -0
- data/lib/devise/strategies/authenticatable.rb +36 -0
- data/lib/devise/strategies/base.rb +16 -0
- data/lib/devise/strategies/http_authenticatable.rb +49 -0
- data/lib/devise/strategies/rememberable.rb +37 -0
- data/lib/devise/strategies/token_authenticatable.rb +37 -0
- data/lib/devise/test_helpers.rb +86 -0
- data/lib/devise/version.rb +3 -0
- data/test/controllers/helpers_test.rb +177 -0
- data/test/controllers/internal_helpers_test.rb +55 -0
- data/test/controllers/url_helpers_test.rb +47 -0
- data/test/devise_test.rb +69 -0
- data/test/encryptors_test.rb +31 -0
- data/test/failure_app_test.rb +44 -0
- data/test/integration/authenticatable_test.rb +271 -0
- data/test/integration/confirmable_test.rb +97 -0
- data/test/integration/http_authenticatable_test.rb +44 -0
- data/test/integration/lockable_test.rb +83 -0
- data/test/integration/recoverable_test.rb +141 -0
- data/test/integration/registerable_test.rb +130 -0
- data/test/integration/rememberable_test.rb +63 -0
- data/test/integration/timeoutable_test.rb +68 -0
- data/test/integration/token_authenticatable_test.rb +55 -0
- data/test/integration/trackable_test.rb +64 -0
- data/test/mailers/confirmation_instructions_test.rb +80 -0
- data/test/mailers/reset_password_instructions_test.rb +68 -0
- data/test/mailers/unlock_instructions_test.rb +62 -0
- data/test/mapping_test.rb +153 -0
- data/test/models/authenticatable_test.rb +180 -0
- data/test/models/confirmable_test.rb +228 -0
- data/test/models/lockable_test.rb +202 -0
- data/test/models/recoverable_test.rb +138 -0
- data/test/models/rememberable_test.rb +135 -0
- data/test/models/timeoutable_test.rb +28 -0
- data/test/models/token_authenticatable_test.rb +51 -0
- data/test/models/trackable_test.rb +5 -0
- data/test/models/validatable_test.rb +106 -0
- data/test/models_test.rb +56 -0
- data/test/orm/active_record.rb +31 -0
- data/test/orm/mongo_mapper.rb +20 -0
- data/test/orm/mongoid.rb +22 -0
- data/test/rails_app/app/active_record/admin.rb +7 -0
- data/test/rails_app/app/active_record/user.rb +7 -0
- data/test/rails_app/app/controllers/admins_controller.rb +6 -0
- data/test/rails_app/app/controllers/application_controller.rb +10 -0
- data/test/rails_app/app/controllers/home_controller.rb +4 -0
- data/test/rails_app/app/controllers/users_controller.rb +16 -0
- data/test/rails_app/app/helpers/application_helper.rb +3 -0
- data/test/rails_app/app/mongo_mapper/admin.rb +9 -0
- data/test/rails_app/app/mongo_mapper/user.rb +8 -0
- data/test/rails_app/app/mongoid/admin.rb +9 -0
- data/test/rails_app/app/mongoid/user.rb +8 -0
- data/test/rails_app/config/boot.rb +110 -0
- data/test/rails_app/config/environment.rb +42 -0
- data/test/rails_app/config/environments/development.rb +17 -0
- data/test/rails_app/config/environments/production.rb +28 -0
- data/test/rails_app/config/environments/test.rb +28 -0
- data/test/rails_app/config/initializers/devise.rb +79 -0
- data/test/rails_app/config/initializers/inflections.rb +2 -0
- data/test/rails_app/config/initializers/new_rails_defaults.rb +24 -0
- data/test/rails_app/config/initializers/session_store.rb +15 -0
- data/test/rails_app/config/routes.rb +21 -0
- data/test/routes_test.rb +110 -0
- data/test/support/assertions_helper.rb +37 -0
- data/test/support/integration_tests_helper.rb +71 -0
- data/test/support/test_silencer.rb +5 -0
- data/test/support/tests_helper.rb +39 -0
- data/test/test_helper.rb +21 -0
- data/test/test_helpers_test.rb +57 -0
- metadata +216 -0
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'test/test_helper'
|
2
|
+
|
3
|
+
class SessionTimeoutTest < ActionController::IntegrationTest
|
4
|
+
|
5
|
+
def last_request_at
|
6
|
+
@controller.user_session['last_request_at']
|
7
|
+
end
|
8
|
+
|
9
|
+
test 'set last request at in user session after each request' do
|
10
|
+
sign_in_as_user
|
11
|
+
old_last_request = last_request_at
|
12
|
+
assert_not_nil last_request_at
|
13
|
+
|
14
|
+
get users_path
|
15
|
+
assert_not_nil last_request_at
|
16
|
+
assert_not_equal old_last_request, last_request_at
|
17
|
+
end
|
18
|
+
|
19
|
+
test 'not time out user session before default limit time' do
|
20
|
+
sign_in_as_user
|
21
|
+
assert_response :success
|
22
|
+
assert warden.authenticated?(:user)
|
23
|
+
|
24
|
+
get users_path
|
25
|
+
assert_response :success
|
26
|
+
assert warden.authenticated?(:user)
|
27
|
+
end
|
28
|
+
|
29
|
+
test 'time out user session after default limit time' do
|
30
|
+
user = sign_in_as_user
|
31
|
+
get expire_user_path(user)
|
32
|
+
assert_not_nil last_request_at
|
33
|
+
|
34
|
+
get users_path
|
35
|
+
assert_redirected_to new_user_session_path(:timeout => true)
|
36
|
+
assert_not warden.authenticated?(:user)
|
37
|
+
end
|
38
|
+
|
39
|
+
test 'user configured timeout limit' do
|
40
|
+
swap Devise, :timeout_in => 8.minutes do
|
41
|
+
user = sign_in_as_user
|
42
|
+
|
43
|
+
get users_path
|
44
|
+
assert_not_nil last_request_at
|
45
|
+
assert_response :success
|
46
|
+
assert warden.authenticated?(:user)
|
47
|
+
|
48
|
+
get expire_user_path(user)
|
49
|
+
get users_path
|
50
|
+
assert_redirected_to new_user_session_path(:timeout => true)
|
51
|
+
assert_not warden.authenticated?(:user)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
test 'error message with i18n' do
|
56
|
+
store_translations :en, :devise => {
|
57
|
+
:sessions => { :user => { :timeout => 'Session expired!' } }
|
58
|
+
} do
|
59
|
+
user = sign_in_as_user
|
60
|
+
|
61
|
+
get expire_user_path(user)
|
62
|
+
get users_path
|
63
|
+
follow_redirect!
|
64
|
+
assert_contain 'Session expired!'
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'test/test_helper'
|
2
|
+
|
3
|
+
class TokenAuthenticationTest < ActionController::IntegrationTest
|
4
|
+
|
5
|
+
test 'sign in should authenticate with valid authentication token and proper authentication token key' do
|
6
|
+
swap Devise, :token_authentication_key => :secret_token do
|
7
|
+
sign_in_as_new_user_with_token(:auth_token_key => :secret_token)
|
8
|
+
|
9
|
+
assert_response :success
|
10
|
+
assert_template 'users/index'
|
11
|
+
assert_contain 'Welcome'
|
12
|
+
assert warden.authenticated?(:user)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
test 'signing in with valid authentication token - but improper authentication token key - return to sign in form with error message' do
|
17
|
+
swap Devise, :token_authentication_key => :donald_duck_token do
|
18
|
+
sign_in_as_new_user_with_token(:auth_token_key => :secret_token)
|
19
|
+
assert_redirected_to new_user_session_path(:unauthenticated => true)
|
20
|
+
follow_redirect!
|
21
|
+
|
22
|
+
assert_contain 'You need to sign in or sign up before continuing'
|
23
|
+
assert_contain 'Sign in'
|
24
|
+
assert_not warden.authenticated?(:user)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
test 'signing in with invalid authentication token should return to sign in form with error message' do
|
29
|
+
store_translations :en, :devise => {:sessions => {:invalid_token => 'LOL, that was not a single character correct.'}} do
|
30
|
+
sign_in_as_new_user_with_token(:auth_token => '*** INVALID TOKEN ***')
|
31
|
+
assert_redirected_to new_user_session_path(:invalid_token => true)
|
32
|
+
follow_redirect!
|
33
|
+
|
34
|
+
assert_response :success
|
35
|
+
assert_contain 'LOL, that was not a single character correct.'
|
36
|
+
assert_contain 'Sign in'
|
37
|
+
assert_not warden.authenticated?(:user)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def sign_in_as_new_user_with_token(options = {})
|
44
|
+
options[:auth_token_key] ||= Devise.token_authentication_key
|
45
|
+
options[:auth_token] ||= VALID_AUTHENTICATION_TOKEN
|
46
|
+
|
47
|
+
user = create_user(options)
|
48
|
+
user.authentication_token = VALID_AUTHENTICATION_TOKEN
|
49
|
+
user.save
|
50
|
+
|
51
|
+
visit users_path(options[:auth_token_key].to_sym => options[:auth_token])
|
52
|
+
user
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'test/test_helper'
|
2
|
+
|
3
|
+
class TrackableHooksTest < ActionController::IntegrationTest
|
4
|
+
|
5
|
+
test "current and last sign in timestamps are updated on each sign in" do
|
6
|
+
user = create_user
|
7
|
+
assert_nil user.current_sign_in_at
|
8
|
+
assert_nil user.last_sign_in_at
|
9
|
+
|
10
|
+
sign_in_as_user
|
11
|
+
user.reload
|
12
|
+
|
13
|
+
assert_kind_of Time, user.current_sign_in_at
|
14
|
+
assert_kind_of Time, user.last_sign_in_at
|
15
|
+
|
16
|
+
assert_equal user.current_sign_in_at, user.last_sign_in_at
|
17
|
+
assert user.current_sign_in_at >= user.created_at
|
18
|
+
|
19
|
+
visit destroy_user_session_path
|
20
|
+
new_time = 2.seconds.from_now
|
21
|
+
Time.stubs(:now).returns(new_time)
|
22
|
+
|
23
|
+
sign_in_as_user
|
24
|
+
user.reload
|
25
|
+
assert user.current_sign_in_at > user.last_sign_in_at
|
26
|
+
end
|
27
|
+
|
28
|
+
test "current and last sign in remote ip are updated on each sign in" do
|
29
|
+
user = create_user
|
30
|
+
assert_nil user.current_sign_in_ip
|
31
|
+
assert_nil user.last_sign_in_ip
|
32
|
+
|
33
|
+
sign_in_as_user
|
34
|
+
user.reload
|
35
|
+
|
36
|
+
assert_equal "127.0.0.1", user.current_sign_in_ip
|
37
|
+
assert_equal "127.0.0.1", user.last_sign_in_ip
|
38
|
+
end
|
39
|
+
|
40
|
+
test "increase sign in count" do
|
41
|
+
user = create_user
|
42
|
+
assert_nil user.sign_in_count
|
43
|
+
|
44
|
+
sign_in_as_user
|
45
|
+
user.reload
|
46
|
+
assert_equal 1, user.sign_in_count
|
47
|
+
|
48
|
+
visit destroy_user_session_path
|
49
|
+
sign_in_as_user
|
50
|
+
user.reload
|
51
|
+
assert_equal 2, user.sign_in_count
|
52
|
+
end
|
53
|
+
|
54
|
+
test "does not update anything if user has signed out along the way" do
|
55
|
+
swap Devise, :confirm_within => 0 do
|
56
|
+
user = create_user(:confirm => false)
|
57
|
+
sign_in_as_user
|
58
|
+
|
59
|
+
user.reload
|
60
|
+
assert_nil user.current_sign_in_at
|
61
|
+
assert_nil user.last_sign_in_at
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'test/test_helper'
|
2
|
+
|
3
|
+
class ConfirmationInstructionsTest < ActionMailer::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
setup_mailer
|
7
|
+
Devise.mailer_sender = 'test@example.com'
|
8
|
+
end
|
9
|
+
|
10
|
+
def user
|
11
|
+
@user ||= create_user
|
12
|
+
end
|
13
|
+
|
14
|
+
def mail
|
15
|
+
@mail ||= begin
|
16
|
+
user
|
17
|
+
ActionMailer::Base.deliveries.first
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
test 'email sent after creating the user' do
|
22
|
+
assert_not_nil mail
|
23
|
+
end
|
24
|
+
|
25
|
+
test 'content type should be set to html' do
|
26
|
+
assert_equal 'text/html', mail.content_type
|
27
|
+
end
|
28
|
+
|
29
|
+
test 'send confirmation instructions to the user email' do
|
30
|
+
mail
|
31
|
+
assert_equal [user.email], mail.to
|
32
|
+
end
|
33
|
+
|
34
|
+
test 'setup sender from configuration' do
|
35
|
+
assert_equal ['test@example.com'], mail.from
|
36
|
+
end
|
37
|
+
|
38
|
+
test 'setup subject from I18n' do
|
39
|
+
store_translations :en, :devise => { :mailer => { :confirmation_instructions => 'Account Confirmation' } } do
|
40
|
+
assert_equal 'Account Confirmation', mail.subject
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
test 'subject namespaced by model' do
|
45
|
+
store_translations :en, :devise => { :mailer => { :user => { :confirmation_instructions => 'User Account Confirmation' } } } do
|
46
|
+
assert_equal 'User Account Confirmation', mail.subject
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
test 'body should have user info' do
|
51
|
+
assert_match /#{user.email}/, mail.body
|
52
|
+
end
|
53
|
+
|
54
|
+
test 'body should have link to confirm the account' do
|
55
|
+
host = ActionMailer::Base.default_url_options[:host]
|
56
|
+
confirmation_url_regexp = %r{<a href=\"http://#{host}/users/confirmation\?confirmation_token=#{user.confirmation_token}">}
|
57
|
+
assert_match confirmation_url_regexp, mail.body
|
58
|
+
end
|
59
|
+
|
60
|
+
test 'renders a scoped if scoped_views is set to true' do
|
61
|
+
swap Devise, :scoped_views => true do
|
62
|
+
assert_equal user.email, mail.body
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
test 'renders a scoped if scoped_views is set in the mailer class' do
|
67
|
+
begin
|
68
|
+
DeviseMailer.scoped_views = true
|
69
|
+
assert_equal user.email, mail.body
|
70
|
+
ensure
|
71
|
+
DeviseMailer.send :remove_instance_variable, :@scoped_views
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
test 'mailer sender accepts a proc' do
|
76
|
+
swap Devise, :mailer_sender => lambda { "another@example.com" } do
|
77
|
+
assert_equal ['another@example.com'], mail.from
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'test/test_helper'
|
2
|
+
|
3
|
+
class ResetPasswordInstructionsTest < ActionMailer::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
setup_mailer
|
7
|
+
Devise.mailer_sender = 'test@example.com'
|
8
|
+
end
|
9
|
+
|
10
|
+
def user
|
11
|
+
@user ||= begin
|
12
|
+
user = create_user
|
13
|
+
user.send_reset_password_instructions
|
14
|
+
user
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def mail
|
19
|
+
@mail ||= begin
|
20
|
+
user
|
21
|
+
ActionMailer::Base.deliveries.last
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
test 'email sent after reseting the user password' do
|
26
|
+
assert_not_nil mail
|
27
|
+
end
|
28
|
+
|
29
|
+
test 'content type should be set to html' do
|
30
|
+
assert_equal 'text/html', mail.content_type
|
31
|
+
end
|
32
|
+
|
33
|
+
test 'send confirmation instructions to the user email' do
|
34
|
+
assert_equal [user.email], mail.to
|
35
|
+
end
|
36
|
+
|
37
|
+
test 'setup sender from configuration' do
|
38
|
+
assert_equal ['test@example.com'], mail.from
|
39
|
+
end
|
40
|
+
|
41
|
+
test 'setup subject from I18n' do
|
42
|
+
store_translations :en, :devise => { :mailer => { :reset_password_instructions => 'Reset instructions' } } do
|
43
|
+
assert_equal 'Reset instructions', mail.subject
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
test 'subject namespaced by model' do
|
48
|
+
store_translations :en, :devise => { :mailer => { :user => { :reset_password_instructions => 'User Reset Instructions' } } } do
|
49
|
+
assert_equal 'User Reset Instructions', mail.subject
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
test 'body should have user info' do
|
54
|
+
assert_match /#{user.email}/, mail.body
|
55
|
+
end
|
56
|
+
|
57
|
+
test 'body should have link to confirm the account' do
|
58
|
+
host = ActionMailer::Base.default_url_options[:host]
|
59
|
+
reset_url_regexp = %r{<a href=\"http://#{host}/users/password/edit\?reset_password_token=#{user.reset_password_token}">}
|
60
|
+
assert_match reset_url_regexp, mail.body
|
61
|
+
end
|
62
|
+
|
63
|
+
test 'mailer sender accepts a proc' do
|
64
|
+
swap Devise, :mailer_sender => lambda { "another@example.com" } do
|
65
|
+
assert_equal ['another@example.com'], mail.from
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'test/test_helper'
|
2
|
+
|
3
|
+
class UnlockInstructionsTest < ActionMailer::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
setup_mailer
|
7
|
+
Devise.mailer_sender = 'test@example.com'
|
8
|
+
end
|
9
|
+
|
10
|
+
def user
|
11
|
+
@user ||= begin
|
12
|
+
user = create_user
|
13
|
+
user.lock!
|
14
|
+
user
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def mail
|
19
|
+
@mail ||= begin
|
20
|
+
user
|
21
|
+
ActionMailer::Base.deliveries.last
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
test 'email sent after locking the user' do
|
26
|
+
assert_not_nil mail
|
27
|
+
end
|
28
|
+
|
29
|
+
test 'content type should be set to html' do
|
30
|
+
assert_equal 'text/html', mail.content_type
|
31
|
+
end
|
32
|
+
|
33
|
+
test 'send unlock instructions to the user email' do
|
34
|
+
assert_equal [user.email], mail.to
|
35
|
+
end
|
36
|
+
|
37
|
+
test 'setup sender from configuration' do
|
38
|
+
assert_equal ['test@example.com'], mail.from
|
39
|
+
end
|
40
|
+
|
41
|
+
test 'setup subject from I18n' do
|
42
|
+
store_translations :en, :devise => { :mailer => { :unlock_instructions => 'Unlock instructions' } } do
|
43
|
+
assert_equal 'Unlock instructions', mail.subject
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
test 'subject namespaced by model' do
|
48
|
+
store_translations :en, :devise => { :mailer => { :user => { :unlock_instructions => 'User Unlock Instructions' } } } do
|
49
|
+
assert_equal 'User Unlock Instructions', mail.subject
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
test 'body should have user info' do
|
54
|
+
assert_match /#{user.email}/, mail.body
|
55
|
+
end
|
56
|
+
|
57
|
+
test 'body should have link to unlock the account' do
|
58
|
+
host = ActionMailer::Base.default_url_options[:host]
|
59
|
+
unlock_url_regexp = %r{<a href=\"http://#{host}/users/unlock\?unlock_token=#{user.unlock_token}">}
|
60
|
+
assert_match unlock_url_regexp, mail.body
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,153 @@
|
|
1
|
+
require 'test/test_helper'
|
2
|
+
|
3
|
+
class MappingTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
test 'store options' do
|
6
|
+
mapping = Devise.mappings[:user]
|
7
|
+
|
8
|
+
assert_equal User, mapping.to
|
9
|
+
assert_equal User.devise_modules, mapping.for
|
10
|
+
assert_equal :users, mapping.as
|
11
|
+
end
|
12
|
+
|
13
|
+
test 'allows as to be given' do
|
14
|
+
assert_equal :admin_area, Devise.mappings[:admin].as
|
15
|
+
end
|
16
|
+
|
17
|
+
test 'allow custom scope to be given' do
|
18
|
+
assert_equal :accounts, Devise.mappings[:manager].as
|
19
|
+
end
|
20
|
+
|
21
|
+
test 'allows a controller depending on the mapping' do
|
22
|
+
mapping = Devise.mappings[:user]
|
23
|
+
assert mapping.allows?(:sessions)
|
24
|
+
assert mapping.allows?(:confirmations)
|
25
|
+
assert mapping.allows?(:passwords)
|
26
|
+
|
27
|
+
mapping = Devise.mappings[:admin]
|
28
|
+
assert mapping.allows?(:sessions)
|
29
|
+
assert_not mapping.allows?(:confirmations)
|
30
|
+
assert_not mapping.allows?(:passwords)
|
31
|
+
end
|
32
|
+
|
33
|
+
test 'find mapping by path' do
|
34
|
+
assert_nil Devise::Mapping.find_by_path("/foo/bar")
|
35
|
+
assert_equal Devise.mappings[:user], Devise::Mapping.find_by_path("/users/session")
|
36
|
+
end
|
37
|
+
|
38
|
+
test 'find mapping by customized path' do
|
39
|
+
assert_equal Devise.mappings[:admin], Devise::Mapping.find_by_path("/admin_area/session")
|
40
|
+
end
|
41
|
+
|
42
|
+
test 'find mapping by class' do
|
43
|
+
assert_nil Devise::Mapping.find_by_class(String)
|
44
|
+
assert_equal Devise.mappings[:user], Devise::Mapping.find_by_class(User)
|
45
|
+
end
|
46
|
+
|
47
|
+
test 'find mapping by class works with single table inheritance' do
|
48
|
+
klass = Class.new(User)
|
49
|
+
assert_equal Devise.mappings[:user], Devise::Mapping.find_by_class(klass)
|
50
|
+
end
|
51
|
+
|
52
|
+
test 'find scope for a given object' do
|
53
|
+
assert_equal :user, Devise::Mapping.find_scope!(User)
|
54
|
+
assert_equal :user, Devise::Mapping.find_scope!(:user)
|
55
|
+
assert_equal :user, Devise::Mapping.find_scope!(User.new)
|
56
|
+
end
|
57
|
+
|
58
|
+
test 'find scope raises an error if cannot be found' do
|
59
|
+
assert_raise RuntimeError do
|
60
|
+
Devise::Mapping.find_scope!(String)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
test 'return default path names' do
|
65
|
+
mapping = Devise.mappings[:user]
|
66
|
+
assert_equal 'sign_in', mapping.path_names[:sign_in]
|
67
|
+
assert_equal 'sign_out', mapping.path_names[:sign_out]
|
68
|
+
assert_equal 'password', mapping.path_names[:password]
|
69
|
+
assert_equal 'confirmation', mapping.path_names[:confirmation]
|
70
|
+
assert_equal 'sign_up', mapping.path_names[:sign_up]
|
71
|
+
assert_equal 'unlock', mapping.path_names[:unlock]
|
72
|
+
end
|
73
|
+
|
74
|
+
test 'allow custom path names to be given' do
|
75
|
+
mapping = Devise.mappings[:manager]
|
76
|
+
assert_equal 'login', mapping.path_names[:sign_in]
|
77
|
+
assert_equal 'logout', mapping.path_names[:sign_out]
|
78
|
+
assert_equal 'secret', mapping.path_names[:password]
|
79
|
+
assert_equal 'verification', mapping.path_names[:confirmation]
|
80
|
+
assert_equal 'register', mapping.path_names[:sign_up]
|
81
|
+
assert_equal 'unblock', mapping.path_names[:unlock]
|
82
|
+
end
|
83
|
+
|
84
|
+
test 'has an empty path as default path prefix' do
|
85
|
+
mapping = Devise.mappings[:user]
|
86
|
+
assert_equal '/', mapping.path_prefix
|
87
|
+
end
|
88
|
+
|
89
|
+
test 'allow path prefix to be configured' do
|
90
|
+
mapping = Devise.mappings[:manager]
|
91
|
+
assert_equal '/:locale/', mapping.path_prefix
|
92
|
+
end
|
93
|
+
|
94
|
+
test 'retrieve as from the proper position' do
|
95
|
+
assert_equal 1, Devise.mappings[:user].as_position
|
96
|
+
assert_equal 2, Devise.mappings[:manager].as_position
|
97
|
+
end
|
98
|
+
|
99
|
+
test 'raw path is returned' do
|
100
|
+
assert_equal '/users', Devise.mappings[:user].raw_path
|
101
|
+
assert_equal '/:locale/accounts', Devise.mappings[:manager].raw_path
|
102
|
+
end
|
103
|
+
|
104
|
+
test 'raw path ignores the relative_url_root' do
|
105
|
+
swap ActionController::Base, :relative_url_root => "/abc" do
|
106
|
+
assert_equal '/users', Devise.mappings[:user].raw_path
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
test 'parsed path is returned' do
|
111
|
+
begin
|
112
|
+
Devise.default_url_options {{ :locale => I18n.locale }}
|
113
|
+
assert_equal '/users', Devise.mappings[:user].parsed_path
|
114
|
+
assert_equal '/en/accounts', Devise.mappings[:manager].parsed_path
|
115
|
+
ensure
|
116
|
+
Devise.default_url_options {{ }}
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
test 'parsed path adds in the relative_url_root' do
|
121
|
+
swap ActionController::Base, :relative_url_root => '/abc' do
|
122
|
+
assert_equal '/abc/users', Devise.mappings[:user].parsed_path
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
test 'parsed path deals with a nil relative_url_root' do
|
127
|
+
swap ActionController::Base, :relative_url_root => nil do
|
128
|
+
assert_equal '/users', Devise.mappings[:user].raw_path
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
test 'should have default route options' do
|
133
|
+
assert_equal({}, Devise.mappings[:user].route_options)
|
134
|
+
end
|
135
|
+
|
136
|
+
test 'should allow passing route options to devise routes' do
|
137
|
+
assert_equal({ :requirements => { :extra => 'value' } }, Devise.mappings[:manager].route_options)
|
138
|
+
end
|
139
|
+
|
140
|
+
test 'magic predicates' do
|
141
|
+
mapping = Devise.mappings[:user]
|
142
|
+
assert mapping.authenticatable?
|
143
|
+
assert mapping.confirmable?
|
144
|
+
assert mapping.recoverable?
|
145
|
+
assert mapping.rememberable?
|
146
|
+
|
147
|
+
mapping = Devise.mappings[:admin]
|
148
|
+
assert mapping.authenticatable?
|
149
|
+
assert_not mapping.confirmable?
|
150
|
+
assert_not mapping.recoverable?
|
151
|
+
assert_not mapping.rememberable?
|
152
|
+
end
|
153
|
+
end
|