diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-05 00:07:49 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-05 00:07:49 +0000 |
commit | 77237c5a6b9044f58beabc54d3589e5fa09cbfba (patch) | |
tree | f43188047fe8955f6cf78e05ae9c2e8f6a019e0b /spec/requests | |
parent | 2fd92f2dc784ade9cb4e1c33dd60cbfad7b86818 (diff) | |
download | gitlab-ce-77237c5a6b9044f58beabc54d3589e5fa09cbfba.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/requests')
-rw-r--r-- | spec/requests/api/broadcast_messages_spec.rb | 22 | ||||
-rw-r--r-- | spec/requests/api/internal/base_spec.rb | 206 | ||||
-rw-r--r-- | spec/requests/groups/milestones_controller_spec.rb | 46 |
3 files changed, 225 insertions, 49 deletions
diff --git a/spec/requests/api/broadcast_messages_spec.rb b/spec/requests/api/broadcast_messages_spec.rb index 17b25d5c7cc..9bfbbe0daab 100644 --- a/spec/requests/api/broadcast_messages_spec.rb +++ b/spec/requests/api/broadcast_messages_spec.rb @@ -17,7 +17,7 @@ describe API::BroadcastMessages do expect(response).to include_pagination_headers expect(json_response).to be_kind_of(Array) expect(json_response.first.keys) - .to match_array(%w(id message starts_at ends_at color font active target_path broadcast_type)) + .to match_array(%w(id message starts_at ends_at color font active target_path broadcast_type dismissable)) end end @@ -28,7 +28,7 @@ describe API::BroadcastMessages do expect(response).to have_gitlab_http_status(:ok) expect(json_response['id']).to eq message.id expect(json_response.keys) - .to match_array(%w(id message starts_at ends_at color font active target_path broadcast_type)) + .to match_array(%w(id message starts_at ends_at color font active target_path broadcast_type dismissable)) end end @@ -111,6 +111,15 @@ describe API::BroadcastMessages do expect(response).to have_gitlab_http_status(:bad_request) end + + it 'accepts an active dismissable value ' do + attrs = { message: 'new message', dismissable: true } + + post api('/broadcast_messages', admin), params: attrs + + expect(response).to have_gitlab_http_status(:created) + expect(json_response['dismissable']).to eq true + end end end @@ -187,6 +196,15 @@ describe API::BroadcastMessages do expect(response).to have_gitlab_http_status(:bad_request) end + + it 'accepts a new dismissable value ' do + attrs = { message: 'new message', dismissable: true } + + put api("/broadcast_messages/#{message.id}", admin), params: attrs + + expect(response).to have_gitlab_http_status(:ok) + expect(json_response['dismissable']).to eq true + end end end diff --git a/spec/requests/api/internal/base_spec.rb b/spec/requests/api/internal/base_spec.rb index fe0a3ffebd3..1f20a088e4f 100644 --- a/spec/requests/api/internal/base_spec.rb +++ b/spec/requests/api/internal/base_spec.rb @@ -10,6 +10,9 @@ describe API::Internal::Base do let(:gl_repository) { "project-#{project.id}" } let(:reference_counter) { double('ReferenceCounter') } + let_it_be(:personal_snippet) { create(:personal_snippet, :repository, author: user) } + let_it_be(:project_snippet) { create(:project_snippet, :repository, author: user, project: project) } + describe "GET /internal/check" do it do expect_any_instance_of(Redis).to receive(:ping).and_return('PONG') @@ -312,6 +315,54 @@ describe API::Internal::Base do end end + context 'git push with personal snippet' do + it 'responds with success' do + push(key, personal_snippet) + + expect(response).to have_gitlab_http_status(:ok) + expect(json_response["status"]).to be_truthy + expect(json_response["gl_project_path"]).to eq(personal_snippet.repository.full_path) + expect(json_response["gl_repository"]).to eq("snippet-#{personal_snippet.id}") + expect(user.reload.last_activity_on).to be_nil + end + end + + context 'git pull with personal snippet' do + it 'responds with success' do + pull(key, personal_snippet) + + expect(response).to have_gitlab_http_status(:ok) + expect(json_response["status"]).to be_truthy + expect(json_response["gl_project_path"]).to eq(personal_snippet.repository.full_path) + expect(json_response["gl_repository"]).to eq("snippet-#{personal_snippet.id}") + expect(user.reload.last_activity_on).to eql(Date.today) + end + end + + context 'git push with project snippet' do + it 'responds with success' do + push(key, project_snippet) + + expect(response).to have_gitlab_http_status(:ok) + expect(json_response["status"]).to be_truthy + expect(json_response["gl_project_path"]).to eq(project_snippet.repository.full_path) + expect(json_response["gl_repository"]).to eq("snippet-#{project_snippet.id}") + expect(user.reload.last_activity_on).to be_nil + end + end + + context 'git pull with project snippet' do + it 'responds with success' do + pull(key, project_snippet) + + expect(response).to have_gitlab_http_status(:ok) + expect(json_response["status"]).to be_truthy + expect(json_response["gl_project_path"]).to eq(project_snippet.repository.full_path) + expect(json_response["gl_repository"]).to eq("snippet-#{project_snippet.id}") + expect(user.reload.last_activity_on).to eql(Date.today) + end + end + context "git pull" do before do allow(Feature).to receive(:persisted_names).and_return(%w[gitaly_mep_mep]) @@ -393,10 +444,28 @@ describe API::Internal::Base do end end - it_behaves_like 'storing arguments in the application context' do - let(:expected_params) { { user: key.user.username, project: project.full_path } } + context 'with Project' do + it_behaves_like 'storing arguments in the application context' do + let(:expected_params) { { user: key.user.username, project: project.full_path } } + + subject { push(key, project) } + end + end + + context 'with PersonalSnippet' do + it_behaves_like 'storing arguments in the application context' do + let(:expected_params) { { user: key.user.username } } + + subject { push(key, personal_snippet) } + end + end - subject { push(key, project) } + context 'with ProjectSnippet' do + it_behaves_like 'storing arguments in the application context' do + let(:expected_params) { { user: key.user.username, project: project_snippet.project.full_path } } + + subject { push(key, project_snippet) } + end end end @@ -450,7 +519,7 @@ describe API::Internal::Base do { authentication_abilities: [:read_project, :download_code, :push_code], namespace_path: project.namespace.path, - project_path: project.path, + repository_path: project.path, redirected_path: nil } ).and_return(access_checker) @@ -835,22 +904,60 @@ describe API::Internal::Base do allow_any_instance_of(Gitlab::Identifier).to receive(:identify).and_return(user) end - it 'executes PostReceiveService' do - message = <<~MESSAGE.strip - To create a merge request for #{branch_name}, visit: - http://#{Gitlab.config.gitlab.host}/#{project.full_path}/-/merge_requests/new?merge_request%5Bsource_branch%5D=#{branch_name} - MESSAGE + context 'with Project' do + it 'executes PostReceiveService' do + message = <<~MESSAGE.strip + To create a merge request for #{branch_name}, visit: + http://#{Gitlab.config.gitlab.host}/#{project.full_path}/-/merge_requests/new?merge_request%5Bsource_branch%5D=#{branch_name} + MESSAGE + + subject - subject + expect(json_response).to eq({ + 'messages' => [{ 'message' => message, 'type' => 'basic' }], + 'reference_counter_decreased' => true + }) + end - expect(json_response).to eq({ - 'messages' => [{ 'message' => message, 'type' => 'basic' }], - 'reference_counter_decreased' => true - }) + it_behaves_like 'storing arguments in the application context' do + let(:expected_params) { { user: user.username, project: project.full_path } } + end end - it_behaves_like 'storing arguments in the application context' do - let(:expected_params) { { user: user.username, project: project.full_path } } + context 'with PersonalSnippet' do + let(:gl_repository) { "snippet-#{personal_snippet.id}" } + + it 'executes PostReceiveService' do + subject + + expect(json_response).to eq({ + 'messages' => [], + 'reference_counter_decreased' => true + }) + end + + it_behaves_like 'storing arguments in the application context' do + let(:expected_params) { { user: key.user.username } } + let(:gl_repository) { "snippet-#{personal_snippet.id}" } + end + end + + context 'with ProjectSnippet' do + let(:gl_repository) { "snippet-#{project_snippet.id}" } + + it 'executes PostReceiveService' do + subject + + expect(json_response).to eq({ + 'messages' => [], + 'reference_counter_decreased' => true + }) + end + + it_behaves_like 'storing arguments in the application context' do + let(:expected_params) { { user: key.user.username, project: project_snippet.project.full_path } } + let(:gl_repository) { "snippet-#{project_snippet.id}" } + end end context 'with an orphaned write deploy key' do @@ -866,16 +973,32 @@ describe API::Internal::Base do end context 'when project is nil' do - let(:gl_repository) { 'project-foo' } + context 'with Project' do + let(:gl_repository) { 'project-foo' } - it 'does not try to notify that project moved' do - allow(Gitlab::GlRepository).to receive(:parse).and_return([nil, Gitlab::GlRepository::PROJECT]) + it 'does not try to notify that project moved' do + allow(Gitlab::GlRepository).to receive(:parse).and_return([nil, nil, Gitlab::GlRepository::PROJECT]) - expect(Gitlab::Checks::ProjectMoved).not_to receive(:fetch_message) + expect(Gitlab::Checks::ProjectMoved).not_to receive(:fetch_message) - subject + subject - expect(response).to have_gitlab_http_status(:ok) + expect(response).to have_gitlab_http_status(:ok) + end + end + + context 'with PersonalSnippet' do + let(:gl_repository) { "snippet-#{personal_snippet.id}" } + + it 'does not try to notify that project moved' do + allow(Gitlab::GlRepository).to receive(:parse).and_return([personal_snippet, nil, Gitlab::GlRepository::PROJECT]) + + expect(Gitlab::Checks::ProjectMoved).not_to receive(:fetch_message) + + subject + + expect(response).to have_gitlab_http_status(:ok) + end end end end @@ -896,24 +1019,37 @@ describe API::Internal::Base do end end - def gl_repository_for(project_or_wiki) - case project_or_wiki + def gl_repository_for(container) + case container when ProjectWiki - Gitlab::GlRepository::WIKI.identifier_for_container(project_or_wiki.project) + Gitlab::GlRepository::WIKI.identifier_for_container(container.project) when Project - Gitlab::GlRepository::PROJECT.identifier_for_container(project_or_wiki) + Gitlab::GlRepository::PROJECT.identifier_for_container(container) + when Snippet + Gitlab::GlRepository::SNIPPET.identifier_for_container(container) else nil end end - def pull(key, project, protocol = 'ssh') + def full_path_for(container) + case container + when PersonalSnippet + "snippets/#{container.id}" + when ProjectSnippet + "#{container.project.full_path}/snippets/#{container.id}" + else + container.full_path + end + end + + def pull(key, container, protocol = 'ssh') post( api("/internal/allowed"), params: { key_id: key.id, - project: project.full_path, - gl_repository: gl_repository_for(project), + project: full_path_for(container), + gl_repository: gl_repository_for(container), action: 'git-upload-pack', secret_token: secret_token, protocol: protocol @@ -921,12 +1057,12 @@ describe API::Internal::Base do ) end - def push(key, project, protocol = 'ssh', env: nil) + def push(key, container, protocol = 'ssh', env: nil) params = { changes: 'd14d6c0abdd253381df51a723d58691b2ee1ab08 570e7b2abdd848b95f2f578043fc23bd6f6fd24d refs/heads/master', key_id: key.id, - project: project.full_path, - gl_repository: gl_repository_for(project), + project: full_path_for(container), + gl_repository: gl_repository_for(container), action: 'git-receive-pack', secret_token: secret_token, protocol: protocol, @@ -939,14 +1075,14 @@ describe API::Internal::Base do ) end - def archive(key, project) + def archive(key, container) post( api("/internal/allowed"), params: { ref: 'master', key_id: key.id, - project: project.full_path, - gl_repository: gl_repository_for(project), + project: full_path_for(container), + gl_repository: gl_repository_for(container), action: 'git-upload-archive', secret_token: secret_token, protocol: 'ssh' diff --git a/spec/requests/groups/milestones_controller_spec.rb b/spec/requests/groups/milestones_controller_spec.rb index 4d15aa43cd2..1c6743dc678 100644 --- a/spec/requests/groups/milestones_controller_spec.rb +++ b/spec/requests/groups/milestones_controller_spec.rb @@ -12,23 +12,45 @@ describe Groups::MilestonesController do end let!(:private_milestone) { create(:milestone, project: public_project_with_private_issues_and_mrs, title: 'project milestone') } - it 'avoids N+1 database queries' do - public_project = create(:project, :public, :merge_requests_enabled, :issues_enabled, group: public_group) - create(:milestone, project: public_project) + describe 'GET #index' do + it 'avoids N+1 database queries' do + public_project = create(:project, :public, :merge_requests_enabled, :issues_enabled, group: public_group) + create(:milestone, project: public_project) - control_count = ActiveRecord::QueryRecorder.new(skip_cached: false) { get "/groups/#{public_group.to_param}/-/milestones.json" }.count + control_count = ActiveRecord::QueryRecorder.new(skip_cached: false) { get group_milestones_path(public_group, format: :json) }.count - projects = create_list(:project, 2, :public, :merge_requests_enabled, :issues_enabled, group: public_group) - projects.each do |project| - create(:milestone, project: project) + projects = create_list(:project, 2, :public, :merge_requests_enabled, :issues_enabled, group: public_group) + projects.each do |project| + create(:milestone, project: project) + end + + expect { get group_milestones_path(public_group, format: :json) }.not_to exceed_all_query_limit(control_count) + expect(response).to have_gitlab_http_status(:ok) + milestones = json_response + + expect(milestones.count).to eq(3) + expect(milestones.map {|x| x['title']}).not_to include(private_milestone.title) end + end - expect { get "/groups/#{public_group.to_param}/-/milestones.json" }.not_to exceed_all_query_limit(control_count) - expect(response).to have_gitlab_http_status(:ok) - milestones = json_response + describe 'GET #show' do + let(:milestone) { create(:milestone, group: public_group) } + let(:show_path) { group_milestone_path(public_group, milestone) } - expect(milestones.count).to eq(3) - expect(milestones.map {|x| x['title']}).not_to include(private_milestone.title) + it 'avoids N+1 database queries' do + projects = create_list(:project, 3, :public, :merge_requests_enabled, :issues_enabled, group: public_group) + projects.each do |project| + create_list(:issue, 2, milestone: milestone, project: project) + end + control = ActiveRecord::QueryRecorder.new(skip_cached: false) { get show_path } + + projects = create_list(:project, 3, :public, :merge_requests_enabled, :issues_enabled, group: public_group) + projects.each do |project| + create_list(:issue, 2, milestone: milestone, project: project) + end + + expect { get show_path }.not_to exceed_all_query_limit(control) + end end end end |