@@ -23,6 +23,7 @@ def token_and_client_config_from(body)
2323 @new_user . send_confirmation_instructions ( redirect_url : @redirect_url )
2424 mail = ActionMailer ::Base . deliveries . last
2525 @token , @client_config = token_and_client_config_from ( mail . body )
26+ @token_params = %w[ access-token client client_id config expiry token uid ]
2627 end
2728
2829 test 'should generate raw token' do
@@ -38,32 +39,52 @@ def token_and_client_config_from(body)
3839 end
3940
4041 describe 'success' do
41- before do
42- get :show ,
43- params : { confirmation_token : @token ,
44- redirect_url : @redirect_url } ,
45- xhr : true
46- @resource = assigns ( :resource )
47- end
42+ describe 'when authenticated' do
43+ before do
44+ sign_in ( @new_user )
45+ get :show ,
46+ params : { confirmation_token : @token ,
47+ redirect_url : @redirect_url } ,
48+ xhr : true
49+ @resource = assigns ( :resource )
50+ end
4851
49- test 'user should now be confirmed' do
50- assert @resource . confirmed?
51- end
52+ test 'user should now be confirmed' do
53+ assert @resource . confirmed?
54+ end
5255
53- test 'should redirect to success url' do
54- assert_redirected_to ( /^#{ @redirect_url } / )
55- end
56+ test 'should redirect to success url' do
57+ assert_redirected_to ( /^#{ @redirect_url } / )
58+ end
5659
57- test 'the sign_in_count should be 1' do
58- assert @resource . sign_in_count == 1
60+ test 'redirect url includes token params' do
61+ assert @token_params . all? { |param | response . body . include? ( param ) }
62+ assert response . body . include? ( 'account_confirmation_success' )
63+ end
5964 end
6065
61- test 'User shoud have the signed in info filled' do
62- assert @resource . current_sign_in_at?
63- end
66+ describe 'when unauthenticated' do
67+ before do
68+ sign_out ( @new_user )
69+ get :show ,
70+ params : { confirmation_token : @token ,
71+ redirect_url : @redirect_url } ,
72+ xhr : true
73+ @resource = assigns ( :resource )
74+ end
6475
65- test 'User shoud have the Last checkin filled' do
66- assert @resource . last_sign_in_at?
76+ test 'user should now be confirmed' do
77+ assert @resource . confirmed?
78+ end
79+
80+ test 'should redirect to success url' do
81+ assert_redirected_to ( /^#{ @redirect_url } / )
82+ end
83+
84+ test 'redirect url does not include token params' do
85+ refute @token_params . any? { |param | response . body . include? ( param ) }
86+ assert response . body . include? ( 'account_confirmation_success' )
87+ end
6788 end
6889 end
6990
0 commit comments