1
1
require "test_helper"
2
2
3
- class UsersSignupTest < ActionDispatch ::IntegrationTest
3
+ class UsersSignup < ActionDispatch ::IntegrationTest
4
4
5
5
def setup
6
6
ActionMailer ::Base . deliveries . clear
7
7
end
8
+ end
9
+
10
+ class UsersSignupTest < UsersSignup
8
11
9
12
test "invalid signup information" do
10
- get signup_path
11
13
assert_no_difference 'User.count' do
12
14
post users_path , params : { user : { name : "" ,
13
15
email : "user@invalid" ,
@@ -21,28 +23,49 @@ def setup
21
23
end
22
24
23
25
test "valid signup information with account activation" do
24
- get signup_path
25
26
assert_difference 'User.count' , 1 do
26
27
post users_path , params : { user : { name : "Example User" ,
27
28
28
29
password : "password" ,
29
30
password_confirmation : "password" } }
30
31
end
31
32
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 )
36
53
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 )
39
58
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' )
42
63
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?
46
69
follow_redirect!
47
70
assert_template 'users/show'
48
71
assert is_logged_in?
0 commit comments