diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-26 09:08:40 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-26 09:08:40 +0300 |
commit | 116d4e56e83a1f408afe710ce070e699ba206475 (patch) | |
tree | cc62d3820d9bfa199061edfdef3a2f4bda140507 /spec/controllers | |
parent | dddde902acfa6acfb11583c61faa67cc7c8d11b6 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/controllers')
3 files changed, 162 insertions, 9 deletions
diff --git a/spec/controllers/admin/integrations_controller_spec.rb b/spec/controllers/admin/integrations_controller_spec.rb index 0641f64b0e3..50748918893 100644 --- a/spec/controllers/admin/integrations_controller_spec.rb +++ b/spec/controllers/admin/integrations_controller_spec.rb @@ -3,8 +3,8 @@ require 'spec_helper' describe Admin::IntegrationsController do + let_it_be(:project) { create(:project) } let(:admin) { create(:admin) } - let!(:project) { create(:project) } before do sign_in(admin) @@ -13,7 +13,7 @@ describe Admin::IntegrationsController do describe '#edit' do context 'when instance_level_integrations not enabled' do it 'returns not_found' do - allow(Feature).to receive(:enabled?).with(:instance_level_integrations) { false } + stub_feature_flags(instance_level_integrations: false) get :edit, params: { id: Service.available_services_names.sample } diff --git a/spec/controllers/groups/settings/integrations_controller_spec.rb b/spec/controllers/groups/settings/integrations_controller_spec.rb new file mode 100644 index 00000000000..bbf215a4bb9 --- /dev/null +++ b/spec/controllers/groups/settings/integrations_controller_spec.rb @@ -0,0 +1,107 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Groups::Settings::IntegrationsController do + let_it_be(:project) { create(:project) } + let(:user) { create(:user) } + let(:group) { create(:group) } + + before do + sign_in(user) + end + + describe '#edit' do + context 'when group_level_integrations not enabled' do + it 'returns not_found' do + stub_feature_flags(group_level_integrations: { enabled: false, thing: group }) + + get :edit, params: { group_id: group, id: Service.available_services_names.sample } + + expect(response).to have_gitlab_http_status(:not_found) + end + end + + context 'when user is not owner' do + it 'renders not_found' do + get :edit, params: { group_id: group, id: Service.available_services_names.sample } + + expect(response).to have_gitlab_http_status(:not_found) + end + end + + context 'when user is owner' do + before do + group.add_owner(user) + end + + Service.available_services_names.each do |integration_name| + context "#{integration_name}" do + it 'successfully displays the template' do + get :edit, params: { group_id: group, id: integration_name } + + expect(response).to have_gitlab_http_status(:ok) + expect(response).to render_template(:edit) + end + end + end + end + end + + describe '#update' do + let(:integration) { create(:jira_service, project: project) } + + before do + group.add_owner(user) + + put :update, params: { group_id: group, id: integration.class.to_param, service: { url: url } } + end + + context 'valid params' do + let(:url) { 'https://jira.gitlab-example.com' } + + it 'updates the integration' do + expect(response).to have_gitlab_http_status(:found) + expect(integration.reload.url).to eq(url) + end + end + + context 'invalid params' do + let(:url) { 'ftp://jira.localhost' } + + it 'does not update the integration' do + expect(response).to have_gitlab_http_status(:ok) + expect(response).to render_template(:edit) + expect(integration.reload.url).not_to eq(url) + end + end + end + + describe '#test' do + context 'testable' do + let(:integration) { create(:jira_service, project: project) } + + before do + group.add_owner(user) + end + + it 'returns ok' do + allow_any_instance_of(integration.class).to receive(:test) { { success: true } } + + put :test, params: { group_id: group, id: integration.class.to_param } + + expect(response).to have_gitlab_http_status(:ok) + end + end + + context 'not testable' do + let(:integration) { create(:alerts_service, project: project) } + + it 'returns not found' do + put :test, params: { group_id: group, id: integration.class.to_param } + + expect(response).to have_gitlab_http_status(:not_found) + end + end + end +end diff --git a/spec/controllers/projects/pipelines_controller_spec.rb b/spec/controllers/projects/pipelines_controller_spec.rb index a929eaeba3f..74931fcdeb2 100644 --- a/spec/controllers/projects/pipelines_controller_spec.rb +++ b/spec/controllers/projects/pipelines_controller_spec.rb @@ -705,13 +705,45 @@ describe Projects::PipelinesController do end describe 'GET test_report.json' do - subject(:get_test_report_json) do - get :test_report, params: { - namespace_id: project.namespace, - project_id: project, - id: pipeline.id - }, - format: :json + let(:pipeline) { create(:ci_pipeline, project: project) } + + context 'with attachments' do + let(:blob) do + <<~EOF + <testsuites> + <testsuite> + <testcase classname='Calculator' name='sumTest1' time='0.01'> + <failure>Some failure</failure> + <system-out>[[ATTACHMENT|some/path.png]]</system-out> + </testcase> + </testsuite> + </testsuites> + EOF + end + + before do + allow_any_instance_of(Ci::JobArtifact).to receive(:each_blob).and_yield(blob) + end + + it 'does not have N+1 problem with attachments' do + get_test_report_json + + create(:ci_build, name: 'rspec', pipeline: pipeline).tap do |build| + create(:ci_job_artifact, :junit, job: build) + end + + clear_controller_memoization + + control_count = ActiveRecord::QueryRecorder.new { get_test_report_json }.count + + create(:ci_build, name: 'karma', pipeline: pipeline).tap do |build| + create(:ci_job_artifact, :junit, job: build) + end + + clear_controller_memoization + + expect { get_test_report_json }.not_to exceed_query_limit(control_count) + end end context 'when feature is enabled' do @@ -772,6 +804,20 @@ describe Projects::PipelinesController do expect(response.body).to be_empty end end + + def get_test_report_json + get :test_report, params: { + namespace_id: project.namespace, + project_id: project, + id: pipeline.id + }, + format: :json + end + + def clear_controller_memoization + controller.clear_memoization(:pipeline_test_report) + controller.instance_variable_set(:@pipeline, nil) + end end describe 'GET test_report_count.json' do |