Skip to content
Snippets Groups Projects
Commit ab7cf450 authored by GitLab Bot's avatar GitLab Bot
Browse files

Add latest changes from gitlab-org/gitlab@master

parent 4204cf30
No related branches found
No related tags found
No related merge requests found
Showing
with 158 additions and 17 deletions
Loading
Loading
@@ -2,7 +2,7 @@
 
require 'spec_helper'
 
describe DeleteMergedBranchesService do
describe Branches::DeleteMergedService do
include ProjectForksHelper
 
subject(:service) { described_class.new(project, project.owner) }
Loading
Loading
Loading
Loading
@@ -2,11 +2,11 @@
 
require 'spec_helper'
 
describe DeleteBranchService do
describe Branches::DeleteService do
let(:project) { create(:project, :repository) }
let(:repository) { project.repository }
let(:user) { create(:user) }
let(:service) { described_class.new(project, user) }
subject(:service) { described_class.new(project, user) }
 
shared_examples 'a deleted branch' do |branch_name|
it 'removes the branch' do
Loading
Loading
# frozen_string_literal: true
require 'spec_helper'
describe Branches::ValidateNewService do
let(:project) { create(:project, :repository) }
subject(:service) { described_class.new(project) }
describe '#execute' do
context 'validation' do
it 'returns error with an invalid branch name' do
result = service.execute('refs/heads/invalid_branch')
expect(result[:status]).to eq(:error)
expect(result[:message]).to eq('Branch name is invalid')
end
it 'returns success with a valid branch name' do
result = service.execute('valid_branch_name')
expect(result[:status]).to eq(:success)
end
end
context 'branch exist' do
it 'returns error when branch exists' do
result = service.execute('master')
expect(result[:status]).to eq(:error)
expect(result[:message]).to eq('Branch already exists')
end
it 'returns success when branch name is available' do
result = service.execute('valid_branch_name')
expect(result[:status]).to eq(:success)
end
end
end
end
Loading
Loading
@@ -22,7 +22,7 @@ describe Clusters::Kubernetes::CreateOrUpdateNamespaceService, '#execute' do
 
before do
stub_kubeclient_discover(api_url)
stub_kubeclient_get_namespace(api_url)
stub_kubeclient_get_namespaces(api_url)
stub_kubeclient_get_service_account_error(api_url, 'gitlab')
stub_kubeclient_create_service_account(api_url)
stub_kubeclient_get_secret_error(api_url, 'gitlab-token')
Loading
Loading
@@ -39,6 +39,8 @@ describe Clusters::Kubernetes::CreateOrUpdateNamespaceService, '#execute' do
stub_kubeclient_put_role_binding(api_url, Clusters::Kubernetes::GITLAB_KNATIVE_SERVING_ROLE_BINDING_NAME, namespace: namespace)
stub_kubeclient_put_role(api_url, Clusters::Kubernetes::GITLAB_CROSSPLANE_DATABASE_ROLE_NAME, namespace: namespace)
stub_kubeclient_put_role_binding(api_url, Clusters::Kubernetes::GITLAB_CROSSPLANE_DATABASE_ROLE_BINDING_NAME, namespace: namespace)
stub_kubeclient_put_cluster_role(api_url, Clusters::Kubernetes::GITLAB_KNATIVE_VERSION_ROLE_NAME)
stub_kubeclient_put_cluster_role_binding(api_url, Clusters::Kubernetes::GITLAB_KNATIVE_VERSION_ROLE_BINDING_NAME)
 
stub_kubeclient_get_secret(
api_url,
Loading
Loading
Loading
Loading
@@ -141,12 +141,15 @@ describe Clusters::Kubernetes::CreateOrUpdateServiceAccountService do
before do
cluster.platform_kubernetes.rbac!
 
stub_kubeclient_get_namespaces(api_url)
stub_kubeclient_get_role_binding_error(api_url, role_binding_name, namespace: namespace)
stub_kubeclient_create_role_binding(api_url, namespace: namespace)
stub_kubeclient_put_role(api_url, Clusters::Kubernetes::GITLAB_KNATIVE_SERVING_ROLE_NAME, namespace: namespace)
stub_kubeclient_put_role_binding(api_url, Clusters::Kubernetes::GITLAB_KNATIVE_SERVING_ROLE_BINDING_NAME, namespace: namespace)
stub_kubeclient_put_role(api_url, Clusters::Kubernetes::GITLAB_CROSSPLANE_DATABASE_ROLE_NAME, namespace: namespace)
stub_kubeclient_put_role_binding(api_url, Clusters::Kubernetes::GITLAB_CROSSPLANE_DATABASE_ROLE_BINDING_NAME, namespace: namespace)
stub_kubeclient_put_cluster_role(api_url, Clusters::Kubernetes::GITLAB_KNATIVE_VERSION_ROLE_NAME)
stub_kubeclient_put_cluster_role_binding(api_url, Clusters::Kubernetes::GITLAB_KNATIVE_VERSION_ROLE_BINDING_NAME)
end
 
it_behaves_like 'creates service account and token'
Loading
Loading
@@ -234,6 +237,30 @@ describe Clusters::Kubernetes::CreateOrUpdateServiceAccountService do
)
)
end
it 'creates a role and role binding granting the ability to get the version of deployments in knative-serving namespace' do
subject
expect(WebMock).to have_requested(:put, api_url + "/apis/rbac.authorization.k8s.io/v1/clusterrolebindings/#{Clusters::Kubernetes::GITLAB_KNATIVE_VERSION_ROLE_BINDING_NAME}").with(
body: hash_including(
metadata: {
name: Clusters::Kubernetes::GITLAB_KNATIVE_VERSION_ROLE_BINDING_NAME
},
roleRef: {
apiGroup: "rbac.authorization.k8s.io",
kind: "ClusterRole",
name: Clusters::Kubernetes::GITLAB_KNATIVE_VERSION_ROLE_NAME
},
subjects: [
{
kind: "ServiceAccount",
name: service_account_name,
namespace: namespace
}
]
)
)
end
end
end
end
Loading
Loading
@@ -211,7 +211,8 @@ describe MergeRequests::MergeService do
end
 
