From 10aa55a770c2985c22c92d17b8a7ea90b0a09085 Mon Sep 17 00:00:00 2001 From: Bob Van Landuyt Date: Fri, 27 Apr 2018 14:56:50 +0200 Subject: Allow a user to accept/decline terms When a user accepts, we store this in the agreements to keep track of which terms they accepted. We also update the flag on the user. --- spec/controllers/users/terms_controller_spec.rb | 36 ++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'spec/controllers/users') diff --git a/spec/controllers/users/terms_controller_spec.rb b/spec/controllers/users/terms_controller_spec.rb index 74d17748093..50e818a4520 100644 --- a/spec/controllers/users/terms_controller_spec.rb +++ b/spec/controllers/users/terms_controller_spec.rb @@ -2,6 +2,7 @@ require 'spec_helper' describe Users::TermsController do let(:user) { create(:user) } + let(:term) { create(:term) } before do sign_in user @@ -15,9 +16,42 @@ describe Users::TermsController do end it 'shows terms when they exist' do - create(:term) + term expect(response).to have_gitlab_http_status(:success) end end + + describe 'POST #accept' do + it 'saves that the user accepted the terms' do + post :accept, id: term.id + + agreement = user.term_agreements.find_by(term: term) + + expect(agreement.accepted).to eq(true) + end + + it 'redirects to a path when specified' do + post :accept, id: term.id, redirect: groups_path + + expect(response).to redirect_to(groups_path) + end + end + + describe 'POST #decline' do + it 'stores that the user declined the terms' do + post :decline, id: term.id + + agreement = user.term_agreements.find_by(term: term) + + expect(agreement.accepted).to eq(false) + end + + it 'signs out the user' do + post :decline, id: term.id + + expect(response).to redirect_to(root_path) + expect(assigns(:current_user)).to be_nil + end + end end -- cgit v1.2.3