diff options
author | Peter Leitzen <pleitzen@gitlab.com> | 2019-01-07 21:46:34 +0300 |
---|---|---|
committer | Peter Leitzen <pleitzen@gitlab.com> | 2019-01-07 21:46:34 +0300 |
commit | 6710c87434e6d2508dc6b2553594258e77d23723 (patch) | |
tree | 50cb2758d6038831dfa2b53782e24b4aac6b6cea /spec/controllers | |
parent | 191c20d71447dca1a516b27c01a152a43cf8be69 (diff) |
Implement error tracking configuration
Re-use operations controller which already handles tracing settings.
Diffstat (limited to 'spec/controllers')
-rw-r--r-- | spec/controllers/projects/settings/operations_controller_spec.rb | 168 |
1 files changed, 157 insertions, 11 deletions
diff --git a/spec/controllers/projects/settings/operations_controller_spec.rb b/spec/controllers/projects/settings/operations_controller_spec.rb index fbb26de76d1..810f5bb64ba 100644 --- a/spec/controllers/projects/settings/operations_controller_spec.rb +++ b/spec/controllers/projects/settings/operations_controller_spec.rb @@ -11,25 +11,171 @@ describe Projects::Settings::OperationsController do project.add_maintainer(user) end - describe 'GET #show' do - it 'returns 404' do - get :show, params: project_params(project) + context 'error tracking' do + describe 'GET #show' do + it 'renders show template' do + get :show, params: project_params(project) - expect(response).to have_gitlab_http_status(:not_found) + expect(response).to have_gitlab_http_status(:ok) + expect(response).to render_template(:show) + end + + context 'with existing setting' do + let!(:error_tracking_setting) do + create(:project_error_tracking_setting, project: project) + end + + it 'loads existing setting' do + get :show, params: project_params(project) + + expect(controller.helpers.error_tracking_setting) + .to eq(error_tracking_setting) + end + end + + context 'without an existing setting' do + it 'builds a new setting' do + get :show, params: project_params(project) + + expect(controller.helpers.error_tracking_setting).to be_new_record + end + end + + context 'with feature flag disabled' do + before do + stub_feature_flags(error_tracking: false) + end + + it 'renders 404' do + get :show, params: project_params(project) + + expect(response).to have_gitlab_http_status(:not_found) + end + end + + context 'with insufficient permissions' do + before do + project.add_reporter(user) + end + + it 'renders 404' do + get :show, params: project_params(project) + + expect(response).to have_gitlab_http_status(:not_found) + end + end + + context 'as an anonymous user' do + before do + sign_out(user) + end + + it 'redirects to signup page' do + get :show, params: project_params(project) + + expect(response).to redirect_to(new_user_session_path) + end + end + end + + describe 'PATCH #update' do + let(:operations_update_service) { spy(:operations_update_service) } + let(:operations_url) { project_settings_operations_url(project) } + + let(:error_tracking_params) do + { + error_tracking_setting_attributes: { + enabled: '1', + api_url: 'http://url', + token: 'token' + } + } + end + let(:error_tracking_permitted) do + ActionController::Parameters.new(error_tracking_params).permit! + end + + context 'when update succeeds' do + before do + stub_operations_update_service_returning(status: :success) + end + + it 'shows a notice' do + patch :update, params: project_params(project, error_tracking_params) + + expect(response).to redirect_to(operations_url) + expect(flash[:notice]).to eq _('Your changes have been saved') + end + end + + context 'when update fails' do + before do + stub_operations_update_service_returning(status: :error) + end + + it 'renders show page' do + patch :update, params: project_params(project, error_tracking_params) + + expect(response).to have_gitlab_http_status(:ok) + expect(response).to render_template(:show) + end + end + + context 'with feature flag disabled' do + before do + stub_feature_flags(error_tracking: false) + end + + it 'renders 404' do + patch :update, params: project_params(project) + + expect(response).to have_gitlab_http_status(:not_found) + end + end + + context 'with insufficient permissions' do + before do + project.add_reporter(user) + end + + it 'renders 404' do + patch :update, params: project_params(project) + + expect(response).to have_gitlab_http_status(:not_found) + end + end + + context 'as an anonymous user' do + before do + sign_out(user) + end + + it 'redirects to signup page' do + patch :update, params: project_params(project) + + expect(response).to redirect_to(new_user_session_path) + end + end end - end - describe 'PATCH #update' do - it 'returns 404' do - patch :update, params: project_params(project) + private - expect(response).to have_gitlab_http_status(:not_found) + def stub_operations_update_service_returning(return_value = {}) + expect(::Projects::Operations::UpdateService) + .to receive(:new).with(project, user, error_tracking_permitted) + .and_return(operations_update_service) + expect(operations_update_service).to receive(:execute) + .and_return(return_value) end end private - def project_params(project) - { namespace_id: project.namespace, project_id: project } + def project_params(project, params = {}) + { + namespace_id: project.namespace, + project_id: project, + project: params + } end end |