it 'does not delete the source branch' do
expect(DeleteBranchService).not_to receive(:new)
expect(::Branches::DeleteService).not_to receive(:new)
service.execute(merge_request)
end
end
Loading
Loading
@@ -226,7 +227,7 @@ describe MergeRequests::MergeService do
end
 
it 'does not delete the source branch' do
expect(DeleteBranchService).not_to receive(:new)
expect(::Branches::DeleteService).not_to receive(:new)
service.execute(merge_request)
end
end
Loading
Loading
@@ -238,7 +239,7 @@ describe MergeRequests::MergeService do
end
 
it 'removes the source branch using the author user' do
expect(DeleteBranchService).to receive(:new)
expect(::Branches::DeleteService).to receive(:new)
.with(merge_request.source_project, merge_request.author)
.and_call_original
service.execute(merge_request)
Loading
Loading
@@ -248,7 +249,7 @@ describe MergeRequests::MergeService do
let(:service) { described_class.new(project, user, merge_params.merge('should_remove_source_branch' => false)) }
 
it 'does not delete the source branch' do
expect(DeleteBranchService).not_to receive(:new)
expect(::Branches::DeleteService).not_to receive(:new)
service.execute(merge_request)
end
end
Loading
Loading
@@ -260,7 +261,7 @@ describe MergeRequests::MergeService do
end
 
it 'removes the source branch using the current user' do
expect(DeleteBranchService).to receive(:new)
expect(::Branches::DeleteService).to receive(:new)
.with(merge_request.source_project, user)
.and_call_original
service.execute(merge_request)
Loading
Loading
Loading
Loading
@@ -61,7 +61,7 @@ describe MergeRequests::MergeToRefService do
end
 
it 'does not delete the source branch' do
expect(DeleteBranchService).not_to receive(:new)
expect(::Branches::DeleteService).not_to receive(:new)
 
process_merge_to_ref
end
Loading
Loading
Loading
Loading
@@ -113,7 +113,7 @@ describe MergeRequests::RefreshService do
 
context 'when source branch ref does not exists' do
before do
DeleteBranchService.new(@project, @user).execute(@merge_request.source_branch)
::Branches::DeleteService.new(@project, @user).execute(@merge_request.source_branch)
end
 
it 'closes MRs without source branch ref' do
Loading
Loading
Loading
Loading
@@ -1015,6 +1015,30 @@ describe TodoService do
end
end
 
describe '#mark_todo_as_done' do
it 'marks a todo done' do
todo1 = create(:todo, :pending, user: john_doe)
described_class.new.mark_todo_as_done(todo1, john_doe)
expect(todo1.reload.state).to eq('done')
end
context 'when todo is already in state done' do
let(:todo1) { create(:todo, :done, user: john_doe) }
it 'does not update the todo' do
expect { described_class.new.mark_todo_as_done(todo1, john_doe) }.not_to change(todo1.reload, :state)
end
it 'does not update cache count' do
expect(john_doe).not_to receive(:update_todos_count_cache)
described_class.new.mark_todo_as_done(todo1, john_doe)
end
end
end
describe '#mark_all_todos_as_done_by_user' do
it 'marks all todos done' do
todo1 = create(:todo, user: john_doe, state: :pending)
Loading
Loading
Loading
Loading
@@ -194,6 +194,11 @@ module KubernetesHelpers
.to_return(kube_response({}))
end
 
def stub_kubeclient_put_cluster_role_binding(api_url, name)
WebMock.stub_request(:put, api_url + "/apis/rbac.authorization.k8s.io/v1/clusterrolebindings/#{name}")
.to_return(kube_response({}))
end
def stub_kubeclient_get_role_binding(api_url, name, namespace: 'default')
WebMock.stub_request(:get, api_url + "/apis/rbac.authorization.k8s.io/v1/namespaces/#{namespace}/rolebindings/#{name}")
.to_return(kube_response({}))
Loading
Loading
@@ -219,11 +224,21 @@ module KubernetesHelpers
.to_return(kube_response({}))
end
 
