Skip to content

Commit 38b60bb

Browse files
committed
Merge branch 'following-users'
2 parents 37ad1eb + 5f83206 commit 38b60bb

File tree

3 files changed

+66
-29
lines changed

3 files changed

+66
-29
lines changed
Lines changed: 63 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,98 @@
11
require "test_helper"
22

3-
class PasswordResetsTest < ActionDispatch::IntegrationTest
3+
class PasswordResets < ActionDispatch::IntegrationTest
44

55
def setup
66
ActionMailer::Base.deliveries.clear
77
@user = users(:michael)
88
end
9+
end
910

10-
test "password resets" do
11+
class PasswordResetsTest < PasswordResets
12+
13+
test "password reset path" do
1114
get new_password_reset_path
1215
assert_template 'password_resets/new'
1316
assert_select 'input[name=?]', 'password_reset[email]'
14-
# Invalid email
17+
end
18+
19+
test "reset path with invalid email" do
1520
post password_resets_path, params: { password_reset: { email: "" } }
1621
assert_not flash.empty?
22+
assert_response :unprocessable_entity
1723
assert_template 'password_resets/new'
18-
# Valid email
24+
end
25+
end
26+
27+
class PasswordForm < PasswordResets
28+
29+
def setup
30+
super
1931
post password_resets_path,
2032
params: { password_reset: { email: @user.email } }
33+
@actual_user = assigns(:user)
34+
end
35+
end
36+
37+
class PasswordFormTest < PasswordForm
38+
39+
test "reset with valid email" do
2140
assert_not_equal @user.reset_digest, @user.reload.reset_digest
2241
assert_equal 1, ActionMailer::Base.deliveries.size
2342
assert_not flash.empty?
2443
assert_redirected_to root_url
25-
# Password reset form
26-
user = assigns(:user)
27-
# Wrong email
28-
get edit_password_reset_path(user.reset_token, email: "")
44+
end
45+
46+
test "reset with wrong email" do
47+
get edit_password_reset_path(@actual_user.reset_token, email: "")
2948
assert_redirected_to root_url
30-
# Inactive user
31-
user.toggle!(:activated)
32-
get edit_password_reset_path(user.reset_token, email: user.email)
49+
end
50+
51+
test "reset with inactive user" do
52+
@actual_user.toggle!(:activated)
53+
get edit_password_reset_path(@actual_user.reset_token,
54+
email: @actual_user.email)
3355
assert_redirected_to root_url
34-
user.toggle!(:activated)
35-
# Right email, wrong token
36-
get edit_password_reset_path('wrong token', email: user.email)
56+
end
57+
58+
test "reset with right email but wrong token" do
59+
get edit_password_reset_path('wrong token', email: @actual_user.email)
3760
assert_redirected_to root_url
38-
# Right email, right token
39-
get edit_password_reset_path(user.reset_token, email: user.email)
61+
end
62+
63+
test "reset with right email and right token" do
64+
get edit_password_reset_path(@actual_user.reset_token,
65+
email: @actual_user.email)
4066
assert_template 'password_resets/edit'
41-
assert_select "input[name=email][type=hidden][value=?]", user.email
42-
# Invalid password & confirmation
43-
patch password_reset_path(user.reset_token),
44-
params: { email: user.email,
67+
assert_select "input[name=email][type=hidden][value=?]", @actual_user.email
68+
end
69+
end
70+
71+
class PasswordUpdateTest < PasswordForm
72+
73+
test "update with invalid password and confirmation" do
74+
patch password_reset_path(@actual_user.reset_token),
75+
params: { email: @actual_user.email,
4576
user: { password: "foobaz",
4677
password_confirmation: "barquux" } }
4778
assert_select 'div#error_explanation'
48-
# Empty password
49-
patch password_reset_path(user.reset_token),
50-
params: { email: user.email,
79+
end
80+
81+
test "update with empty password" do
82+
patch password_reset_path(@actual_user.reset_token),
83+
params: { email: @actual_user.email,
5184
user: { password: "",
5285
password_confirmation: "" } }
5386
assert_select 'div#error_explanation'
54-
# Valid password & confirmation
55-
patch password_reset_path(user.reset_token),
56-
params: { email: user.email,
87+
end
88+
89+
test "update with valid password and confirmation" do
90+
patch password_reset_path(@actual_user.reset_token),
91+
params: { email: @actual_user.email,
5792
user: { password: "foobaz",
5893
password_confirmation: "foobaz" } }
5994
assert is_logged_in?
6095
assert_not flash.empty?
61-
assert_redirected_to user
96+
assert_redirected_to @actual_user
6297
end
63-
end
98+
end

test/integration/users_login_test.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ def setup
1212
post login_path, params: { session: { email: @user.email,
1313
password: "invalid" } }
1414
assert_not is_logged_in?
15+
assert_response :unprocessable_entity
1516
assert_template 'sessions/new'
1617
assert_not flash.empty?
1718
get root_path
@@ -53,4 +54,4 @@ def setup
5354
log_in_as(@user, remember_me: '0')
5455
assert cookies[:remember_token].blank?
5556
end
56-
end
57+
end

test/integration/users_signup_test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def setup
1414
password: "foo",
1515
password_confirmation: "bar" } }
1616
end
17+
assert_response :unprocessable_entity
1718
assert_template 'users/new'
1819
assert_select 'div#error_explanation'
1920
assert_select 'div.field_with_errors'

0 commit comments

Comments
 (0)