diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-15 03:08:43 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-15 03:08:43 +0300 |
commit | 45ccc5610c9afec64de3c4894789896ee2d5c48d (patch) | |
tree | 544b5e40167eca28e075cec24d4736283620b88e /spec/controllers | |
parent | 6b4c082fc8f266aa796595103e6c5f6ddb199280 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/controllers')
-rw-r--r-- | spec/controllers/groups/imports_controller_spec.rb | 85 | ||||
-rw-r--r-- | spec/controllers/groups_controller_spec.rb | 14 | ||||
-rw-r--r-- | spec/controllers/projects/branches_controller_spec.rb | 76 |
3 files changed, 174 insertions, 1 deletions
diff --git a/spec/controllers/groups/imports_controller_spec.rb b/spec/controllers/groups/imports_controller_spec.rb new file mode 100644 index 00000000000..eb43a62b75b --- /dev/null +++ b/spec/controllers/groups/imports_controller_spec.rb @@ -0,0 +1,85 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Groups::ImportsController do + describe 'GET #show' do + let_it_be(:user) { create(:user) } + let_it_be(:group) { create(:group, :private) } + + context 'when the user has permission to view the group' do + before do + sign_in(user) + group.add_maintainer(user) + end + + context 'when the import is in progress' do + before do + create(:group_import_state, group: group) + end + + it 'renders the show template' do + get :show, params: { group_id: group } + + expect(response).to render_template :show + end + + it 'sets the flash notice' do + get :show, params: { group_id: group, continue: { to: '/', notice_now: 'In progress' } } + + expect(flash.now[:notice]).to eq 'In progress' + end + end + + context 'when the import has failed' do + before do + create(:group_import_state, :failed, group: group) + end + + it 'redirects to the new group path' do + get :show, params: { group_id: group } + + expect(response).to redirect_to new_group_path(group) + end + + it 'sets a flash error' do + get :show, params: { group_id: group } + + expect(flash[:alert]).to eq 'Failed to import group.' + end + end + + context 'when the import has finished' do + before do + create(:group_import_state, :finished, group: group) + end + + it 'redirects to the group page' do + get :show, params: { group_id: group } + + expect(response).to redirect_to group_path(group) + end + end + + context 'when there is no import state' do + it 'redirects to the group page' do + get :show, params: { group_id: group } + + expect(response).to redirect_to group_path(group) + end + end + end + + context 'when the user does not have permission to view the group' do + before do + sign_in(user) + end + + it 'returns a 404' do + get :show, params: { group_id: group } + + expect(response).to have_gitlab_http_status :not_found + end + end + end +end diff --git a/spec/controllers/groups_controller_spec.rb b/spec/controllers/groups_controller_spec.rb index e2e5e07fba0..dce7105c073 100644 --- a/spec/controllers/groups_controller_spec.rb +++ b/spec/controllers/groups_controller_spec.rb @@ -66,7 +66,19 @@ RSpec.describe GroupsController do subject { get :show, params: { id: group.to_param }, format: format } - it_behaves_like 'details view' + context 'when the group is not importing' do + it_behaves_like 'details view' + end + + context 'when the group is importing' do + before do + create(:group_import_state, group: group) + end + + it 'redirects to the import status page' do + expect(subject).to redirect_to group_import_path(group) + end + end end describe 'GET #details' do diff --git a/spec/controllers/projects/branches_controller_spec.rb b/spec/controllers/projects/branches_controller_spec.rb index 02a8f525b4d..625fc5bddda 100644 --- a/spec/controllers/projects/branches_controller_spec.rb +++ b/spec/controllers/projects/branches_controller_spec.rb @@ -486,6 +486,82 @@ RSpec.describe Projects::BranchesController do end end + context 'when a branch has multiple pipelines' do + it 'chooses the latest to determine status' do + sha = project.repository.create_file(developer, generate(:branch), 'content', message: 'message', branch_name: 'master') + create(:ci_pipeline, + project: project, + user: developer, + ref: "master", + sha: sha, + status: :running, + created_at: 6.months.ago) + create(:ci_pipeline, + project: project, + user: developer, + ref: "master", + sha: sha, + status: :success, + created_at: 2.months.ago) + + get :index, + format: :html, + params: { + namespace_id: project.namespace, + project_id: project, + state: 'all' + } + + expect(controller.instance_variable_get(:@branch_pipeline_statuses)["master"].group).to eq("success") + end + end + + context 'when multiple branches exist' do + it 'all relevant commit statuses are received' do + master_sha = project.repository.create_file(developer, generate(:branch), 'content', message: 'message', branch_name: 'master') + create(:ci_pipeline, + project: project, + user: developer, + ref: "master", + sha: master_sha, + status: :running, + created_at: 6.months.ago) + test_sha = project.repository.create_file(developer, generate(:branch), 'content', message: 'message', branch_name: 'test') + create(:ci_pipeline, + project: project, + user: developer, + ref: "test", + sha: test_sha, + status: :success, + created_at: 2.months.ago) + + get :index, + format: :html, + params: { + namespace_id: project.namespace, + project_id: project, + state: 'all' + } + + expect(controller.instance_variable_get(:@branch_pipeline_statuses)["master"].group).to eq("running") + expect(controller.instance_variable_get(:@branch_pipeline_statuses)["test"].group).to eq("success") + end + end + + context 'when a branch contains no pipelines' do + it 'no commit statuses are received' do + get :index, + format: :html, + params: { + namespace_id: project.namespace, + project_id: project, + state: 'all' + } + + expect(controller.instance_variable_get(:@branch_pipeline_statuses)).to be_blank + end + end + # We need :request_store because Gitaly only counts the queries whenever # `RequestStore.active?` in GitalyClient.enforce_gitaly_request_limits # And the main goal of this test is making sure TooManyInvocationsError |