rails_mvp_authentication 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +28 -0
- data/Rakefile +8 -0
- data/app/assets/config/rails_mvp_authentication_manifest.js +1 -0
- data/app/assets/stylesheets/rails_mvp_authentication/application.css +15 -0
- data/app/controllers/rails_mvp_authentication/application_controller.rb +4 -0
- data/app/helpers/rails_mvp_authentication/application_helper.rb +4 -0
- data/app/jobs/rails_mvp_authentication/application_job.rb +4 -0
- data/app/mailers/rails_mvp_authentication/application_mailer.rb +6 -0
- data/app/models/rails_mvp_authentication/application_record.rb +5 -0
- data/app/views/layouts/rails_mvp_authentication/application.html.erb +15 -0
- data/config/routes.rb +2 -0
- data/lib/generators/rails_mvp_authentication/USAGE +5 -0
- data/lib/generators/rails_mvp_authentication/install_generator.rb +251 -0
- data/lib/generators/rails_mvp_authentication/templates/README +7 -0
- data/lib/generators/rails_mvp_authentication/templates/authentication.rb.tt +58 -0
- data/lib/generators/rails_mvp_authentication/templates/confirmations_controller.rb.tt +32 -0
- data/lib/generators/rails_mvp_authentication/templates/current.rb.tt +3 -0
- data/lib/generators/rails_mvp_authentication/templates/passwords_controller.rb.tt +52 -0
- data/lib/generators/rails_mvp_authentication/templates/sessions_controller.rb.tt +30 -0
- data/lib/generators/rails_mvp_authentication/templates/test/controllers/active_sessions_controller_test.rb.tt +68 -0
- data/lib/generators/rails_mvp_authentication/templates/test/controllers/confirmations_controller_test.rb.tt +143 -0
- data/lib/generators/rails_mvp_authentication/templates/test/controllers/passwords_controller_test.rb.tt +119 -0
- data/lib/generators/rails_mvp_authentication/templates/test/controllers/sessions_controller_test.rb.tt +105 -0
- data/lib/generators/rails_mvp_authentication/templates/test/controllers/users_controller_test.rb.tt +150 -0
- data/lib/generators/rails_mvp_authentication/templates/test/integration/friendly_redirects_test.rb.tt +23 -0
- data/lib/generators/rails_mvp_authentication/templates/test/integration/user_interface_test.rb.tt +35 -0
- data/lib/generators/rails_mvp_authentication/templates/test/mailers/previews/user_mailer_preview.rb.tt +17 -0
- data/lib/generators/rails_mvp_authentication/templates/test/mailers/user_mailer_test.rb.tt +25 -0
- data/lib/generators/rails_mvp_authentication/templates/test/models/active_session_test.rb.tt +18 -0
- data/lib/generators/rails_mvp_authentication/templates/test/models/user_test.rb.tt +183 -0
- data/lib/generators/rails_mvp_authentication/templates/test/system/logins_test.rb.tt +18 -0
- data/lib/generators/rails_mvp_authentication/templates/user.rb.tt +96 -0
- data/lib/generators/rails_mvp_authentication/templates/user_mailer.rb.tt +22 -0
- data/lib/generators/rails_mvp_authentication/templates/users_controller.rb.tt +59 -0
- data/lib/generators/rails_mvp_authentication/templates/views/confirmations/new.html.erb.tt +4 -0
- data/lib/generators/rails_mvp_authentication/templates/views/passwords/edit.html.erb.tt +11 -0
- data/lib/generators/rails_mvp_authentication/templates/views/passwords/new.html.erb.tt +4 -0
- data/lib/generators/rails_mvp_authentication/templates/views/sessions/new.html.erb.tt +15 -0
- data/lib/generators/rails_mvp_authentication/templates/views/user_mailer/confirmation.html.erb.tt +3 -0
- data/lib/generators/rails_mvp_authentication/templates/views/user_mailer/confirmation.text.erb.tt +3 -0
- data/lib/generators/rails_mvp_authentication/templates/views/user_mailer/password_reset.html.erb.tt +3 -0
- data/lib/generators/rails_mvp_authentication/templates/views/user_mailer/password_reset.text.erb.tt +3 -0
- data/lib/generators/rails_mvp_authentication/templates/views/users/edit.html.erb.tt +42 -0
- data/lib/generators/rails_mvp_authentication/templates/views/users/new.html.erb.tt +16 -0
- data/lib/rails_mvp_authentication/engine.rb +5 -0
- data/lib/rails_mvp_authentication/version.rb +3 -0
- data/lib/rails_mvp_authentication.rb +6 -0
- data/lib/tasks/rails_mvp_authentication_tasks.rake +4 -0
- metadata +129 -0
@@ -0,0 +1,143 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class ConfirmationsControllerTest < ActionDispatch::IntegrationTest
|
4
|
+
setup do
|
5
|
+
@reconfirmed_user = User.create!(email: "reconfirmed_user@example.com", password: "password", password_confirmation: "password", confirmed_at: 1.week.ago, unconfirmed_email: "unconfirmed_email@example.com")
|
6
|
+
@confirmed_user = User.create!(email: "confirmed_user@example.com", password: "password", password_confirmation: "password", confirmed_at: 1.week.ago)
|
7
|
+
@unconfirmed_user = User.create!(email: "unconfirmed_user@example.com", password: "password", password_confirmation: "password")
|
8
|
+
end
|
9
|
+
|
10
|
+
test "should confirm unconfirmed user" do
|
11
|
+
freeze_time do
|
12
|
+
confirmation_token = @unconfirmed_user.generate_confirmation_token
|
13
|
+
|
14
|
+
get edit_confirmation_path(confirmation_token)
|
15
|
+
|
16
|
+
assert @unconfirmed_user.reload.confirmed?
|
17
|
+
assert_equal Time.now, @unconfirmed_user.confirmed_at
|
18
|
+
assert_redirected_to root_path
|
19
|
+
assert_not_nil flash[:notice]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
test "should reconfirm confirmed user" do
|
24
|
+
unconfirmed_email = @reconfirmed_user.unconfirmed_email
|
25
|
+
|
26
|
+
freeze_time do
|
27
|
+
confirmation_token = @reconfirmed_user.generate_confirmation_token
|
28
|
+
|
29
|
+
get edit_confirmation_path(confirmation_token)
|
30
|
+
|
31
|
+
assert @reconfirmed_user.reload.confirmed?
|
32
|
+
assert_equal Time.current, @reconfirmed_user.reload.confirmed_at
|
33
|
+
assert_equal unconfirmed_email, @reconfirmed_user.reload.email
|
34
|
+
assert_nil @reconfirmed_user.reload.unconfirmed_email
|
35
|
+
assert_redirected_to root_path
|
36
|
+
assert_not_nil flash[:notice]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
test "should not update email address if already taken" do
|
41
|
+
original_email = @reconfirmed_user.email
|
42
|
+
@reconfirmed_user.update(unconfirmed_email: @confirmed_user.email)
|
43
|
+
|
44
|
+
freeze_time do
|
45
|
+
confirmation_token = @reconfirmed_user.generate_confirmation_token
|
46
|
+
|
47
|
+
get edit_confirmation_path(confirmation_token)
|
48
|
+
|
49
|
+
assert_equal original_email, @reconfirmed_user.reload.email
|
50
|
+
assert_redirected_to new_confirmation_path
|
51
|
+
assert_not_nil flash[:alert]
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
test "should redirect if confirmation link expired" do
|
56
|
+
confirmation_token = @unconfirmed_user.generate_confirmation_token
|
57
|
+
|
58
|
+
travel_to 601.seconds.from_now do
|
59
|
+
get edit_confirmation_path(confirmation_token)
|
60
|
+
|
61
|
+
assert_nil @unconfirmed_user.reload.confirmed_at
|
62
|
+
assert_not @unconfirmed_user.reload.confirmed?
|
63
|
+
assert_redirected_to new_confirmation_path
|
64
|
+
assert_not_nil flash[:alert]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
test "should redirect if confirmation link is incorrect" do
|
69
|
+
get edit_confirmation_path("not_a_real_token")
|
70
|
+
assert_redirected_to new_confirmation_path
|
71
|
+
assert_not_nil flash[:alert]
|
72
|
+
end
|
73
|
+
|
74
|
+
test "should resend confirmation email if user is unconfirmed" do
|
75
|
+
assert_emails 1 do
|
76
|
+
post confirmations_path, params: {user: {email: @unconfirmed_user.email}}
|
77
|
+
end
|
78
|
+
|
79
|
+
assert_redirected_to root_path
|
80
|
+
assert_not_nil flash[:notice]
|
81
|
+
end
|
82
|
+
|
83
|
+
test "should prevent user from confirming if they are already confirmed" do
|
84
|
+
assert_no_emails do
|
85
|
+
post confirmations_path, params: {user: {email: @confirmed_user.email}}
|
86
|
+
end
|
87
|
+
assert_redirected_to new_confirmation_path
|
88
|
+
assert_not_nil flash[:alert]
|
89
|
+
end
|
90
|
+
|
91
|
+
test "should get new if not authenticated" do
|
92
|
+
get new_confirmation_path
|
93
|
+
assert_response :ok
|
94
|
+
end
|
95
|
+
|
96
|
+
test "should prevent authenticated user from confirming" do
|
97
|
+
freeze_time do
|
98
|
+
confirmation_token = @confirmed_user.generate_confirmation_token
|
99
|
+
|
100
|
+
login @confirmed_user
|
101
|
+
|
102
|
+
get edit_confirmation_path(confirmation_token)
|
103
|
+
|
104
|
+
assert_not_equal Time.current, @confirmed_user.reload.confirmed_at
|
105
|
+
assert_redirected_to new_confirmation_path
|
106
|
+
assert_not_nil flash[:alert]
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
test "should not prevent authenticated user confirming their unconfirmed_email" do
|
111
|
+
unconfirmed_email = @reconfirmed_user.unconfirmed_email
|
112
|
+
|
113
|
+
freeze_time do
|
114
|
+
login @reconfirmed_user
|
115
|
+
|
116
|
+
confirmation_token = @reconfirmed_user.generate_confirmation_token
|
117
|
+
|
118
|
+
get edit_confirmation_path(confirmation_token)
|
119
|
+
|
120
|
+
assert_equal Time.current, @reconfirmed_user.reload.confirmed_at
|
121
|
+
assert @reconfirmed_user.reload.confirmed?
|
122
|
+
assert_equal unconfirmed_email, @reconfirmed_user.reload.email
|
123
|
+
assert_nil @reconfirmed_user.reload.unconfirmed_email
|
124
|
+
assert_redirected_to root_path
|
125
|
+
assert_not_nil flash[:notice]
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
test "should prevent authenticated user from submitting the confirmation form" do
|
130
|
+
login @confirmed_user
|
131
|
+
|
132
|
+
get new_confirmation_path
|
133
|
+
assert_redirected_to root_path
|
134
|
+
assert_not_nil flash[:alert]
|
135
|
+
|
136
|
+
assert_no_emails do
|
137
|
+
post confirmations_path, params: {user: {email: @confirmed_user.email}}
|
138
|
+
end
|
139
|
+
|
140
|
+
assert_redirected_to root_path
|
141
|
+
assert_not_nil flash[:alert]
|
142
|
+
end
|
143
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class PasswordsControllerTest < ActionDispatch::IntegrationTest
|
4
|
+
setup do
|
5
|
+
@confirmed_user = User.create!(email: "confirmed_user@example.com", password: "password", password_confirmation: "password", confirmed_at: 1.week.ago)
|
6
|
+
end
|
7
|
+
|
8
|
+
test "should get edit" do
|
9
|
+
password_reset_token = @confirmed_user.generate_password_reset_token
|
10
|
+
|
11
|
+
get edit_password_path(password_reset_token)
|
12
|
+
assert_response :ok
|
13
|
+
end
|
14
|
+
|
15
|
+
test "should redirect from edit if password link expired" do
|
16
|
+
password_reset_token = @confirmed_user.generate_password_reset_token
|
17
|
+
|
18
|
+
travel_to 601.seconds.from_now
|
19
|
+
get edit_password_path(password_reset_token)
|
20
|
+
|
21
|
+
assert_redirected_to new_password_path
|
22
|
+
assert_not_nil flash[:alert]
|
23
|
+
end
|
24
|
+
|
25
|
+
test "should redirect from edit if password link is incorrect" do
|
26
|
+
get edit_password_path("not_a_real_token")
|
27
|
+
|
28
|
+
assert_redirected_to new_password_path
|
29
|
+
assert_not_nil flash[:alert]
|
30
|
+
end
|
31
|
+
|
32
|
+
test "should redirect from edit if user is not confirmed" do
|
33
|
+
@confirmed_user.update!(confirmed_at: nil)
|
34
|
+
password_reset_token = @confirmed_user.generate_password_reset_token
|
35
|
+
|
36
|
+
get edit_password_path(password_reset_token)
|
37
|
+
|
38
|
+
assert_redirected_to new_confirmation_path
|
39
|
+
assert_not_nil flash[:alert]
|
40
|
+
end
|
41
|
+
|
42
|
+
test "should redirect from edit if user is authenticated" do
|
43
|
+
password_reset_token = @confirmed_user.generate_password_reset_token
|
44
|
+
|
45
|
+
login @confirmed_user
|
46
|
+
|
47
|
+
get edit_password_path(password_reset_token)
|
48
|
+
assert_redirected_to root_path
|
49
|
+
end
|
50
|
+
|
51
|
+
test "should get new" do
|
52
|
+
get new_password_path
|
53
|
+
assert_response :ok
|
54
|
+
end
|
55
|
+
|
56
|
+
test "should redirect from new if user is authenticated" do
|
57
|
+
login @confirmed_user
|
58
|
+
|
59
|
+
get new_password_path
|
60
|
+
assert_redirected_to root_path
|
61
|
+
end
|
62
|
+
|
63
|
+
test "should send password reset mailer" do
|
64
|
+
assert_emails 1 do
|
65
|
+
post passwords_path, params: {
|
66
|
+
user: {
|
67
|
+
email: @confirmed_user.email.upcase
|
68
|
+
}
|
69
|
+
}
|
70
|
+
end
|
71
|
+
|
72
|
+
assert_redirected_to root_path
|
73
|
+
assert_not_nil flash[:notice]
|
74
|
+
end
|
75
|
+
|
76
|
+
test "should update password" do
|
77
|
+
password_reset_token = @confirmed_user.generate_password_reset_token
|
78
|
+
|
79
|
+
put password_path(password_reset_token), params: {
|
80
|
+
user: {
|
81
|
+
password: "password",
|
82
|
+
password_confirmation: "password"
|
83
|
+
}
|
84
|
+
}
|
85
|
+
|
86
|
+
assert_redirected_to login_path
|
87
|
+
assert_not_nil flash[:notice]
|
88
|
+
end
|
89
|
+
|
90
|
+
test "should handle errors" do
|
91
|
+
password_reset_token = @confirmed_user.generate_password_reset_token
|
92
|
+
|
93
|
+
put password_path(password_reset_token), params: {
|
94
|
+
user: {
|
95
|
+
password: "password",
|
96
|
+
password_confirmation: "password_that_does_not_match"
|
97
|
+
}
|
98
|
+
}
|
99
|
+
|
100
|
+
assert_not_nil flash[:alert]
|
101
|
+
end
|
102
|
+
|
103
|
+
test "should not update password if authenticated" do
|
104
|
+
password_reset_token = @confirmed_user.generate_password_reset_token
|
105
|
+
|
106
|
+
login @confirmed_user
|
107
|
+
|
108
|
+
put password_path(password_reset_token), params: {
|
109
|
+
user: {
|
110
|
+
password: "password",
|
111
|
+
password_confirmation: "password"
|
112
|
+
|
113
|
+
}
|
114
|
+
}
|
115
|
+
|
116
|
+
get new_password_path
|
117
|
+
assert_redirected_to root_path
|
118
|
+
end
|
119
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class SessionsControllerTest < ActionDispatch::IntegrationTest
|
4
|
+
setup do
|
5
|
+
@unconfirmed_user = User.create!(email: "unconfirmed_user@example.com", password: "password", password_confirmation: "password")
|
6
|
+
@confirmed_user = User.create!(email: "confirmed_user@example.com", password: "password", password_confirmation: "password", confirmed_at: Time.current)
|
7
|
+
end
|
8
|
+
|
9
|
+
test "should get login if anonymous" do
|
10
|
+
get login_path
|
11
|
+
assert_response :ok
|
12
|
+
end
|
13
|
+
|
14
|
+
test "should redirect from login if authenticated" do
|
15
|
+
login @confirmed_user
|
16
|
+
|
17
|
+
get login_path
|
18
|
+
assert_redirected_to root_path
|
19
|
+
end
|
20
|
+
|
21
|
+
test "should login and create active session if confirmed" do
|
22
|
+
assert_difference("@confirmed_user.active_sessions.count") do
|
23
|
+
post login_path, params: {
|
24
|
+
user: {
|
25
|
+
email: @confirmed_user.email,
|
26
|
+
password: @confirmed_user.password
|
27
|
+
}
|
28
|
+
}
|
29
|
+
end
|
30
|
+
assert_redirected_to root_path
|
31
|
+
assert_equal @confirmed_user, current_user
|
32
|
+
end
|
33
|
+
|
34
|
+
test "should remember user when logging in" do
|
35
|
+
assert_nil cookies[:remember_token]
|
36
|
+
|
37
|
+
post login_path, params: {
|
38
|
+
user: {
|
39
|
+
email: @confirmed_user.email,
|
40
|
+
password: @confirmed_user.password,
|
41
|
+
remember_me: 1
|
42
|
+
}
|
43
|
+
}
|
44
|
+
|
45
|
+
assert_not_nil current_user
|
46
|
+
assert_not_nil cookies[:remember_token]
|
47
|
+
end
|
48
|
+
|
49
|
+
test "should forget user when logging out" do
|
50
|
+
login @confirmed_user, remember_user: true
|
51
|
+
|
52
|
+
delete logout_path
|
53
|
+
|
54
|
+
# FIXME: Expected "" to be nil.
|
55
|
+
# When I run byebug in SessionsController#destroy cookies[:remember_token] does == nil.
|
56
|
+
# I think this might be a bug in Rails?
|
57
|
+
# assert_nil cookies[:remember_token]
|
58
|
+
assert cookies[:remember_token].blank?
|
59
|
+
assert_nil current_user
|
60
|
+
assert_redirected_to root_path
|
61
|
+
assert_not_nil flash[:notice]
|
62
|
+
end
|
63
|
+
|
64
|
+
test "should not login if unconfirmed" do
|
65
|
+
post login_path, params: {
|
66
|
+
user: {
|
67
|
+
email: @unconfirmed_user.email,
|
68
|
+
password: @unconfirmed_user.password
|
69
|
+
}
|
70
|
+
}
|
71
|
+
assert_equal "Incorrect email or password.", flash[:alert]
|
72
|
+
assert_nil current_user
|
73
|
+
assert_redirected_to new_confirmation_path
|
74
|
+
end
|
75
|
+
|
76
|
+
test "should handle invalid login" do
|
77
|
+
post login_path, params: {
|
78
|
+
user: {
|
79
|
+
email: @confirmed_user.email,
|
80
|
+
password: "foo"
|
81
|
+
}
|
82
|
+
}
|
83
|
+
assert_not_nil flash[:alert]
|
84
|
+
assert_nil current_user
|
85
|
+
end
|
86
|
+
|
87
|
+
test "should logout and delete current active session if authenticated" do
|
88
|
+
login @confirmed_user
|
89
|
+
|
90
|
+
assert_difference("@confirmed_user.active_sessions.count", -1) do
|
91
|
+
delete logout_path
|
92
|
+
end
|
93
|
+
|
94
|
+
assert_nil current_user
|
95
|
+
assert_redirected_to root_path
|
96
|
+
assert_not_nil flash[:notice]
|
97
|
+
end
|
98
|
+
|
99
|
+
test "should not logout if anonymous" do
|
100
|
+
login @confirmed_user
|
101
|
+
|
102
|
+
delete logout_path
|
103
|
+
assert_redirected_to root_path
|
104
|
+
end
|
105
|
+
end
|
data/lib/generators/rails_mvp_authentication/templates/test/controllers/users_controller_test.rb.tt
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class UsersControllerTest < ActionDispatch::IntegrationTest
|
4
|
+
setup do
|
5
|
+
@confirmed_user = User.create!(email: "confirmed_user@example.com", password: "password", password_confirmation: "password", confirmed_at: Time.current)
|
6
|
+
end
|
7
|
+
|
8
|
+
test "should load sign up page for anonymous users" do
|
9
|
+
get sign_up_path
|
10
|
+
assert_response :ok
|
11
|
+
end
|
12
|
+
|
13
|
+
test "should redirect authenticated users from signing up" do
|
14
|
+
login @confirmed_user
|
15
|
+
|
16
|
+
get sign_up_path
|
17
|
+
assert_redirected_to root_path
|
18
|
+
|
19
|
+
assert_no_difference("User.count") do
|
20
|
+
post sign_up_path, params: {
|
21
|
+
user: {
|
22
|
+
email: "some_unique_email@example.com",
|
23
|
+
password: "password",
|
24
|
+
password_confirmation: "password"
|
25
|
+
}
|
26
|
+
}
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
test "should create user and send confirmation instructions" do
|
31
|
+
assert_difference("User.count", 1) do
|
32
|
+
assert_emails 1 do
|
33
|
+
post sign_up_path, params: {
|
34
|
+
user: {
|
35
|
+
email: "some_unique_email@example.com",
|
36
|
+
password: "password",
|
37
|
+
password_confirmation: "password"
|
38
|
+
}
|
39
|
+
}
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
assert_redirected_to root_path
|
44
|
+
assert_not_nil flash[:notice]
|
45
|
+
end
|
46
|
+
|
47
|
+
test "should handle errors when signing up" do
|
48
|
+
assert_no_difference("User.count") do
|
49
|
+
assert_no_emails do
|
50
|
+
post sign_up_path, params: {
|
51
|
+
user: {
|
52
|
+
email: "some_unique_email@example.com",
|
53
|
+
password: "password",
|
54
|
+
password_confirmation: "wrong_password"
|
55
|
+
}
|
56
|
+
}
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
test "should get edit if authorized" do
|
62
|
+
login(@confirmed_user)
|
63
|
+
|
64
|
+
get account_path
|
65
|
+
assert_response :ok
|
66
|
+
end
|
67
|
+
|
68
|
+
test "should redirect unauthorized user from editing account" do
|
69
|
+
get account_path
|
70
|
+
assert_redirected_to login_path
|
71
|
+
assert_not_nil flash[:alert]
|
72
|
+
end
|
73
|
+
|
74
|
+
test "should edit email" do
|
75
|
+
unconfirmed_email = "unconfirmed_user@example.com"
|
76
|
+
current_email = @confirmed_user.email
|
77
|
+
|
78
|
+
login(@confirmed_user)
|
79
|
+
|
80
|
+
assert_emails 1 do
|
81
|
+
put account_path, params: {
|
82
|
+
user: {
|
83
|
+
unconfirmed_email: unconfirmed_email,
|
84
|
+
current_password: "password"
|
85
|
+
}
|
86
|
+
}
|
87
|
+
end
|
88
|
+
|
89
|
+
assert_not_nil flash[:notice]
|
90
|
+
assert_equal current_email, @confirmed_user.reload.email
|
91
|
+
end
|
92
|
+
|
93
|
+
test "should not edit email if current_password is incorrect" do
|
94
|
+
unconfirmed_email = "unconfirmed_user@example.com"
|
95
|
+
current_email = @confirmed_user.email
|
96
|
+
|
97
|
+
login(@confirmed_user)
|
98
|
+
|
99
|
+
assert_no_emails do
|
100
|
+
put account_path, params: {
|
101
|
+
user: {
|
102
|
+
unconfirmed_email: unconfirmed_email,
|
103
|
+
current_password: "wrong_password"
|
104
|
+
}
|
105
|
+
}
|
106
|
+
end
|
107
|
+
|
108
|
+
assert_not_nil flash[:notice]
|
109
|
+
assert_equal current_email, @confirmed_user.reload.email
|
110
|
+
end
|
111
|
+
|
112
|
+
test "should update password" do
|
113
|
+
login(@confirmed_user)
|
114
|
+
|
115
|
+
put account_path, params: {
|
116
|
+
user: {
|
117
|
+
current_password: "password",
|
118
|
+
password: "new_password",
|
119
|
+
password_confirmation: "new_password"
|
120
|
+
}
|
121
|
+
}
|
122
|
+
|
123
|
+
assert_redirected_to root_path
|
124
|
+
assert_not_nil flash[:notice]
|
125
|
+
end
|
126
|
+
|
127
|
+
test "should not update password if current_password is incorrect" do
|
128
|
+
login(@confirmed_user)
|
129
|
+
|
130
|
+
put account_path, params: {
|
131
|
+
user: {
|
132
|
+
current_password: "wrong_password",
|
133
|
+
password: "new_password",
|
134
|
+
password_confirmation: "new_password"
|
135
|
+
}
|
136
|
+
}
|
137
|
+
|
138
|
+
assert_response :unprocessable_entity
|
139
|
+
end
|
140
|
+
|
141
|
+
test "should delete user" do
|
142
|
+
login(@confirmed_user)
|
143
|
+
|
144
|
+
delete account_path(@confirmed_user)
|
145
|
+
|
146
|
+
assert_nil current_user
|
147
|
+
assert_redirected_to root_path
|
148
|
+
assert_not_nil flash[:notice]
|
149
|
+
end
|
150
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class FriendlyRedirectsTest < ActionDispatch::IntegrationTest
|
4
|
+
setup do
|
5
|
+
@confirmed_user = User.create!(email: "confirmed_user@example.com", password: "password", password_confirmation: "password", confirmed_at: Time.current)
|
6
|
+
end
|
7
|
+
|
8
|
+
test "redirect to requested url after sign in" do
|
9
|
+
get account_path
|
10
|
+
|
11
|
+
assert_redirected_to login_path
|
12
|
+
login(@confirmed_user)
|
13
|
+
|
14
|
+
assert_redirected_to account_path
|
15
|
+
end
|
16
|
+
|
17
|
+
test "redirects to root path after sign in" do
|
18
|
+
get login_path
|
19
|
+
login(@confirmed_user)
|
20
|
+
|
21
|
+
assert_redirected_to root_path
|
22
|
+
end
|
23
|
+
end
|
data/lib/generators/rails_mvp_authentication/templates/test/integration/user_interface_test.rb.tt
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class UserInterfaceTest < ActionDispatch::IntegrationTest
|
4
|
+
setup do
|
5
|
+
@confirmed_user = User.create!(email: "confirmed_user@example.com", password: "password", password_confirmation: "password", confirmed_at: Time.current)
|
6
|
+
end
|
7
|
+
|
8
|
+
test "should render active sessions on account page" do
|
9
|
+
login @confirmed_user
|
10
|
+
@confirmed_user.active_sessions.last.update!(user_agent: "Mozilla", ip_address: "123.457.789")
|
11
|
+
|
12
|
+
get account_path
|
13
|
+
|
14
|
+
assert_match "Mozilla", @response.body
|
15
|
+
assert_match "123.457.789", @response.body
|
16
|
+
end
|
17
|
+
|
18
|
+
test "should render buttons to delete specific active sessions" do
|
19
|
+
login @confirmed_user
|
20
|
+
|
21
|
+
get account_path
|
22
|
+
|
23
|
+
assert_select "input[type='submit']" do
|
24
|
+
assert_select "[value=?]", "Log out of all other sessions"
|
25
|
+
end
|
26
|
+
assert_match destroy_all_active_sessions_path, @response.body
|
27
|
+
|
28
|
+
assert_select "table" do
|
29
|
+
assert_select "input[type='submit']" do
|
30
|
+
assert_select "[value=?]", "Sign Out"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
assert_match active_session_path(@confirmed_user.active_sessions.last), @response.body
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# Preview all emails at http://localhost:3000/rails/mailers/user_mailer
|
2
|
+
class UserMailerPreview < ActionMailer::Preview
|
3
|
+
# Preview this email at http://localhost:3000/rails/mailers/user_mailer/confirmation
|
4
|
+
def confirmation
|
5
|
+
@unconfirmed_user = User.find_by(email: "unconfirmed_user@example.com") || User.create!(email: "unconfirmed_user@example.com", password: "password", password_confirmation: "password")
|
6
|
+
@unconfirmed_user.update!(confirmed_at: nil)
|
7
|
+
confirmation_token = @unconfirmed_user.generate_confirmation_token
|
8
|
+
UserMailer.confirmation(@unconfirmed_user, confirmation_token)
|
9
|
+
end
|
10
|
+
|
11
|
+
# Preview this email at http://localhost:3000/rails/mailers/user_mailer/password_reset
|
12
|
+
def password_reset
|
13
|
+
@password_reset_user = User.find_by(email: "password_reset_user@example.com") || User.create!(email: "password_reset_user@example.com", password: "password", password_confirmation: "password", confirmed_at: Time.current)
|
14
|
+
password_reset_token = @password_reset_user.generate_password_reset_token
|
15
|
+
UserMailer.password_reset(@password_reset_user, password_reset_token)
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class UserMailerTest < ActionMailer::TestCase
|
4
|
+
setup do
|
5
|
+
@user = User.create!(email: "some_unique_email@example.com", password: "password", password_confirmation: "password")
|
6
|
+
end
|
7
|
+
|
8
|
+
test "confirmation" do
|
9
|
+
confirmation_token = @user.generate_confirmation_token
|
10
|
+
mail = UserMailer.confirmation(@user, confirmation_token)
|
11
|
+
assert_equal "Confirmation Instructions", mail.subject
|
12
|
+
assert_equal [@user.email], mail.to
|
13
|
+
assert_equal [User::MAILER_FROM_EMAIL], mail.from
|
14
|
+
assert_match confirmation_token, mail.body.encoded
|
15
|
+
end
|
16
|
+
|
17
|
+
test "password_reset" do
|
18
|
+
password_reset_token = @user.generate_password_reset_token
|
19
|
+
mail = UserMailer.password_reset(@user, password_reset_token)
|
20
|
+
assert_equal "Password Reset Instructions", mail.subject
|
21
|
+
assert_equal [@user.email], mail.to
|
22
|
+
assert_equal [User::MAILER_FROM_EMAIL], mail.from
|
23
|
+
assert_match password_reset_token, mail.body.encoded
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class ActiveSessionTest < ActiveSupport::TestCase
|
4
|
+
setup do
|
5
|
+
@user = User.new(email: "unique_email@example.com", password: "password", password_confirmation: "password")
|
6
|
+
@active_session = @user.active_sessions.build
|
7
|
+
end
|
8
|
+
|
9
|
+
test "should be valid" do
|
10
|
+
assert @active_session.valid?
|
11
|
+
end
|
12
|
+
|
13
|
+
test "should have a user" do
|
14
|
+
@active_session.user = nil
|
15
|
+
|
16
|
+
assert_not @active_session.valid?
|
17
|
+
end
|
18
|
+
end
|