Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-09 15:07:45 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-09 15:07:45 +0300
commitac1dca43baa7b3b1ac7d60d89ad60fdeefed0b80 (patch)
tree33aa23ddf7f18ddbfba3d006041c460de88583b7 /spec
parentf4186a753b86625a83e8499af14b5badd63a2ac2 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/projects/pipelines_controller_spec.rb37
-rw-r--r--spec/controllers/repositories/git_http_controller_spec.rb38
-rw-r--r--spec/features/projects/snippets/user_updates_snippet_spec.rb25
-rw-r--r--spec/features/snippets/user_edits_snippet_spec.rb19
-rw-r--r--spec/fixtures/api/schemas/remote_mirror.json5
-rw-r--r--spec/lib/gitlab/git_access_snippet_spec.rb7
-rw-r--r--spec/requests/api/internal/base_spec.rb28
-rw-r--r--spec/requests/api/projects_spec.rb60
-rw-r--r--spec/requests/api/remote_mirrors_spec.rb25
-rw-r--r--spec/services/snippets/update_service_spec.rb4
10 files changed, 225 insertions, 23 deletions
diff --git a/spec/controllers/projects/pipelines_controller_spec.rb b/spec/controllers/projects/pipelines_controller_spec.rb
index fd33f32e877..71bb256cee9 100644
--- a/spec/controllers/projects/pipelines_controller_spec.rb
+++ b/spec/controllers/projects/pipelines_controller_spec.rb
@@ -38,9 +38,9 @@ describe Projects::PipelinesController do
expect(response).to match_response_schema('pipeline')
expect(json_response).to include('pipelines')
- expect(json_response['pipelines'].count).to eq 5
- expect(json_response['count']['all']).to eq '5'
- expect(json_response['count']['running']).to eq '1'
+ expect(json_response['pipelines'].count).to eq 6
+ expect(json_response['count']['all']).to eq '6'
+ expect(json_response['count']['running']).to eq '2'
expect(json_response['count']['pending']).to eq '1'
expect(json_response['count']['finished']).to eq '3'
@@ -61,7 +61,7 @@ describe Projects::PipelinesController do
# There appears to be one extra query for Pipelines#has_warnings? for some reason
expect { get_pipelines_index_json }.not_to exceed_query_limit(control_count + 1)
expect(response).to have_gitlab_http_status(:ok)
- expect(json_response['pipelines'].count).to eq 10
+ expect(json_response['pipelines'].count).to eq 12
end
end
@@ -77,9 +77,9 @@ describe Projects::PipelinesController do
expect(response).to match_response_schema('pipeline')
expect(json_response).to include('pipelines')
- expect(json_response['pipelines'].count).to eq 5
- expect(json_response['count']['all']).to eq '5'
- expect(json_response['count']['running']).to eq '1'
+ expect(json_response['pipelines'].count).to eq 6
+ expect(json_response['count']['all']).to eq '6'
+ expect(json_response['count']['running']).to eq '2'
expect(json_response['count']['pending']).to eq '1'
expect(json_response['count']['finished']).to eq '3'
@@ -99,8 +99,9 @@ describe Projects::PipelinesController do
# There appears to be one extra query for Pipelines#has_warnings? for some reason
expect { get_pipelines_index_json }.not_to exceed_query_limit(control_count + 1)
+
expect(response).to have_gitlab_http_status(:ok)
- expect(json_response['pipelines'].count).to eq 10
+ expect(json_response['pipelines'].count).to eq 12
end
end
@@ -139,7 +140,7 @@ describe Projects::PipelinesController do
it 'returns the pipelines when the user has access' do
get_pipelines_index_json
- expect(json_response['pipelines'].size).to eq(5)
+ expect(json_response['pipelines'].size).to eq(6)
end
end
@@ -155,18 +156,32 @@ describe Projects::PipelinesController do
%w(pending running success failed canceled).each_with_index do |status, index|
create_pipeline(status, project.commit("HEAD~#{index}"))
end
+
+ create_pipeline_with_merge_request
end
- def create_pipeline(status, sha)
+ def create_pipeline_with_merge_request
+ # New merge requests must be created with different branches, so
+ # let's just create new ones with random names.
+ branch_name = "test-#{SecureRandom.hex}"
+ project.repository.create_branch(branch_name, project.repository.root_ref)
+ mr = create(:merge_request, source_project: project, target_project: project, source_branch: branch_name)
+ create_pipeline(:running, project.commit('HEAD'), merge_request: mr)
+ end
+
+ def create_pipeline(status, sha, merge_request: nil)
user = create(:user)
pipeline = create(:ci_empty_pipeline, status: status,
project: project,
sha: sha,
- user: user)
+ user: user,
+ merge_request: merge_request)
create_build(pipeline, 'build', 1, 'build', user)
create_build(pipeline, 'test', 2, 'test', user)
create_build(pipeline, 'deploy', 3, 'deploy', user)
+
+ pipeline
end
def create_build(pipeline, stage, stage_idx, name, user = nil)
diff --git a/spec/controllers/repositories/git_http_controller_spec.rb b/spec/controllers/repositories/git_http_controller_spec.rb
index 2573fdf16ff..005db748e91 100644
--- a/spec/controllers/repositories/git_http_controller_spec.rb
+++ b/spec/controllers/repositories/git_http_controller_spec.rb
@@ -135,6 +135,38 @@ describe Repositories::GitHttpController do
end
end
+ shared_examples 'snippet feature flag disabled behavior' do
+ before do
+ stub_feature_flags(version_snippets: false)
+
+ request.headers.merge! auth_env(user.username, user.password, nil)
+ end
+
+ describe 'GET #info_refs' do
+ let(:params) { container_params.merge(service: 'git-upload-pack') }
+
+ it 'returns 404' do
+ get :info_refs, params: params
+
+ expect(response).to have_gitlab_http_status(:not_found)
+ end
+ end
+
+ describe 'POST #git_upload_pack' do
+ before do
+ allow(controller).to receive(:authenticate_user).and_return(true)
+ allow(controller).to receive(:verify_workhorse_api!).and_return(true)
+ allow(controller).to receive(:access_check).and_return(nil)
+ end
+
+ it 'returns 404' do
+ post :git_upload_pack, params: params
+
+ expect(response).to have_gitlab_http_status(:not_found)
+ end
+ end
+ end
+
context 'when repository container is a project' do
it_behaves_like 'info_refs behavior' do
let(:user) { project.owner }
@@ -158,6 +190,9 @@ describe Repositories::GitHttpController do
let(:expected_class) { Gitlab::GitAccessSnippet }
let(:expected_object) { personal_snippet }
end
+ it_behaves_like 'snippet feature flag disabled behavior' do
+ let(:user) { personal_snippet.author }
+ end
end
context 'when repository container is a project snippet' do
@@ -172,5 +207,8 @@ describe Repositories::GitHttpController do
let(:expected_class) { Gitlab::GitAccessSnippet }
let(:expected_object) { project_snippet }
end
+ it_behaves_like 'snippet feature flag disabled behavior' do
+ let(:user) { project_snippet.author }
+ end
end
end
diff --git a/spec/features/projects/snippets/user_updates_snippet_spec.rb b/spec/features/projects/snippets/user_updates_snippet_spec.rb
index 93a5b4a7262..0c3438575ba 100644
--- a/spec/features/projects/snippets/user_updates_snippet_spec.rb
+++ b/spec/features/projects/snippets/user_updates_snippet_spec.rb
@@ -3,9 +3,9 @@
require 'spec_helper'
describe 'Projects > Snippets > User updates a snippet' do
- let(:project) { create(:project) }
+ let_it_be(:user) { create(:user) }
+ let_it_be(:project) { create(:project, namespace: user.namespace) }
let!(:snippet) { create(:project_snippet, project: project, author: user) }
- let(:user) { create(:user) }
before do
stub_feature_flags(snippets_vue: false)
@@ -13,16 +13,33 @@ describe 'Projects > Snippets > User updates a snippet' do
sign_in(user)
visit(project_snippet_path(project, snippet))
- end
- it 'updates a snippet' do
page.within('.detail-page-header') do
first(:link, 'Edit').click
end
+ end
+ it 'updates a snippet' do
fill_in('project_snippet_title', with: 'Snippet new title')
click_button('Save')
expect(page).to have_content('Snippet new title')
end
+
+ context 'when the git operation fails' do
+ before do
+ allow_next_instance_of(Snippets::UpdateService) do |instance|
+ allow(instance).to receive(:create_commit).and_raise(StandardError)
+ end
+
+ fill_in('project_snippet_title', with: 'Snippet new title')
+
+ click_button('Save')
+ end
+
+ it 'renders edit page and displays the error' do
+ expect(page).to have_content('Error updating the snippet')
+ expect(page).to have_content('Edit Snippet')
+ end
+ end
end
diff --git a/spec/features/snippets/user_edits_snippet_spec.rb b/spec/features/snippets/user_edits_snippet_spec.rb
index 1d26660a4f6..706758164b2 100644
--- a/spec/features/snippets/user_edits_snippet_spec.rb
+++ b/spec/features/snippets/user_edits_snippet_spec.rb
@@ -8,7 +8,7 @@ describe 'User edits snippet', :js do
let(:file_name) { 'test.rb' }
let(:content) { 'puts "test"' }
- let(:user) { create(:user) }
+ let_it_be(:user) { create(:user) }
let(:snippet) { create(:personal_snippet, :public, file_name: file_name, content: content, author: user) }
before do
@@ -58,4 +58,21 @@ describe 'User edits snippet', :js do
expect(page).to have_no_xpath("//i[@class='fa fa-lock']")
expect(page).to have_xpath("//i[@class='fa fa-globe']")
end
+
+ context 'when the git operation fails' do
+ before do
+ allow_next_instance_of(Snippets::UpdateService) do |instance|
+ allow(instance).to receive(:create_commit).and_raise(StandardError)
+ end
+
+ fill_in 'personal_snippet_title', with: 'New Snippet Title'
+
+ click_button('Save changes')
+ end
+
+ it 'renders edit page and displays the error' do
+ expect(page).to have_content('Error updating the snippet')
+ expect(page).to have_content('Edit Snippet')
+ end
+ end
end
diff --git a/spec/fixtures/api/schemas/remote_mirror.json b/spec/fixtures/api/schemas/remote_mirror.json
index 416b0f080d9..87bde189db5 100644
--- a/spec/fixtures/api/schemas/remote_mirror.json
+++ b/spec/fixtures/api/schemas/remote_mirror.json
@@ -10,7 +10,7 @@
"last_successful_update_at",
"last_error",
"only_protected_branches"
- ],
+ ],
"properties": {
"id": { "type": "integer" },
"enabled": { "type": "boolean" },
@@ -20,7 +20,8 @@
"last_update_started_at": { "type": ["string", "null"] },
"last_successful_update_at": { "type": ["string", "null"] },
"last_error": { "type": ["string", "null"] },
- "only_protected_branches": { "type": "boolean" }
+ "only_protected_branches": { "type": "boolean" },
+ "keep_divergent_refs": { "type": ["boolean", "null"] }
},
"additionalProperties": false
}
diff --git a/spec/lib/gitlab/git_access_snippet_spec.rb b/spec/lib/gitlab/git_access_snippet_spec.rb
index a68ac8ee8fe..ba7b7da7e7d 100644
--- a/spec/lib/gitlab/git_access_snippet_spec.rb
+++ b/spec/lib/gitlab/git_access_snippet_spec.rb
@@ -31,12 +31,15 @@ describe Gitlab::GitAccessSnippet do
end
describe 'when feature flag :version_snippets is disabled' do
+ let(:user) { snippet.author }
+
before do
stub_feature_flags(version_snippets: false)
end
- it 'does not allow push and pull access' do
- expect { pull_access_check }.to raise_project_not_found
+ it 'allows push and pull access' do
+ expect { pull_access_check }.not_to raise_error
+ expect { push_access_check }.not_to raise_error
end
end
diff --git a/spec/requests/api/internal/base_spec.rb b/spec/requests/api/internal/base_spec.rb
index 1f20a088e4f..95513776f39 100644
--- a/spec/requests/api/internal/base_spec.rb
+++ b/spec/requests/api/internal/base_spec.rb
@@ -315,6 +315,18 @@ describe API::Internal::Base do
end
end
+ shared_examples 'snippets with disabled feature flag' do
+ context 'when feature flag :version_snippets is disabled' do
+ it 'returns 404' do
+ stub_feature_flags(version_snippets: false)
+
+ subject
+
+ expect(response).to have_gitlab_http_status(:not_found)
+ end
+ end
+ end
+
context 'git push with personal snippet' do
it 'responds with success' do
push(key, personal_snippet)
@@ -325,6 +337,10 @@ describe API::Internal::Base do
expect(json_response["gl_repository"]).to eq("snippet-#{personal_snippet.id}")
expect(user.reload.last_activity_on).to be_nil
end
+
+ it_behaves_like 'snippets with disabled feature flag' do
+ subject { push(key, personal_snippet) }
+ end
end
context 'git pull with personal snippet' do
@@ -337,6 +353,10 @@ describe API::Internal::Base do
expect(json_response["gl_repository"]).to eq("snippet-#{personal_snippet.id}")
expect(user.reload.last_activity_on).to eql(Date.today)
end
+
+ it_behaves_like 'snippets with disabled feature flag' do
+ subject { pull(key, personal_snippet) }
+ end
end
context 'git push with project snippet' do
@@ -349,6 +369,10 @@ describe API::Internal::Base do
expect(json_response["gl_repository"]).to eq("snippet-#{project_snippet.id}")
expect(user.reload.last_activity_on).to be_nil
end
+
+ it_behaves_like 'snippets with disabled feature flag' do
+ subject { push(key, project_snippet) }
+ end
end
context 'git pull with project snippet' do
@@ -361,6 +385,10 @@ describe API::Internal::Base do
expect(json_response["gl_repository"]).to eq("snippet-#{project_snippet.id}")
expect(user.reload.last_activity_on).to eql(Date.today)
end
+
+ it_behaves_like 'snippets with disabled feature flag' do
+ subject { pull(key, project_snippet) }
+ end
end
context "git pull" do
diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb
index 858fdc783ee..1e8ab983b50 100644
--- a/spec/requests/api/projects_spec.rb
+++ b/spec/requests/api/projects_spec.rb
@@ -2871,6 +2871,66 @@ describe API::Projects do
expect(json_response['namespace']['name']).to eq(group2.name)
end
+ context 'when namespace_id is specified' do
+ shared_examples_for 'forking to specified namespace_id' do
+ it 'forks to specified namespace_id' do
+ expect(response).to have_gitlab_http_status(:created)
+ expect(json_response['owner']['id']).to eq(user2.id)
+ expect(json_response['namespace']['id']).to eq(user2.namespace.id)
+ end
+ end
+
+ context 'and namespace_id is specified alone' do
+ before do
+ post api("/projects/#{project.id}/fork", user2), params: { namespace_id: user2.namespace.id }
+ end
+
+ it_behaves_like 'forking to specified namespace_id'
+ end
+
+ context 'and namespace_id and namespace are both specified' do
+ before do
+ post api("/projects/#{project.id}/fork", user2), params: { namespace_id: user2.namespace.id, namespace: admin.namespace.id }
+ end
+
+ it_behaves_like 'forking to specified namespace_id'
+ end
+
+ context 'and namespace_id and namespace_path are both specified' do
+ before do
+ post api("/projects/#{project.id}/fork", user2), params: { namespace_id: user2.namespace.id, namespace_path: admin.namespace.path }
+ end
+
+ it_behaves_like 'forking to specified namespace_id'
+ end
+ end
+
+ context 'when namespace_path is specified' do
+ shared_examples_for 'forking to specified namespace_path' do
+ it 'forks to specified namespace_path' do
+ expect(response).to have_gitlab_http_status(:created)
+ expect(json_response['owner']['id']).to eq(user2.id)
+ expect(json_response['namespace']['path']).to eq(user2.namespace.path)
+ end
+ end
+
+ context 'and namespace_path is specified alone' do
+ before do
+ post api("/projects/#{project.id}/fork", user2), params: { namespace_path: user2.namespace.path }
+ end
+
+ it_behaves_like 'forking to specified namespace_path'
+ end
+
+ context 'and namespace_path and namespace are both specified' do
+ before do
+ post api("/projects/#{project.id}/fork", user2), params: { namespace_path: user2.namespace.path, namespace: admin.namespace.path }
+ end
+
+ it_behaves_like 'forking to specified namespace_path'
+ end
+ end
+
it 'forks to owned subgroup' do
full_path = "#{group2.path}/#{group3.path}"
post api("/projects/#{project.id}/fork", user2), params: { namespace: full_path }
diff --git a/spec/requests/api/remote_mirrors_spec.rb b/spec/requests/api/remote_mirrors_spec.rb
index 2186fe375ac..5b5188e024c 100644
--- a/spec/requests/api/remote_mirrors_spec.rb
+++ b/spec/requests/api/remote_mirrors_spec.rb
@@ -91,6 +91,10 @@ describe API::RemoteMirrors do
let(:route) { ->(id) { "/projects/#{project.id}/remote_mirrors/#{id}" } }
let(:mirror) { project.remote_mirrors.first }
+ before do
+ stub_feature_flags(keep_divergent_refs: false)
+ end
+
it 'requires `admin_remote_mirror` permission' do
put api(route[mirror.id], developer)
@@ -102,12 +106,31 @@ describe API::RemoteMirrors do
put api(route[mirror.id], user), params: {
enabled: '0',
- only_protected_branches: 'true'
+ only_protected_branches: 'true',
+ keep_divergent_refs: 'true'
}
expect(response).to have_gitlab_http_status(:success)
expect(json_response['enabled']).to eq(false)
expect(json_response['only_protected_branches']).to eq(true)
+
+ # Deleted due to lack of feature availability
+ expect(json_response['keep_divergent_refs']).to be_nil
+ end
+
+ context 'with the `keep_divergent_refs` feature enabled' do
+ before do
+ stub_feature_flags(keep_divergent_refs: { enabled: true, project: project })
+ end
+
+ it 'updates the `keep_divergent_refs` attribute' do
+ project.add_maintainer(user)
+
+ put api(route[mirror.id], user), params: { keep_divergent_refs: 'true' }
+
+ expect(response).to have_gitlab_http_status(:success)
+ expect(json_response['keep_divergent_refs']).to eq(true)
+ end
end
# TODO: Remove flag: https://gitlab.com/gitlab-org/gitlab/issues/38121
diff --git a/spec/services/snippets/update_service_spec.rb b/spec/services/snippets/update_service_spec.rb
index 2c70cce767d..3605d3f76da 100644
--- a/spec/services/snippets/update_service_spec.rb
+++ b/spec/services/snippets/update_service_spec.rb
@@ -148,7 +148,7 @@ describe Snippets::UpdateService do
response = subject
expect(response).to be_error
- expect(response.payload[:snippet].errors.full_messages).to eq ['Error updating the snippet']
+ expect(response.payload[:snippet].errors.full_messages).to eq ['Repository Error updating the snippet']
end
end
@@ -173,7 +173,7 @@ describe Snippets::UpdateService do
response = subject
expect(response).to be_error
- expect(response.payload[:snippet].errors.full_messages).to eq ['Error updating the snippet']
+ expect(response.payload[:snippet].errors.full_messages).to eq ['Repository Error updating the snippet']
end
it 'returns error if snippet does not have a snippet_repository' do