11require "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" ,
27282829 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