def stub_kubeclient_get_namespaces(api_url)
WebMock.stub_request(:get, api_url + '/api/v1/namespaces')
.to_return(kube_response(kube_v1_namespace_list_body))
end
def stub_kubeclient_get_namespace(api_url, namespace: 'default')
WebMock.stub_request(:get, api_url + "/api/v1/namespaces/#{namespace}")
.to_return(kube_response({}))
end
 
def stub_kubeclient_put_cluster_role(api_url, name)
WebMock.stub_request(:put, api_url + "/apis/rbac.authorization.k8s.io/v1/clusterroles/#{name}")
.to_return(kube_response({}))
end
def stub_kubeclient_put_role(api_url, name, namespace: 'default')
WebMock.stub_request(:put, api_url + "/apis/rbac.authorization.k8s.io/v1/namespaces/#{namespace}/roles/#{name}")
.to_return(kube_response({}))
Loading
Loading
@@ -257,6 +272,20 @@ module KubernetesHelpers
}
end
 
def kube_v1_namespace_list_body
{
"kind" => "NamespaceList",
"apiVersion" => "v1",
"items" => [
{
"metadata" => {
"name" => "knative-serving"
}
}
]
}
end
def kube_v1beta1_discovery_body
{
"kind" => "APIResourceList",
Loading
Loading
Loading
Loading
@@ -50,7 +50,7 @@ module PositionTracerHelpers
end
 
def create_branch(new_name, branch_name)
CreateBranchService.new(project, current_user).execute(new_name, branch_name)
::Branches::CreateService.new(project, current_user).execute(new_name, branch_name)
end
 
def create_file(branch_name, file_name, content)
Loading
Loading
Loading
Loading
@@ -74,7 +74,7 @@ shared_examples 'handle uploads' do
end
 
before do
expect(FileUploader).to receive(:generate_secret).and_return(secret)
allow(FileUploader).to receive(:generate_secret).and_return(secret)
UploadService.new(model, jpg, uploader_class).execute
end
 
Loading
Loading
@@ -88,6 +88,18 @@ shared_examples 'handle uploads' do
end
end
 
context 'when the upload does not have a MIME type that Rails knows' do
let(:po) { fixture_file_upload('spec/fixtures/missing_metadata.po', 'text/plain') }
it 'falls back to the null type' do
UploadService.new(model, po, uploader_class).execute
get :show, params: params.merge(secret: secret, filename: 'missing_metadata.po')
expect(response.headers['Content-Type']).to eq('application/octet-stream')
end
end
context "when the model is public" do
before do
model.update_attribute(:visibility_level, Gitlab::VisibilityLevel::PUBLIC)
Loading
Loading
Loading
Loading
@@ -8,11 +8,14 @@ RSpec.shared_examples 'a creatable merge request' do
page.within '.dropdown-menu-user' do
click_link user2.name
end
expect(find('input[name="merge_request[assignee_ids][]"]', visible: false).value).to match(user2.id.to_s)
page.within '.js-assignee-search' do
expect(page).to have_content user2.name
end
click_link 'Assign to me'
expect(find('input[name="merge_request[assignee_ids][]"]', visible: false).value).to match(user.id.to_s)
page.within '.js-assignee-search' do
expect(page).to have_content user.name
Loading
Loading
@@ -22,6 +25,7 @@ RSpec.shared_examples 'a creatable merge request' do
page.within '.issue-milestone' do
click_link milestone.title
end
expect(find('input[name="merge_request[milestone_id]"]', visible: false).value).to match(milestone.id.to_s)
page.within '.js-milestone-select' do
expect(page).to have_content milestone.title
Loading
Loading
@@ -32,6 +36,7 @@ RSpec.shared_examples 'a creatable merge request' do
click_link label.title
click_link label2.title
end
page.within '.js-label-select' do
expect(page).to have_content label.title
end
Loading
Loading
@@ -58,8 +63,9 @@ RSpec.shared_examples 'a creatable merge request' do
 
it 'updates the branches when selecting a new target project', :js do
target_project_member = target_project.owner
CreateBranchService.new(target_project, target_project_member)
.execute('a-brand-new-branch-to-test', 'master')
::Branches::CreateService.new(target_project, target_project_member)
.execute('a-brand-new-branch-to-test', 'master')
visit project_new_merge_request_path(source_project)
 
first('.js-target-project').click
Loading
Loading
Loading
Loading
@@ -8,8 +8,8 @@ describe DeleteMergedBranchesWorker do
let(:project) { create(:project, :repository) }
 
describe "#perform" do
it "calls DeleteMergedBranchesService" do
expect_any_instance_of(DeleteMergedBranchesService).to receive(:execute).and_return(true)
it "delegates to Branches::DeleteMergedService" do
expect_any_instance_of(::Branches::DeleteMergedService).to receive(:execute).and_return(true)
 
worker.perform(project.id, project.owner.id)
end
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment