Skip to content

Commit d16b3e9

Browse files
committed
Include broken-up tests
1 parent 4136d18 commit d16b3e9

File tree

2 files changed

+83
-20
lines changed

2 files changed

+83
-20
lines changed

test/integration/users_login_test.rb

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
require "test_helper"
22

3-
class UsersLoginTest < ActionDispatch::IntegrationTest
3+
class UsersLogin < ActionDispatch::IntegrationTest
44

55
def setup
66
@user = users(:michael)
77
end
8+
end
89

9-
test "login with valid email/invalid password" do
10+
class InvalidPasswordTest < UsersLogin
11+
12+
test "login path" do
1013
get login_path
1114
assert_template 'sessions/new'
15+
end
16+
17+
test "login with valid email/invalid password" do
1218
post login_path, params: { session: { email: @user.email,
1319
password: "invalid" } }
1420
assert_not is_logged_in?
@@ -18,30 +24,64 @@ def setup
1824
get root_path
1925
assert flash.empty?
2026
end
27+
end
2128

22-
test "login with valid information followed by logout" do
23-
get login_path
29+
class ValidLogin < UsersLogin
30+
31+
def setup
32+
super
2433
post login_path, params: { session: { email: @user.email,
2534
password: 'password' } }
35+
end
36+
end
37+
38+
class ValidLoginTest < ValidLogin
39+
40+
test "valid login" do
2641
assert is_logged_in?
2742
assert_redirected_to @user
43+
end
44+
45+
test "redirect after login" do
2846
follow_redirect!
2947
assert_template 'users/show'
3048
assert_select "a[href=?]", login_path, count: 0
3149
assert_select "a[href=?]", logout_path
3250
assert_select "a[href=?]", user_path(@user)
51+
end
52+
end
53+
54+
class Logout < ValidLogin
55+
56+
def setup
57+
super
3358
delete logout_path
59+
end
60+
end
61+
62+
class LogoutTest < Logout
63+
64+
test "successful logout" do
3465
assert_not is_logged_in?
3566
assert_response :see_other
3667
assert_redirected_to root_url
37-
# Simulate a user clicking logout in a second window.
38-
delete logout_path
68+
end
69+
70+
test "redirect after logout" do
3971
follow_redirect!
4072
assert_select "a[href=?]", login_path
4173
assert_select "a[href=?]", logout_path, count: 0
4274
assert_select "a[href=?]", user_path(@user), count: 0
4375
end
4476

77+
test "should still work after logout in second window" do
78+
delete logout_path
79+
assert_redirected_to root_url
80+
end
81+
end
82+
83+
class RememberingTest < UsersLogin
84+
4585
test "login with remembering" do
4686
log_in_as(@user, remember_me: '1')
4787
assert_not cookies[:remember_token].blank?

test/integration/users_signup_test.rb

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
require "test_helper"
22

3-
class UsersSignupTest < ActionDispatch::IntegrationTest
3+
class UsersSignup < ActionDispatch::IntegrationTest
44

55
def setup
66
ActionMailer::Base.deliveries.clear
77
end
8+
end
9+
10+
class UsersSignupTest < UsersSignup
811

912
test "invalid signup information" do
10-
get signup_path
1113
assert_no_difference 'User.count' do
1214
post users_path, params: { user: { name: "",
1315
email: "user@invalid",
@@ -21,28 +23,49 @@ def setup
2123
end
2224

2325
test "valid signup information with account activation" do
24-
get signup_path
2526
assert_difference 'User.count', 1 do
2627
post users_path, params: { user: { name: "Example User",
2728
2829
password: "password",
2930
password_confirmation: "password" } }
3031
end
3132
assert_equal 1, ActionMailer::Base.deliveries.size
32-
user = assigns(:user)
33-
assert_not user.activated?
34-
# Try to log in before activation.
35-
log_in_as(user)
33+
end
34+
end
35+
36+
class AccountActivationTest < UsersSignup
37+
38+
def setup
39+
super
40+
post users_path, params: { user: { name: "Example User",
41+
42+
password: "password",
43+
password_confirmation: "password" } }
44+
@user = assigns(:user)
45+
end
46+
47+
test "should not be activated" do
48+
assert_not @user.activated?
49+
end
50+
51+
test "should not be able to log in before account activation" do
52+
log_in_as(@user)
3653
assert_not is_logged_in?
37-
# Invalid activation token
38-
get edit_account_activation_path("invalid token", email: user.email)
54+
end
55+
56+
test "should not be able to log in with invalid activation token" do
57+
get edit_account_activation_path("invalid token", email: @user.email)
3958
assert_not is_logged_in?
40-
# Valid token, wrong email
41-
get edit_account_activation_path(user.activation_token, email: 'wrong')
59+
end
60+
61+
test "should not be able to log in with invalid email" do
62+
get edit_account_activation_path(@user.activation_token, email: 'wrong')
4263
assert_not is_logged_in?
43-
# Valid activation token
44-
get edit_account_activation_path(user.activation_token, email: user.email)
45-
assert user.reload.activated?
64+
end
65+
66+
test "should log in successfully with valid activation token and email" do
67+
get edit_account_activation_path(@user.activation_token, email: @user.email)
68+
assert @user.reload.activated?
4669
follow_redirect!
4770
assert_template 'users/show'
4871
assert is_logged_in?

0 commit comments

Comments
 (0)