2019-04-15 06:17:05 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-04-26 07:28:24 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Users::TermsController do
|
2018-05-25 19:17:57 -04:00
|
|
|
include TermsHelper
|
2018-04-26 07:28:24 -04:00
|
|
|
let(:user) { create(:user) }
|
2018-04-27 08:56:50 -04:00
|
|
|
let(:term) { create(:term) }
|
2018-04-26 07:28:24 -04:00
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in user
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #index' do
|
|
|
|
it 'redirects when no terms exist' do
|
|
|
|
get :index
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:redirect)
|
|
|
|
end
|
|
|
|
|
2018-05-25 19:17:57 -04:00
|
|
|
context 'when terms exist' do
|
|
|
|
before do
|
|
|
|
stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false')
|
|
|
|
term
|
|
|
|
end
|
2018-04-26 07:28:24 -04:00
|
|
|
|
2018-05-25 19:17:57 -04:00
|
|
|
it 'shows terms when they exist' do
|
|
|
|
get :index
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:success)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows a message when the user already accepted the terms' do
|
|
|
|
accept_terms(user)
|
|
|
|
|
|
|
|
get :index
|
|
|
|
|
|
|
|
expect(controller).to set_flash.now[:notice].to(/already accepted/)
|
|
|
|
end
|
2018-04-26 07:28:24 -04:00
|
|
|
end
|
|
|
|
end
|
2018-04-27 08:56:50 -04:00
|
|
|
|
|
|
|
describe 'POST #accept' do
|
|
|
|
it 'saves that the user accepted the terms' do
|
2018-12-17 17:52:17 -05:00
|
|
|
post :accept, params: { id: term.id }
|
2018-04-27 08:56:50 -04:00
|
|
|
|
|
|
|
agreement = user.term_agreements.find_by(term: term)
|
|
|
|
|
|
|
|
expect(agreement.accepted).to eq(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'redirects to a path when specified' do
|
2018-12-17 17:52:17 -05:00
|
|
|
post :accept, params: { id: term.id, redirect: groups_path }
|
2018-04-27 08:56:50 -04:00
|
|
|
|
|
|
|
expect(response).to redirect_to(groups_path)
|
|
|
|
end
|
2018-04-27 10:50:33 -04:00
|
|
|
|
|
|
|
it 'redirects to the referer when no redirect specified' do
|
|
|
|
request.env["HTTP_REFERER"] = groups_url
|
|
|
|
|
2018-12-17 17:52:17 -05:00
|
|
|
post :accept, params: { id: term.id }
|
2018-04-27 10:50:33 -04:00
|
|
|
|
|
|
|
expect(response).to redirect_to(groups_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'redirecting to another domain' do
|
|
|
|
it 'is prevented when passing a redirect param' do
|
2018-12-17 17:52:17 -05:00
|
|
|
post :accept, params: { id: term.id, redirect: '//example.com/random/path' }
|
2018-04-27 10:50:33 -04:00
|
|
|
|
|
|
|
expect(response).to redirect_to(root_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is prevented when redirecting to the referer' do
|
|
|
|
request.env["HTTP_REFERER"] = 'http://example.com/and/a/path'
|
|
|
|
|
2018-12-17 17:52:17 -05:00
|
|
|
post :accept, params: { id: term.id }
|
2018-04-27 10:50:33 -04:00
|
|
|
|
|
|
|
expect(response).to redirect_to(root_path)
|
|
|
|
end
|
|
|
|
end
|
2018-04-27 08:56:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'POST #decline' do
|
|
|
|
it 'stores that the user declined the terms' do
|
2018-12-17 17:52:17 -05:00
|
|
|
post :decline, params: { id: term.id }
|
2018-04-27 08:56:50 -04:00
|
|
|
|
|
|
|
agreement = user.term_agreements.find_by(term: term)
|
|
|
|
|
|
|
|
expect(agreement.accepted).to eq(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'signs out the user' do
|
2018-12-17 17:52:17 -05:00
|
|
|
post :decline, params: { id: term.id }
|
2018-04-27 08:56:50 -04:00
|
|
|
|
|
|
|
expect(response).to redirect_to(root_path)
|
|
|
|
expect(assigns(:current_user)).to be_nil
|
|
|
|
end
|
|
|
|
end
|
2018-04-26 07:28:24 -04:00
|
|
|
end
|