diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-20 23:50:22 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-20 23:50:22 +0000 |
commit | 9dc93a4519d9d5d7be48ff274127136236a3adb3 (patch) | |
tree | 70467ae3692a0e35e5ea56bcb803eb512a10bedb /spec/controllers/projects | |
parent | 4b0f34b6d759d6299322b3a54453e930c6121ff0 (diff) | |
download | gitlab-ce-9dc93a4519d9d5d7be48ff274127136236a3adb3.tar.gz |
Add latest changes from gitlab-org/gitlab@13-11-stable-eev13.11.0-rc43
Diffstat (limited to 'spec/controllers/projects')
44 files changed, 454 insertions, 224 deletions
diff --git a/spec/controllers/projects/alerting/notifications_controller_spec.rb b/spec/controllers/projects/alerting/notifications_controller_spec.rb index 3656cfbcc30..fe0c4ce00bf 100644 --- a/spec/controllers/projects/alerting/notifications_controller_spec.rb +++ b/spec/controllers/projects/alerting/notifications_controller_spec.rb @@ -5,6 +5,7 @@ require 'spec_helper' RSpec.describe Projects::Alerting::NotificationsController do let_it_be(:project) { create(:project) } let_it_be(:environment) { create(:environment, project: project) } + let(:params) { project_params } describe 'POST #create' do @@ -68,6 +69,7 @@ RSpec.describe Projects::Alerting::NotificationsController do context 'with a corresponding integration' do context 'with integration parameters specified' do let_it_be_with_reload(:integration) { create(:alert_management_http_integration, project: project) } + let(:params) { project_params(endpoint_identifier: integration.endpoint_identifier, name: integration.name) } context 'the integration is active' do diff --git a/spec/controllers/projects/artifacts_controller_spec.rb b/spec/controllers/projects/artifacts_controller_spec.rb index 69ab9873b90..754b0ddfb94 100644 --- a/spec/controllers/projects/artifacts_controller_spec.rb +++ b/spec/controllers/projects/artifacts_controller_spec.rb @@ -448,7 +448,7 @@ RSpec.describe Projects::ArtifactsController do context 'with regular branch' do before do - pipeline.update(ref: 'master', + pipeline.update!(ref: 'master', sha: project.commit('master').sha) get :latest_succeeded, params: params_from_ref('master') @@ -459,7 +459,7 @@ RSpec.describe Projects::ArtifactsController do context 'with branch name containing slash' do before do - pipeline.update(ref: 'improve/awesome', + pipeline.update!(ref: 'improve/awesome', sha: project.commit('improve/awesome').sha) get :latest_succeeded, params: params_from_ref('improve/awesome') @@ -470,7 +470,7 @@ RSpec.describe Projects::ArtifactsController do context 'with branch name and path containing slashes' do before do - pipeline.update(ref: 'improve/awesome', + pipeline.update!(ref: 'improve/awesome', sha: project.commit('improve/awesome').sha) get :latest_succeeded, params: params_from_ref('improve/awesome', job.name, 'file/README.md') diff --git a/spec/controllers/projects/boards_controller_spec.rb b/spec/controllers/projects/boards_controller_spec.rb index cde3a8d4761..48a12a27911 100644 --- a/spec/controllers/projects/boards_controller_spec.rb +++ b/spec/controllers/projects/boards_controller_spec.rb @@ -22,6 +22,15 @@ RSpec.describe Projects::BoardsController do expect(assigns(:boards_endpoint)).to eq project_boards_path(project) end + it 'pushes swimlanes_buffered_rendering feature flag' do + allow(controller).to receive(:push_frontend_feature_flag).and_call_original + + expect(controller).to receive(:push_frontend_feature_flag) + .with(:swimlanes_buffered_rendering, project, default_enabled: :yaml) + + list_boards + end + context 'when format is HTML' do it 'renders template' do list_boards @@ -116,6 +125,15 @@ RSpec.describe Projects::BoardsController do describe 'GET show' do let!(:board) { create(:board, project: project) } + it 'pushes swimlanes_buffered_rendering feature flag' do + allow(controller).to receive(:push_frontend_feature_flag).and_call_original + + expect(controller).to receive(:push_frontend_feature_flag) + .with(:swimlanes_buffered_rendering, project, default_enabled: :yaml) + + read_board board: board + end + it 'sets boards_endpoint instance variable to a boards path' do read_board board: board diff --git a/spec/controllers/projects/clusters_controller_spec.rb b/spec/controllers/projects/clusters_controller_spec.rb index dd3440f7660..2a8feb09780 100644 --- a/spec/controllers/projects/clusters_controller_spec.rb +++ b/spec/controllers/projects/clusters_controller_spec.rb @@ -674,22 +674,32 @@ RSpec.describe Projects::ClustersController do describe 'GET show' do let(:cluster) { create(:cluster, :provided_by_gcp, projects: [project]) } - def go + def go(tab: nil) get :show, params: { namespace_id: project.namespace, project_id: project, - id: cluster + id: cluster, + tab: tab } end describe 'functionality' do + render_views + it "renders view" do go expect(response).to have_gitlab_http_status(:ok) expect(assigns(:cluster)).to eq(cluster) end + + it 'renders integration tab view' do + go(tab: 'integrations') + + expect(response).to render_template('clusters/clusters/_integrations') + expect(response).to have_gitlab_http_status(:ok) + end end describe 'security' do diff --git a/spec/controllers/projects/commit_controller_spec.rb b/spec/controllers/projects/commit_controller_spec.rb index 2d7f036be21..a231b54419e 100644 --- a/spec/controllers/projects/commit_controller_spec.rb +++ b/spec/controllers/projects/commit_controller_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' RSpec.describe Projects::CommitController do + include ProjectForksHelper + let_it_be(:project) { create(:project, :repository) } let_it_be(:user) { create(:user) } @@ -295,6 +297,102 @@ RSpec.describe Projects::CommitController do expect(flash[:alert]).to match('Sorry, we cannot cherry-pick this commit automatically.') end end + + context 'when a project has a fork' do + let(:project) { create(:project, :repository) } + let(:forked_project) { fork_project(project, user, namespace: user.namespace, repository: true) } + let(:target_project) { project } + let(:create_merge_request) { nil } + + def send_request + post(:cherry_pick, + params: { + namespace_id: forked_project.namespace, + project_id: forked_project, + target_project_id: target_project.id, + start_branch: 'feature', + id: forked_project.commit.id, + create_merge_request: create_merge_request + }) + end + + def merge_request_url(source_project, branch) + project_new_merge_request_path( + source_project, + merge_request: { + source_project_id: source_project.id, + target_project_id: project.id, + source_branch: branch, + target_branch: 'feature' + } + ) + end + + before do + forked_project.add_maintainer(user) + end + + it 'successfully cherry picks a commit from fork to upstream project' do + send_request + + expect(response).to redirect_to project_commits_path(project, 'feature') + expect(flash[:notice]).to eq('The commit has been successfully cherry-picked into feature.') + expect(project.commit('feature').message).to include(forked_project.commit.id) + end + + context 'when the cherry pick is performed via merge request' do + let(:create_merge_request) { true } + + it 'successfully cherry picks a commit from fork to a cherry pick branch' do + branch = forked_project.commit.cherry_pick_branch_name + send_request + + expect(response).to redirect_to merge_request_url(project, branch) + expect(flash[:notice]).to start_with("The commit has been successfully cherry-picked into #{branch}") + expect(project.commit(branch).message).to include(forked_project.commit.id) + end + end + + context 'when a user cannot push to upstream project' do + let(:create_merge_request) { true } + + before do + project.add_reporter(user) + end + + it 'cherry picks a commit to the fork' do + branch = forked_project.commit.cherry_pick_branch_name + send_request + + expect(response).to redirect_to merge_request_url(forked_project, branch) + expect(flash[:notice]).to start_with("The commit has been successfully cherry-picked into #{branch}") + expect(project.commit('feature').message).not_to include(forked_project.commit.id) + expect(forked_project.commit(branch).message).to include(forked_project.commit.id) + end + end + + context 'when a user do not have access to the target project' do + let(:target_project) { create(:project, :private) } + + it 'cherry picks a commit to the fork' do + send_request + + expect(response).to have_gitlab_http_status(:not_found) + end + end + + context 'disable pick_into_project feature flag' do + before do + stub_feature_flags(pick_into_project: false) + end + + it 'does not cherry pick a commit from fork to upstream' do + send_request + + expect(project.commit('feature').message).not_to include(forked_project.commit.id) + end + end + end end describe 'GET diff_for_path' do diff --git a/spec/controllers/projects/cycle_analytics/events_controller_spec.rb b/spec/controllers/projects/cycle_analytics/events_controller_spec.rb index f940da7ea35..6bbdda89b14 100644 --- a/spec/controllers/projects/cycle_analytics/events_controller_spec.rb +++ b/spec/controllers/projects/cycle_analytics/events_controller_spec.rb @@ -26,7 +26,7 @@ RSpec.describe Projects::CycleAnalytics::EventsController do let(:issue) { create(:issue, project: project, created_at: 9.days.ago) } before do - issue.update(milestone: milestone) + issue.update!(milestone: milestone) end it 'is not empty' do diff --git a/spec/controllers/projects/design_management/designs/raw_images_controller_spec.rb b/spec/controllers/projects/design_management/designs/raw_images_controller_spec.rb index e0f86876f67..c78b838d0df 100644 --- a/spec/controllers/projects/design_management/designs/raw_images_controller_spec.rb +++ b/spec/controllers/projects/design_management/designs/raw_images_controller_spec.rb @@ -8,6 +8,7 @@ RSpec.describe Projects::DesignManagement::Designs::RawImagesController do let_it_be(:project) { create(:project, :private) } let_it_be(:issue) { create(:issue, project: project) } let_it_be(:viewer) { issue.author } + let(:design_id) { design.id } let(:sha) { design.versions.first.sha } let(:filename) { design.filename } @@ -44,17 +45,6 @@ RSpec.describe Projects::DesignManagement::Designs::RawImagesController do expect(response).to have_gitlab_http_status(:ok) end - context 'when the feature flag attachment_with_filename is disabled' do - it 'serves files with just `attachment` in the disposition header' do - stub_feature_flags(attachment_with_filename: false) - - subject - - expect(response.header['Content-Disposition']).to eq('attachment') - expect(response).to have_gitlab_http_status(:ok) - end - end - it 'serves files with Workhorse' do subject diff --git a/spec/controllers/projects/design_management/designs/resized_image_controller_spec.rb b/spec/controllers/projects/design_management/designs/resized_image_controller_spec.rb index 96ecbaf55b6..56c0ef592ca 100644 --- a/spec/controllers/projects/design_management/designs/resized_image_controller_spec.rb +++ b/spec/controllers/projects/design_management/designs/resized_image_controller_spec.rb @@ -9,6 +9,7 @@ RSpec.describe Projects::DesignManagement::Designs::ResizedImageController do let_it_be(:issue) { create(:issue, project: project) } let_it_be(:viewer) { issue.author } let_it_be(:size) { :v432x230 } + let(:design) { create(:design, :with_smaller_image_versions, issue: issue, versions_count: 2) } let(:design_id) { design.id } let(:sha) { design.versions.first.sha } diff --git a/spec/controllers/projects/discussions_controller_spec.rb b/spec/controllers/projects/discussions_controller_spec.rb index 8a793e29bfa..0c8677ea4b9 100644 --- a/spec/controllers/projects/discussions_controller_spec.rb +++ b/spec/controllers/projects/discussions_controller_spec.rb @@ -85,7 +85,7 @@ RSpec.describe Projects::DiscussionsController do context "when the discussion is not resolvable" do before do - note.update(system: true) + note.update!(system: true) end it "returns status 404" do @@ -168,7 +168,7 @@ RSpec.describe Projects::DiscussionsController do context "when the discussion is not resolvable" do before do - note.update(system: true) + note.update!(system: true) end it "returns status 404" do diff --git a/spec/controllers/projects/environments_controller_spec.rb b/spec/controllers/projects/environments_controller_spec.rb index 83ad36b217f..4cb90edb742 100644 --- a/spec/controllers/projects/environments_controller_spec.rb +++ b/spec/controllers/projects/environments_controller_spec.rb @@ -9,6 +9,7 @@ RSpec.describe Projects::EnvironmentsController do let_it_be(:project) { create(:project) } let_it_be(:maintainer) { create(:user, name: 'main-dos').tap { |u| project.add_maintainer(u) } } let_it_be(:reporter) { create(:user, name: 'repo-dos').tap { |u| project.add_reporter(u) } } + let(:user) { maintainer } let!(:environment) { create(:environment, name: 'production', project: project) } diff --git a/spec/controllers/projects/feature_flags_controller_spec.rb b/spec/controllers/projects/feature_flags_controller_spec.rb index f69cc0ddfd8..cd7d1ea0e8a 100644 --- a/spec/controllers/projects/feature_flags_controller_spec.rb +++ b/spec/controllers/projects/feature_flags_controller_spec.rb @@ -9,6 +9,7 @@ RSpec.describe Projects::FeatureFlagsController do let_it_be(:project) { create(:project) } let_it_be(:developer) { create(:user) } let_it_be(:reporter) { create(:user) } + let(:user) { developer } before_all do diff --git a/spec/controllers/projects/forks_controller_spec.rb b/spec/controllers/projects/forks_controller_spec.rb index 7da3d403b53..8ca3009e0c7 100644 --- a/spec/controllers/projects/forks_controller_spec.rb +++ b/spec/controllers/projects/forks_controller_spec.rb @@ -71,7 +71,7 @@ RSpec.describe Projects::ForksController do context 'when fork is internal' do before do - forked_project.update(visibility_level: Project::INTERNAL, group: group) + forked_project.update!(visibility_level: Project::INTERNAL, group: group) end it 'forks counts are correct' do @@ -86,7 +86,7 @@ RSpec.describe Projects::ForksController do context 'when fork is private' do before do - forked_project.update(visibility_level: Project::PRIVATE, group: group) + forked_project.update!(visibility_level: Project::PRIVATE, group: group) end shared_examples 'forks counts' do @@ -153,8 +153,11 @@ RSpec.describe Projects::ForksController do end describe 'GET new' do - subject do + let(:format) { :html } + + subject(:do_request) do get :new, + format: format, params: { namespace_id: project.namespace, project_id: project @@ -166,24 +169,32 @@ RSpec.describe Projects::ForksController do sign_in(user) end - context 'when JSON requested' do - it 'responds with available groups' do - get :new, - format: :json, - params: { - namespace_id: project.namespace, - project_id: project - } + it 'responds with status 200' do + request - expect(json_response['namespaces'].length).to eq(1) - expect(json_response['namespaces'].first['id']).to eq(group.id) - end + expect(response).to have_gitlab_http_status(:ok) end - it 'responds with status 200' do - subject + context 'when JSON is requested' do + let(:format) { :json } - expect(response).to have_gitlab_http_status(:ok) + it 'responds with user namespace + groups' do + do_request + + expect(response).to have_gitlab_http_status(:ok) + expect(json_response['namespaces'].length).to eq(2) + expect(json_response['namespaces'][0]['id']).to eq(user.namespace.id) + expect(json_response['namespaces'][1]['id']).to eq(group.id) + end + + it 'responds with group only when fork_project_form feature flag is disabled' do + stub_feature_flags(fork_project_form: false) + do_request + + expect(response).to have_gitlab_http_status(:ok) + expect(json_response['namespaces'].length).to eq(1) + expect(json_response['namespaces'][0]['id']).to eq(group.id) + end end end diff --git a/spec/controllers/projects/group_links_controller_spec.rb b/spec/controllers/projects/group_links_controller_spec.rb index 084a807e162..d514c486f60 100644 --- a/spec/controllers/projects/group_links_controller_spec.rb +++ b/spec/controllers/projects/group_links_controller_spec.rb @@ -8,15 +8,16 @@ RSpec.describe Projects::GroupLinksController do let_it_be(:project) { create(:project, :private, group: group2) } let_it_be(:user) { create(:user) } - around do |example| - travel_to DateTime.new(2019, 4, 1) { example.run } - end - before do + travel_to DateTime.new(2019, 4, 1) project.add_maintainer(user) sign_in(user) end + after do + travel_back + end + describe '#create' do shared_context 'link project to group' do before do @@ -31,7 +32,7 @@ RSpec.describe Projects::GroupLinksController do context 'when project is not allowed to be shared with a group' do before do - group.update(share_with_group_lock: false) + group.update!(share_with_group_lock: false) end include_context 'link project to group' diff --git a/spec/controllers/projects/imports_controller_spec.rb b/spec/controllers/projects/imports_controller_spec.rb index 5e09a50aa36..65a80b9e8ec 100644 --- a/spec/controllers/projects/imports_controller_spec.rb +++ b/spec/controllers/projects/imports_controller_spec.rb @@ -47,7 +47,7 @@ RSpec.describe Projects::ImportsController do context 'when import is in progress' do before do - import_state.update(status: :started) + import_state.update!(status: :started) end it 'renders template' do @@ -65,7 +65,7 @@ RSpec.describe Projects::ImportsController do context 'when import failed' do before do - import_state.update(status: :failed) + import_state.update!(status: :failed) end it 'redirects to new_namespace_project_import_path' do @@ -77,7 +77,7 @@ RSpec.describe Projects::ImportsController do context 'when import finished' do before do - import_state.update(status: :finished) + import_state.update!(status: :finished) end context 'when project is a fork' do @@ -126,7 +126,7 @@ RSpec.describe Projects::ImportsController do context 'when import never happened' do before do - import_state.update(status: :none) + import_state.update!(status: :none) end it 'redirects to namespace_project_path' do diff --git a/spec/controllers/projects/incidents_controller_spec.rb b/spec/controllers/projects/incidents_controller_spec.rb index ddd15b9b1dd..460821634b0 100644 --- a/spec/controllers/projects/incidents_controller_spec.rb +++ b/spec/controllers/projects/incidents_controller_spec.rb @@ -69,6 +69,7 @@ RSpec.describe Projects::IncidentsController do end let_it_be(:resource) { create(:incident, project: project) } + let(:user) { developer } it 'renders incident page' do diff --git a/spec/controllers/projects/issues_controller_spec.rb b/spec/controllers/projects/issues_controller_spec.rb index 74062038248..3e016a5e8d2 100644 --- a/spec/controllers/projects/issues_controller_spec.rb +++ b/spec/controllers/projects/issues_controller_spec.rb @@ -8,6 +8,7 @@ RSpec.describe Projects::IssuesController do let_it_be(:project, reload: true) { create(:project) } let_it_be(:user, reload: true) { create(:user) } + let(:issue) { create(:issue, project: project) } let(:spam_action_response_fields) { { 'stub_spam_action_response_fields' => true } } @@ -44,7 +45,7 @@ RSpec.describe Projects::IssuesController do let_it_be(:issue) { create(:issue, project: new_project) } before do - project.route.destroy + project.route.destroy! new_project.redirect_routes.create!(path: project.full_path) new_project.add_developer(user) end @@ -63,23 +64,6 @@ RSpec.describe Projects::IssuesController do expect(response).to have_gitlab_http_status(:moved_permanently) end end - - describe 'the null hypothesis experiment', :experiment do - before do - stub_experiments(null_hypothesis: :candidate) - end - - it 'defines the expected before actions' do - expect(controller).to use_before_action(:run_null_hypothesis_experiment) - end - - it 'assigns the candidate experience and tracks the event' do - expect(experiment(:null_hypothesis)).to track('index').on_any_instance.for(:candidate) - .with_context(project: project) - - get :index, params: { namespace_id: project.namespace, project_id: project } - end - end end context 'internal issue tracker' do @@ -209,6 +193,32 @@ RSpec.describe Projects::IssuesController do expect(response).to have_gitlab_http_status(:ok) expect(json_response['issue_email_participants']).to contain_exactly({ "email" => participants[0].email }, { "email" => participants[1].email }) end + + context 'with the invite_members_in_comment experiment', :experiment do + context 'when user can invite' do + before do + stub_experiments(invite_members_in_comment: :invite_member_link) + project.add_maintainer(user) + end + + it 'assigns the candidate experience and tracks the event' do + expect(experiment(:invite_members_in_comment)).to track(:view, property: project.root_ancestor.id.to_s) + .for(:invite_member_link) + .with_context(namespace: project.root_ancestor) + .on_next_instance + + get :show, params: { namespace_id: project.namespace, project_id: project, id: issue.iid } + end + end + + context 'when user can not invite' do + it 'does not track the event' do + expect(experiment(:invite_members_in_comment)).not_to track(:view) + + get :show, params: { namespace_id: project.namespace, project_id: project, id: issue.iid } + end + end + end end describe 'GET #new' do @@ -342,6 +352,7 @@ RSpec.describe Projects::IssuesController do end let_it_be(:issue) { create(:issue, project: project) } + let(:developer) { user } let(:params) do { @@ -685,7 +696,7 @@ RSpec.describe Projects::IssuesController do issue.update!(last_edited_by: deleted_user, last_edited_at: Time.current) - deleted_user.destroy + deleted_user.destroy! sign_in(user) end @@ -1038,10 +1049,10 @@ RSpec.describe Projects::IssuesController do labels = create_list(:label, 10, project: project).map(&:to_reference) issue = create(:issue, project: project, description: 'Test issue') - control_count = ActiveRecord::QueryRecorder.new { issue.update(description: [issue.description, label].join(' ')) }.count + control_count = ActiveRecord::QueryRecorder.new { issue.update!(description: [issue.description, label].join(' ')) }.count # Follow-up to get rid of this `2 * label.count` requirement: https://gitlab.com/gitlab-org/gitlab-foss/issues/52230 - expect { issue.update(description: [issue.description, labels].join(' ')) } + expect { issue.update!(description: [issue.description, labels].join(' ')) } .not_to exceed_query_limit(control_count + 2 * labels.count) end @@ -1158,6 +1169,7 @@ RSpec.describe Projects::IssuesController do context 'resolving discussions in MergeRequest' do let_it_be(:discussion) { create(:diff_note_on_merge_request).to_discussion } + let(:merge_request) { discussion.noteable } let(:project) { merge_request.source_project } @@ -1420,9 +1432,7 @@ RSpec.describe Projects::IssuesController do expect_next_instance_of(Spam::AkismetService) do |akismet_service| expect(akismet_service).to receive_messages(submit_spam: true) end - expect_next_instance_of(ApplicationSetting) do |setting| - expect(setting).to receive_messages(akismet_enabled: true) - end + stub_application_setting(akismet_enabled: true) end def post_spam @@ -1490,12 +1500,6 @@ RSpec.describe Projects::IssuesController do expect(response).to have_gitlab_http_status(:unprocessable_entity) expect(json_response).to eq({ 'errors' => 'Destroy confirmation not provided for issue' }) end - - it 'delegates the update of the todos count cache to TodoService' do - expect_any_instance_of(TodoService).to receive(:destroy_target).with(issue).once - - delete :destroy, params: { namespace_id: project.namespace, project_id: project, id: issue.iid, destroy_confirm: true } - end end end @@ -1623,6 +1627,7 @@ RSpec.describe Projects::IssuesController do describe 'POST #import_csv' do let_it_be(:project) { create(:project, :public) } + let(:file) { fixture_file_upload('spec/fixtures/csv_comma.csv') } context 'unauthorized' do @@ -1822,6 +1827,7 @@ RSpec.describe Projects::IssuesController do context 'with cross-reference system note', :request_store do let_it_be(:new_issue) { create(:issue) } + let(:cross_reference) { "mentioned in #{new_issue.to_reference(issue.project)}" } before do @@ -1899,7 +1905,7 @@ RSpec.describe Projects::IssuesController do before do sign_in(user) - project.route.destroy + project.route.destroy! new_project.redirect_routes.create!(path: project.full_path) new_project.add_developer(user) end diff --git a/spec/controllers/projects/jobs_controller_spec.rb b/spec/controllers/projects/jobs_controller_spec.rb index 80e1268cb01..a7a36d3a074 100644 --- a/spec/controllers/projects/jobs_controller_spec.rb +++ b/spec/controllers/projects/jobs_controller_spec.rb @@ -1275,6 +1275,7 @@ RSpec.describe Projects::JobsController, :clean_gitlab_redis_shared_state do let_it_be(:reporter) { create(:user) } let_it_be(:guest) { create(:user) } let_it_be(:project) { create(:project, :private, :repository, namespace: owner.namespace) } + let(:user) { maintainer } let(:pipeline) { create(:ci_pipeline, project: project, source: :webide, config_source: :webide_source, user: user) } let(:job) { create(:ci_build, :running, :with_runner_session, pipeline: pipeline, user: user) } diff --git a/spec/controllers/projects/labels_controller_spec.rb b/spec/controllers/projects/labels_controller_spec.rb index f452c22a5ca..081927ea73c 100644 --- a/spec/controllers/projects/labels_controller_spec.rb +++ b/spec/controllers/projects/labels_controller_spec.rb @@ -65,7 +65,7 @@ RSpec.describe Projects::LabelsController do end it 'does not include group labels when project does not belong to a group' do - project.update(namespace: create(:namespace)) + project.update!(namespace: create(:namespace)) list_labels @@ -93,6 +93,26 @@ RSpec.describe Projects::LabelsController do end end + context 'with views rendered' do + render_views + + before do + list_labels + end + + it 'avoids N+1 queries' do + control = ActiveRecord::QueryRecorder.new(skip_cached: false) { list_labels } + + create_list(:label, 3, project: project) + create_list(:group_label, 3, group: group) + + # some n+1 queries still exist + # calls to get max project authorization access level + expect { list_labels }.not_to exceed_all_query_limit(control.count).with_threshold(25) + expect(assigns(:labels).count).to eq(10) + end + end + def list_labels get :index, params: { namespace_id: project.namespace.to_param, project_id: project } end @@ -221,7 +241,7 @@ RSpec.describe Projects::LabelsController do end context 'when requesting a redirected path' do - let_it_be(:redirect_route) { project.redirect_routes.create(path: project.full_path + 'old') } + let_it_be(:redirect_route) { project.redirect_routes.create!(path: project.full_path + 'old') } it 'redirects to the canonical path' do get :index, params: { namespace_id: project.namespace, project_id: project.to_param + 'old' } @@ -267,7 +287,7 @@ RSpec.describe Projects::LabelsController do end context 'when requesting a redirected path' do - let_it_be(:redirect_route) { project.redirect_routes.create(path: project.full_path + 'old') } + let_it_be(:redirect_route) { project.redirect_routes.create!(path: project.full_path + 'old') } it 'returns not found' do post :generate, params: { namespace_id: project.namespace, project_id: project.to_param + 'old' } diff --git a/spec/controllers/projects/merge_requests/content_controller_spec.rb b/spec/controllers/projects/merge_requests/content_controller_spec.rb index 67d3ef6f4f0..0eaa528a330 100644 --- a/spec/controllers/projects/merge_requests/content_controller_spec.rb +++ b/spec/controllers/projects/merge_requests/content_controller_spec.rb @@ -11,13 +11,13 @@ RSpec.describe Projects::MergeRequests::ContentController do sign_in(user) end - def do_request(action = :cached_widget) + def do_request(action = :cached_widget, params = {}) get action, params: { namespace_id: project.namespace.to_param, project_id: project, id: merge_request.iid, format: :json - } + }.merge(params) end context 'user has access to the project' do @@ -42,6 +42,10 @@ RSpec.describe Projects::MergeRequests::ContentController do end describe 'GET widget' do + before do + merge_request.mark_as_unchecked! + end + it 'checks whether the MR can be merged' do controller.instance_variable_set(:@merge_request, merge_request) @@ -53,6 +57,17 @@ RSpec.describe Projects::MergeRequests::ContentController do expect(response.headers['Poll-Interval']).to eq('10000') end + context 'when async_mergeability_check param is passed' do + it 'checks mergeability asynchronously' do + expect_next_instance_of(MergeRequests::MergeabilityCheckService) do |service| + expect(service).not_to receive(:execute) + expect(service).to receive(:async_execute).and_call_original + end + + do_request(:widget, { async_mergeability_check: true }) + end + end + context 'merged merge request' do let(:merge_request) do create(:merged_merge_request, :with_test_reports, target_project: project, source_project: project) diff --git a/spec/controllers/projects/merge_requests/creations_controller_spec.rb b/spec/controllers/projects/merge_requests/creations_controller_spec.rb index 091a44130a1..df2023b7356 100644 --- a/spec/controllers/projects/merge_requests/creations_controller_spec.rb +++ b/spec/controllers/projects/merge_requests/creations_controller_spec.rb @@ -213,6 +213,38 @@ RSpec.describe Projects::MergeRequests::CreationsController do expect(assigns(:commit)).to be_nil expect(response).to have_gitlab_http_status(:ok) end + + context 'no target_project_id provided' do + before do + project.add_maintainer(user) + end + + it 'selects itself as a target project' do + get :branch_to, + params: { + namespace_id: project.namespace, + project_id: project, + ref: 'master' + } + + expect(assigns(:target_project)).to eq(project) + expect(response).to have_gitlab_http_status(:ok) + end + + context 'project is a fork' do + it 'calls to project defaults to selects a correct target project' do + get :branch_to, + params: { + namespace_id: fork_project.namespace, + project_id: fork_project, + ref: 'master' + } + + expect(assigns(:target_project)).to eq(project) + expect(response).to have_gitlab_http_status(:ok) + end + end + end end describe 'POST create' do diff --git a/spec/controllers/projects/merge_requests/drafts_controller_spec.rb b/spec/controllers/projects/merge_requests/drafts_controller_spec.rb index af39d4dec72..580211893dc 100644 --- a/spec/controllers/projects/merge_requests/drafts_controller_spec.rb +++ b/spec/controllers/projects/merge_requests/drafts_controller_spec.rb @@ -297,7 +297,7 @@ RSpec.describe Projects::MergeRequests::DraftsController do expect { post :publish, params: params }.to change { Note.count }.by(0).and change { DraftNote.count }.by(0) end - it 'publishes a draft note with quick actions and applies them' do + it 'publishes a draft note with quick actions and applies them', :sidekiq_inline do project.add_developer(user2) create(:draft_note, merge_request: merge_request, author: user, note: "/assign #{user2.to_reference}") diff --git a/spec/controllers/projects/merge_requests_controller_spec.rb b/spec/controllers/projects/merge_requests_controller_spec.rb index 93d5e7eff6c..337a4a19b2e 100644 --- a/spec/controllers/projects/merge_requests_controller_spec.rb +++ b/spec/controllers/projects/merge_requests_controller_spec.rb @@ -8,6 +8,7 @@ RSpec.describe Projects::MergeRequestsController do let_it_be_with_refind(:project) { create(:project, :repository) } let_it_be_with_reload(:project_public_with_private_builds) { create(:project, :repository, :public, :builds_private) } + let(:user) { project.owner } let(:merge_request) { create(:merge_request_with_diffs, target_project: project, source_project: project) } @@ -40,6 +41,32 @@ RSpec.describe Projects::MergeRequestsController do get :show, params: params.merge(extra_params) end + context 'with the invite_members_in_comment experiment', :experiment do + context 'when user can invite' do + before do + stub_experiments(invite_members_in_comment: :invite_member_link) + project.add_maintainer(user) + end + + it 'assigns the candidate experience and tracks the event' do + expect(experiment(:invite_members_in_comment)).to track(:view, property: project.root_ancestor.id.to_s) + .for(:invite_member_link) + .with_context(namespace: project.root_ancestor) + .on_next_instance + + go + end + end + + context 'when user can not invite' do + it 'does not track the event' do + expect(experiment(:invite_members_in_comment)).not_to track(:view) + + go + end + end + end + context 'with view param' do before do go(view: 'parallel') @@ -55,13 +82,19 @@ RSpec.describe Projects::MergeRequestsController do merge_request.mark_as_unchecked! end - it 'checks mergeability asynchronously' do - expect_next_instance_of(MergeRequests::MergeabilityCheckService) do |service| - expect(service).not_to receive(:execute) - expect(service).to receive(:async_execute) + context 'check_mergeability_async_in_widget feature flag is disabled' do + before do + stub_feature_flags(check_mergeability_async_in_widget: false) end - go + it 'checks mergeability asynchronously' do + expect_next_instance_of(MergeRequests::MergeabilityCheckService) do |service| + expect(service).not_to receive(:execute) + expect(service).to receive(:async_execute) + end + + go + end end end @@ -695,12 +728,6 @@ RSpec.describe Projects::MergeRequestsController do expect(response).to have_gitlab_http_status(:unprocessable_entity) expect(json_response).to eq({ 'errors' => 'Destroy confirmation not provided for merge request' }) end - - it 'delegates the update of the todos count cache to TodoService' do - expect_any_instance_of(TodoService).to receive(:destroy_target).with(merge_request).once - - delete :destroy, params: { namespace_id: project.namespace, project_id: project, id: merge_request.iid, destroy_confirm: true } - end end end diff --git a/spec/controllers/projects/milestones_controller_spec.rb b/spec/controllers/projects/milestones_controller_spec.rb index b93f1b41a7e..b62353784b3 100644 --- a/spec/controllers/projects/milestones_controller_spec.rb +++ b/spec/controllers/projects/milestones_controller_spec.rb @@ -105,7 +105,7 @@ RSpec.describe Projects::MilestonesController do context 'with a single group ancestor' do before do - project.update(namespace: group) + project.update!(namespace: group) get :index, params: { namespace_id: project.namespace.id, project_id: project.id }, format: :json end @@ -122,7 +122,7 @@ RSpec.describe Projects::MilestonesController do let!(:subgroup_milestone) { create(:milestone, group: subgroup) } before do - project.update(namespace: subgroup) + project.update!(namespace: subgroup) get :index, params: { namespace_id: project.namespace.id, project_id: project.id }, format: :json end @@ -158,7 +158,7 @@ RSpec.describe Projects::MilestonesController do let(:group) { create(:group) } before do - project.update(namespace: group) + project.update!(namespace: group) end context 'when user does not have permission to promote milestone' do @@ -234,7 +234,7 @@ RSpec.describe Projects::MilestonesController do end it 'renders 404' do - project.update(namespace: user.namespace) + project.update!(namespace: user.namespace) post :promote, params: { namespace_id: project.namespace.id, project_id: project.id, id: milestone.iid } @@ -253,7 +253,7 @@ RSpec.describe Projects::MilestonesController do before do project.add_guest(guest_user) sign_in(guest_user) - issue.update(assignee_ids: issue_assignee.id) + issue.update!(assignee_ids: issue_assignee.id) end context "when issue is not confidential" do @@ -269,7 +269,7 @@ RSpec.describe Projects::MilestonesController do context "when issue is confidential" do before do - issue.update(confidential: true) + issue.update!(confidential: true) end it 'shows no milestone participants' do diff --git a/spec/controllers/projects/notes_controller_spec.rb b/spec/controllers/projects/notes_controller_spec.rb index add249e2c74..d92862f0ca3 100644 --- a/spec/controllers/projects/notes_controller_spec.rb +++ b/spec/controllers/projects/notes_controller_spec.rb @@ -334,7 +334,7 @@ RSpec.describe Projects::NotesController do before do project.update_attribute(:visibility_level, project_visibility) - project.project_feature.update(merge_requests_access_level: merge_requests_access_level) + project.project_feature.update!(merge_requests_access_level: merge_requests_access_level) sign_in(user) end @@ -917,7 +917,7 @@ RSpec.describe Projects::NotesController do context "when the note is not resolvable" do before do - note.update(system: true) + note.update!(system: true) end it "returns status 404" do @@ -980,7 +980,7 @@ RSpec.describe Projects::NotesController do context "when the note is not resolvable" do before do - note.update(system: true) + note.update!(system: true) end it "returns status 404" do diff --git a/spec/controllers/projects/performance_monitoring/dashboards_controller_spec.rb b/spec/controllers/projects/performance_monitoring/dashboards_controller_spec.rb index 8a344a72120..923581d9367 100644 --- a/spec/controllers/projects/performance_monitoring/dashboards_controller_spec.rb +++ b/spec/controllers/projects/performance_monitoring/dashboards_controller_spec.rb @@ -5,6 +5,7 @@ require 'spec_helper' RSpec.describe Projects::PerformanceMonitoring::DashboardsController do let_it_be(:user) { create(:user) } let_it_be(:namespace) { create(:namespace) } + let!(:project) { create(:project, :repository, name: 'dashboard-project', namespace: namespace) } let(:repository) { project.repository } let(:branch) { double(name: branch_name) } diff --git a/spec/controllers/projects/pipelines_controller_spec.rb b/spec/controllers/projects/pipelines_controller_spec.rb index e1405660ccb..753223c5a4f 100644 --- a/spec/controllers/projects/pipelines_controller_spec.rb +++ b/spec/controllers/projects/pipelines_controller_spec.rb @@ -7,13 +7,14 @@ RSpec.describe Projects::PipelinesController do let_it_be(:user) { create(:user) } let_it_be(:project) { create(:project, :public, :repository) } + let(:feature) { ProjectFeature::ENABLED } before do allow(Sidekiq.logger).to receive(:info) stub_not_protect_default_branch project.add_developer(user) - project.project_feature.update(builds_access_level: feature) + project.project_feature.update!(builds_access_level: feature) sign_in(user) end @@ -272,6 +273,23 @@ RSpec.describe Projects::PipelinesController do end end + describe 'GET #index' do + context 'pipeline_empty_state_templates experiment' do + before do + stub_application_setting(auto_devops_enabled: false) + end + + it 'tracks the view', :experiment do + expect(experiment(:pipeline_empty_state_templates)) + .to track(:view, value: project.namespace_id) + .with_context(actor: user) + .on_next_instance + + get :index, params: { namespace_id: project.namespace, project_id: project } + end + end + end + describe 'GET show.json' do let(:pipeline) { create(:ci_pipeline, project: project) } @@ -628,44 +646,6 @@ RSpec.describe Projects::PipelinesController do end end - describe 'GET stages_ajax.json' do - let(:pipeline) { create(:ci_pipeline, project: project) } - - context 'when accessing existing stage' do - before do - create(:ci_build, pipeline: pipeline, stage: 'build') - - get_stage_ajax('build') - end - - it 'returns html source for stage dropdown' do - expect(response).to have_gitlab_http_status(:ok) - expect(response).to render_template('projects/pipelines/_stage') - expect(json_response).to include('html') - end - end - - context 'when accessing unknown stage' do - before do - get_stage_ajax('test') - end - - it 'responds with not found' do - expect(response).to have_gitlab_http_status(:not_found) - end - end - - def get_stage_ajax(name) - get :stage_ajax, params: { - namespace_id: project.namespace, - project_id: project, - id: pipeline.id, - stage: name - }, - format: :json - end - end - describe 'GET status.json' do let(:pipeline) { create(:ci_pipeline, project: project) } let(:status) { pipeline.detailed_status(double('user')) } @@ -702,7 +682,7 @@ RSpec.describe Projects::PipelinesController do before do project.add_developer(user) - project.project_feature.update(builds_access_level: feature) + project.project_feature.update!(builds_access_level: feature) end context 'with a valid .gitlab-ci.yml file' do @@ -721,7 +701,7 @@ RSpec.describe Projects::PipelinesController do pipeline = project.ci_pipelines.last expected_redirect_path = Gitlab::Routing.url_helpers.project_pipeline_path(project, pipeline) - expect(pipeline).to be_pending + expect(pipeline).to be_created expect(response).to redirect_to(expected_redirect_path) end end @@ -777,7 +757,7 @@ RSpec.describe Projects::PipelinesController do before do project.add_developer(user) - project.project_feature.update(builds_access_level: feature) + project.project_feature.update!(builds_access_level: feature) end context 'with a valid .gitlab-ci.yml file' do diff --git a/spec/controllers/projects/pipelines_settings_controller_spec.rb b/spec/controllers/projects/pipelines_settings_controller_spec.rb index ad631b7c3da..39fb153e802 100644 --- a/spec/controllers/projects/pipelines_settings_controller_spec.rb +++ b/spec/controllers/projects/pipelines_settings_controller_spec.rb @@ -5,6 +5,7 @@ require 'spec_helper' RSpec.describe Projects::PipelinesSettingsController do let_it_be(:user) { create(:user) } let_it_be(:project_auto_devops) { create(:project_auto_devops) } + let(:project) { project_auto_devops.project } before do diff --git a/spec/controllers/projects/project_members_controller_spec.rb b/spec/controllers/projects/project_members_controller_spec.rb index 53a7c2ca069..46a0fc8edb0 100644 --- a/spec/controllers/projects/project_members_controller_spec.rb +++ b/spec/controllers/projects/project_members_controller_spec.rb @@ -7,8 +7,12 @@ RSpec.describe Projects::ProjectMembersController do let(:group) { create(:group, :public) } let(:project) { create(:project, :public) } - around do |example| - travel_to DateTime.new(2019, 4, 1) { example.run } + before do + travel_to DateTime.new(2019, 4, 1) + end + + after do + travel_back end describe 'GET index' do diff --git a/spec/controllers/projects/raw_controller_spec.rb b/spec/controllers/projects/raw_controller_spec.rb index b1c3c1c0276..5dee36ee7c2 100644 --- a/spec/controllers/projects/raw_controller_spec.rb +++ b/spec/controllers/projects/raw_controller_spec.rb @@ -6,6 +6,7 @@ RSpec.describe Projects::RawController do include RepoHelpers let_it_be(:project) { create(:project, :public, :repository) } + let(:inline) { nil } describe 'GET #show' do diff --git a/spec/controllers/projects/registry/repositories_controller_spec.rb b/spec/controllers/projects/registry/repositories_controller_spec.rb index 9b803edd463..0685e5a2055 100644 --- a/spec/controllers/projects/registry/repositories_controller_spec.rb +++ b/spec/controllers/projects/registry/repositories_controller_spec.rb @@ -16,19 +16,19 @@ RSpec.describe Projects::Registry::RepositoriesController do project.add_developer(user) end - shared_examples 'with name parameter' do - let_it_be(:repo) { create(:container_repository, project: project, name: 'my_searched_image') } - let_it_be(:another_repo) { create(:container_repository, project: project, name: 'bar') } - - it 'returns the searched repo' do - go_to_index(format: :json, params: { name: 'my_searched_image' }) + shared_examples 'renders 200 for html and 404 for json' do + it 'successfully renders container repositories', :snowplow do + go_to_index expect(response).to have_gitlab_http_status(:ok) - expect(json_response.length).to eq 1 - expect(json_response.first).to include( - 'id' => repo.id, - 'name' => repo.name - ) + # event tracked in GraphQL API: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/44926 + expect_no_snowplow_event + end + + it 'returns 404 for request in json format' do + go_to_index(format: :json) + + expect(response).to have_gitlab_http_status(:not_found) end end @@ -50,33 +50,12 @@ RSpec.describe Projects::Registry::RepositoriesController do tags: %w[rc1 latest]) end - it 'successfully renders container repositories', :snowplow do - go_to_index - - expect_no_snowplow_event - expect(response).to have_gitlab_http_status(:ok) - end - - it 'tracks the event', :snowplow do - go_to_index(format: :json) - - expect_snowplow_event(category: anything, action: 'list_repositories') - end - it 'creates a root container repository' do expect { go_to_index }.to change { ContainerRepository.all.count }.by(1) expect(ContainerRepository.first).to be_root_repository end - it 'json has a list of projects' do - go_to_index(format: :json) - - expect(response).to have_gitlab_http_status(:ok) - expect(response).to match_response_schema('registry/repositories') - expect(response).to include_pagination_headers - end - - it_behaves_like 'with name parameter' + it_behaves_like 'renders 200 for html and 404 for json' end context 'when there are no tags for this repository' do @@ -84,22 +63,11 @@ RSpec.describe Projects::Registry::RepositoriesController do stub_container_registry_tags(repository: :any, tags: []) end - it 'successfully renders container repositories' do - go_to_index - - expect(response).to have_gitlab_http_status(:ok) - end - it 'does not ensure root container repository' do expect { go_to_index }.not_to change { ContainerRepository.all.count } end - it 'responds with json if asked' do - go_to_index(format: :json) - - expect(response).to have_gitlab_http_status(:ok) - expect(json_response).to be_kind_of(Array) - end + it_behaves_like 'renders 200 for html and 404 for json' end end end diff --git a/spec/controllers/projects/registry/tags_controller_spec.rb b/spec/controllers/projects/registry/tags_controller_spec.rb index 5bff89b4308..c03a280d2cd 100644 --- a/spec/controllers/projects/registry/tags_controller_spec.rb +++ b/spec/controllers/projects/registry/tags_controller_spec.rb @@ -42,7 +42,7 @@ RSpec.describe Projects::Registry::TagsController do it 'tracks the event', :snowplow do get_tags - expect_snowplow_event(category: anything, action: 'list_tags') + expect_snowplow_event(category: 'Projects::Registry::TagsController', action: 'list_tags') end end @@ -107,11 +107,12 @@ RSpec.describe Projects::Registry::TagsController do destroy_tag('test.') end - it 'tracks the event' do + it 'tracks the event', :snowplow do expect_delete_tags(%w[test.]) - expect(controller).to receive(:track_event).with(:delete_tag) destroy_tag('test.') + + expect_snowplow_event(category: 'Projects::Registry::TagsController', action: 'delete_tag') end end end diff --git a/spec/controllers/projects/releases/evidences_controller_spec.rb b/spec/controllers/projects/releases/evidences_controller_spec.rb index 0ec4cdf2a31..68433969d69 100644 --- a/spec/controllers/projects/releases/evidences_controller_spec.rb +++ b/spec/controllers/projects/releases/evidences_controller_spec.rb @@ -7,6 +7,7 @@ RSpec.describe Projects::Releases::EvidencesController do let_it_be(:private_project) { create(:project, :repository, :private) } let_it_be(:developer) { create(:user) } let_it_be(:reporter) { create(:user) } + let(:user) { developer } before do @@ -62,7 +63,7 @@ RSpec.describe Projects::Releases::EvidencesController do context 'when the release was created before evidence existed' do before do - evidence.destroy + evidence.destroy! end it_behaves_like 'not found' diff --git a/spec/controllers/projects/releases_controller_spec.rb b/spec/controllers/projects/releases_controller_spec.rb index fc7ab88bbe0..a1e36ec5c4c 100644 --- a/spec/controllers/projects/releases_controller_spec.rb +++ b/spec/controllers/projects/releases_controller_spec.rb @@ -11,6 +11,7 @@ RSpec.describe Projects::ReleasesController do let_it_be(:reporter) { create(:user) } let_it_be(:guest) { create(:user) } let_it_be(:user) { developer } + let!(:release_1) { create(:release, project: project, released_at: Time.zone.parse('2018-10-18')) } let!(:release_2) { create(:release, project: project, released_at: Time.zone.parse('2019-10-19')) } diff --git a/spec/controllers/projects/repositories_controller_spec.rb b/spec/controllers/projects/repositories_controller_spec.rb index e6327a72a68..cb2579b800a 100644 --- a/spec/controllers/projects/repositories_controller_spec.rb +++ b/spec/controllers/projects/repositories_controller_spec.rb @@ -56,28 +56,6 @@ RSpec.describe Projects::RepositoriesController do expect(response.header[Gitlab::Workhorse::SEND_DATA_HEADER]).to start_with("git-archive:") end - it 'handles legacy queries with no ref' do - get :archive, params: { namespace_id: project.namespace, project_id: project }, format: "zip" - - expect(response.header[Gitlab::Workhorse::SEND_DATA_HEADER]).to start_with("git-archive:") - end - - it 'handles legacy queries with the ref specified as ref in params' do - get :archive, params: { namespace_id: project.namespace, project_id: project, ref: 'feature' }, format: 'zip' - - expect(response).to have_gitlab_http_status(:ok) - expect(assigns(:ref)).to eq('feature') - expect(response.header[Gitlab::Workhorse::SEND_DATA_HEADER]).to start_with("git-archive:") - end - - it 'handles legacy queries with the ref specified as id in params' do - get :archive, params: { namespace_id: project.namespace, project_id: project, id: 'feature' }, format: 'zip' - - expect(response).to have_gitlab_http_status(:ok) - expect(assigns(:ref)).to eq('feature') - expect(response.header[Gitlab::Workhorse::SEND_DATA_HEADER]).to start_with("git-archive:") - end - it 'prioritizes the id param over the ref param when both are specified' do get :archive, params: { namespace_id: project.namespace, project_id: project, id: 'feature', ref: 'feature_conflict' }, format: 'zip' diff --git a/spec/controllers/projects/runners_controller_spec.rb b/spec/controllers/projects/runners_controller_spec.rb index d63d88f8283..3021ad42c9f 100644 --- a/spec/controllers/projects/runners_controller_spec.rb +++ b/spec/controllers/projects/runners_controller_spec.rb @@ -46,7 +46,7 @@ RSpec.describe Projects::RunnersController do describe '#resume' do it 'marks the runner as active and ticks the queue' do - runner.update(active: false) + runner.update!(active: false) expect do post :resume, params: params @@ -61,7 +61,7 @@ RSpec.describe Projects::RunnersController do describe '#pause' do it 'marks the runner as inactive and ticks the queue' do - runner.update(active: true) + runner.update!(active: true) expect do post :pause, params: params diff --git a/spec/controllers/projects/services_controller_spec.rb b/spec/controllers/projects/services_controller_spec.rb index 8f928cf3382..488a34b74df 100644 --- a/spec/controllers/projects/services_controller_spec.rb +++ b/spec/controllers/projects/services_controller_spec.rb @@ -4,6 +4,7 @@ require 'spec_helper' RSpec.describe Projects::ServicesController do include JiraServiceHelper + include AfterNextHelpers let(:project) { create(:project, :repository) } let(:user) { create(:user) } @@ -13,7 +14,6 @@ RSpec.describe Projects::ServicesController do before do sign_in(user) project.add_maintainer(user) - allow(Gitlab::UrlBlocker).to receive(:validate!).and_return([URI.parse('http://example.com'), nil]) end describe '#test' do @@ -114,7 +114,7 @@ RSpec.describe Projects::ServicesController do end context 'failure' do - it 'returns success status code and the error message' do + it 'returns an error response when the integration test fails' do stub_request(:get, 'http://example.com/rest/api/2/serverInfo') .to_return(status: 404) @@ -128,6 +128,36 @@ RSpec.describe Projects::ServicesController do 'test_failed' => true ) end + + context 'with the Slack integration' do + let_it_be(:service) { build(:slack_service) } + + it 'returns an error response when the URL is blocked' do + put :test, params: project_params(service: { webhook: 'http://127.0.0.1' }) + + expect(response).to be_successful + expect(json_response).to eq( + 'error' => true, + 'message' => 'Connection failed. Please check your settings.', + 'service_response' => "URL 'http://127.0.0.1' is blocked: Requests to localhost are not allowed", + 'test_failed' => true + ) + end + + it 'returns an error response when a network exception is raised' do + expect_next(SlackService).to receive(:test).and_raise(Errno::ECONNREFUSED) + + put :test, params: project_params + + expect(response).to be_successful + expect(json_response).to eq( + 'error' => true, + 'message' => 'Connection failed. Please check your settings.', + 'service_response' => 'Connection refused', + 'test_failed' => true + ) + end + end end end diff --git a/spec/controllers/projects/settings/access_tokens_controller_spec.rb b/spec/controllers/projects/settings/access_tokens_controller_spec.rb index ff52b2a765a..2a7e3d0b322 100644 --- a/spec/controllers/projects/settings/access_tokens_controller_spec.rb +++ b/spec/controllers/projects/settings/access_tokens_controller_spec.rb @@ -4,7 +4,8 @@ require('spec_helper') RSpec.describe Projects::Settings::AccessTokensController do let_it_be(:user) { create(:user) } - let_it_be(:project) { create(:project) } + let_it_be(:group) { create(:group) } + let_it_be(:project) { create(:project, group: group) } let_it_be(:bot_user) { create(:user, :project_bot) } before_all do @@ -40,6 +41,26 @@ RSpec.describe Projects::Settings::AccessTokensController do it_behaves_like 'feature unavailable' it_behaves_like 'project access tokens available #create' + + context 'when project access token creation is disabled' do + before do + group.namespace_settings.update_column(:resource_access_token_creation_allowed, false) + end + + it { is_expected.to have_gitlab_http_status(:not_found) } + + it 'does not create the token' do + expect { subject }.not_to change { PersonalAccessToken.count } + end + + it 'does not add the project bot as a member' do + expect { subject }.not_to change { Member.count } + end + + it 'does not create the project bot user' do + expect { subject }.not_to change { User.count } + end + end end describe '#revoke', :sidekiq_inline do diff --git a/spec/controllers/projects/settings/ci_cd_controller_spec.rb b/spec/controllers/projects/settings/ci_cd_controller_spec.rb index 7a6e11d53d4..d953249c139 100644 --- a/spec/controllers/projects/settings/ci_cd_controller_spec.rb +++ b/spec/controllers/projects/settings/ci_cd_controller_spec.rb @@ -5,6 +5,7 @@ require('spec_helper') RSpec.describe Projects::Settings::CiCdController do let_it_be(:user) { create(:user) } let_it_be(:project_auto_devops) { create(:project_auto_devops) } + let(:project) { project_auto_devops.project } before do diff --git a/spec/controllers/projects/settings/operations_controller_spec.rb b/spec/controllers/projects/settings/operations_controller_spec.rb index 46f69eaf96a..d2934ec4e97 100644 --- a/spec/controllers/projects/settings/operations_controller_spec.rb +++ b/spec/controllers/projects/settings/operations_controller_spec.rb @@ -493,6 +493,7 @@ RSpec.describe Projects::Settings::OperationsController do describe 'PATCH #update' do let_it_be(:external_url) { 'https://gitlab.com' } + let(:params) do { tracing_setting_attributes: { diff --git a/spec/controllers/projects/snippets_controller_spec.rb b/spec/controllers/projects/snippets_controller_spec.rb index 793ffbbfad9..1a6c0974f08 100644 --- a/spec/controllers/projects/snippets_controller_spec.rb +++ b/spec/controllers/projects/snippets_controller_spec.rb @@ -46,6 +46,10 @@ RSpec.describe Projects::SnippetsController do let(:params) { base_params } end + it_behaves_like 'snippets views' do + let(:params) { base_params } + end + context 'when the project snippet is private' do let_it_be(:project_snippet) { create(:project_snippet, :private, project: project, author: user) } diff --git a/spec/controllers/projects/starrers_controller_spec.rb b/spec/controllers/projects/starrers_controller_spec.rb index 66888fa3024..8d03600cd58 100644 --- a/spec/controllers/projects/starrers_controller_spec.rb +++ b/spec/controllers/projects/starrers_controller_spec.rb @@ -170,7 +170,7 @@ RSpec.describe Projects::StarrersController do context 'when project is private' do before do - project.update(visibility_level: Project::PRIVATE) + project.update!(visibility_level: Project::PRIVATE) end it 'starrers are not visible for non logged in users' do diff --git a/spec/controllers/projects/static_site_editor_controller_spec.rb b/spec/controllers/projects/static_site_editor_controller_spec.rb index b563f3b667f..73b0e3bba69 100644 --- a/spec/controllers/projects/static_site_editor_controller_spec.rb +++ b/spec/controllers/projects/static_site_editor_controller_spec.rb @@ -5,6 +5,7 @@ require 'spec_helper' RSpec.describe Projects::StaticSiteEditorController do let_it_be(:project) { create(:project, :public, :repository) } let_it_be(:user) { create(:user) } + let(:data) { { key: 'value' } } describe 'GET index' do diff --git a/spec/controllers/projects/todos_controller_spec.rb b/spec/controllers/projects/todos_controller_spec.rb index 0e35f401bc8..9a73417ffdb 100644 --- a/spec/controllers/projects/todos_controller_spec.rb +++ b/spec/controllers/projects/todos_controller_spec.rb @@ -5,6 +5,7 @@ require('spec_helper') RSpec.describe Projects::TodosController do let_it_be(:user) { create(:user) } let_it_be(:project) { create(:project) } + let(:issue) { create(:issue, project: project) } let(:merge_request) { create(:merge_request, source_project: project) } let(:design) { create(:design, project: project, issue: issue) } diff --git a/spec/controllers/projects/uploads_controller_spec.rb b/spec/controllers/projects/uploads_controller_spec.rb index dda58f06a37..c008c7253d8 100644 --- a/spec/controllers/projects/uploads_controller_spec.rb +++ b/spec/controllers/projects/uploads_controller_spec.rb @@ -29,7 +29,7 @@ RSpec.describe Projects::UploadsController do let!(:upload) { create(:upload, :issuable_upload, :with_file, model: model) } let(:project) { model } let(:upload_path) { File.basename(upload.path) } - let!(:redirect_route) { project.redirect_routes.create(path: project.full_path + 'old') } + let!(:redirect_route) { project.redirect_routes.create!(path: project.full_path + 'old') } it 'redirects to a file with the proper extension' do get :show, params: { namespace_id: project.namespace, project_id: project.to_param + 'old', filename: File.basename(upload.path), secret: upload.secret } |