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
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-10-11 21:06:15 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2019-10-11 21:06:15 +0300
commit0dfbcd8f8b1587a7e10eb79940a8dc13bd72c664 (patch)
tree769b7b5eaea4354498ca0b91945e4733895bba43 /spec/services
parentcd631619f465a0eee2fe714e720f6b6312dd3e56 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/services')
-rw-r--r--spec/services/git/process_ref_changes_service_spec.rb105
-rw-r--r--spec/services/issues/update_service_spec.rb4
-rw-r--r--spec/services/merge_requests/update_service_spec.rb4
-rw-r--r--spec/services/notes/update_service_spec.rb94
4 files changed, 193 insertions, 14 deletions
diff --git a/spec/services/git/process_ref_changes_service_spec.rb b/spec/services/git/process_ref_changes_service_spec.rb
new file mode 100644
index 00000000000..4d394a29867
--- /dev/null
+++ b/spec/services/git/process_ref_changes_service_spec.rb
@@ -0,0 +1,105 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Git::ProcessRefChangesService do
+ let(:project) { create(:project, :repository) }
+ let(:user) { project.owner }
+ let(:params) { { changes: git_changes } }
+
+ subject { described_class.new(project, user, params) }
+
+ shared_examples_for 'service for processing ref changes' do |push_service_class|
+ let(:service) { double(execute: true) }
+ let(:git_changes) { double(branch_changes: [], tag_changes: []) }
+
+ let(:changes) do
+ [
+ { index: 0, oldrev: Gitlab::Git::BLANK_SHA, newrev: '789012', ref: "#{ref_prefix}/create" },
+ { index: 1, oldrev: '123456', newrev: '789012', ref: "#{ref_prefix}/update" },
+ { index: 2, oldrev: '123456', newrev: Gitlab::Git::BLANK_SHA, ref: "#{ref_prefix}/delete" }
+ ]
+ end
+
+ before do
+ allow(git_changes).to receive(changes_method).and_return(changes)
+ end
+
+ it "calls #{push_service_class}" do
+ expect(push_service_class)
+ .to receive(:new)
+ .exactly(changes.count).times
+ .and_return(service)
+
+ subject.execute
+ end
+
+ context 'pipeline creation' do
+ context 'with valid .gitlab-ci.yml' do
+ before do
+ stub_ci_pipeline_to_return_yaml_file
+
+ allow_any_instance_of(Project)
+ .to receive(:commit)
+ .and_return(project.commit)
+
+ allow_any_instance_of(Repository)
+ .to receive(:branch_exists?)
+ .and_return(true)
+ end
+
+ context 'when git_push_create_all_pipelines is disabled' do
+ before do
+ stub_feature_flags(git_push_create_all_pipelines: false)
+ end
+
+ it 'creates pipeline for branches and tags' do
+ subject.execute
+
+ expect(Ci::Pipeline.pluck(:ref)).to contain_exactly('create', 'update', 'delete')
+ end
+
+ it "creates exactly #{described_class::PIPELINE_PROCESS_LIMIT} pipelines" do
+ stub_const("#{described_class}::PIPELINE_PROCESS_LIMIT", changes.count - 1)
+
+ expect { subject.execute }.to change { Ci::Pipeline.count }.by(described_class::PIPELINE_PROCESS_LIMIT)
+ end
+ end
+
+ context 'when git_push_create_all_pipelines is enabled' do
+ before do
+ stub_feature_flags(git_push_create_all_pipelines: true)
+ end
+
+ it 'creates all pipelines' do
+ expect { subject.execute }.to change { Ci::Pipeline.count }.by(changes.count)
+ end
+ end
+ end
+
+ context 'with invalid .gitlab-ci.yml' do
+ before do
+ stub_ci_pipeline_yaml_file(nil)
+ end
+
+ it 'does not create a pipeline' do
+ expect { subject.execute }.not_to change { Ci::Pipeline.count }
+ end
+ end
+ end
+ end
+
+ context 'branch changes' do
+ let(:changes_method) { :branch_changes }
+ let(:ref_prefix) { 'refs/heads' }
+
+ it_behaves_like 'service for processing ref changes', Git::BranchPushService
+ end
+
+ context 'tag changes' do
+ let(:changes_method) { :tag_changes }
+ let(:ref_prefix) { 'refs/tags' }
+
+ it_behaves_like 'service for processing ref changes', Git::TagPushService
+ end
+end
diff --git a/spec/services/issues/update_service_spec.rb b/spec/services/issues/update_service_spec.rb
index 55254b61ac8..154bfec0da2 100644
--- a/spec/services/issues/update_service_spec.rb
+++ b/spec/services/issues/update_service_spec.rb
@@ -6,7 +6,8 @@ describe Issues::UpdateService, :mailer do
let(:user) { create(:user) }
let(:user2) { create(:user) }
let(:user3) { create(:user) }
- let(:project) { create(:project) }
+ let(:group) { create(:group, :public) }
+ let(:project) { create(:project, :repository, group: group) }
let(:label) { create(:label, project: project) }
let(:label2) { create(:label) }
@@ -667,6 +668,7 @@ describe Issues::UpdateService, :mailer do
context 'updating mentions' do
let(:mentionable) { issue }
+
include_examples 'updating mentions', described_class
end
diff --git a/spec/services/merge_requests/update_service_spec.rb b/spec/services/merge_requests/update_service_spec.rb
index 9688e02d6ac..d3c4c436901 100644
--- a/spec/services/merge_requests/update_service_spec.rb
+++ b/spec/services/merge_requests/update_service_spec.rb
@@ -5,7 +5,8 @@ require 'spec_helper'
describe MergeRequests::UpdateService, :mailer do
include ProjectForksHelper
- let(:project) { create(:project, :repository) }
+ let(:group) { create(:group, :public) }
+ let(:project) { create(:project, :repository, group: group) }
let(:user) { create(:user) }
let(:user2) { create(:user) }
let(:user3) { create(:user) }
@@ -472,6 +473,7 @@ describe MergeRequests::UpdateService, :mailer do
context 'updating mentions' do
let(:mentionable) { merge_request }
+
include_examples 'updating mentions', described_class
end
diff --git a/spec/services/notes/update_service_spec.rb b/spec/services/notes/update_service_spec.rb
index 717eb97fa5a..73fcdd787aa 100644
--- a/spec/services/notes/update_service_spec.rb
+++ b/spec/services/notes/update_service_spec.rb
@@ -3,17 +3,25 @@
require 'spec_helper'
describe Notes::UpdateService do
- let(:project) { create(:project) }
+ let(:group) { create(:group, :public) }
+ let(:project) { create(:project, :public, group: group) }
+ let(:private_group) { create(:group, :private) }
+ let(:private_project) { create(:project, :private, group: private_group) }
let(:user) { create(:user) }
let(:user2) { create(:user) }
let(:user3) { create(:user) }
let(:issue) { create(:issue, project: project) }
+ let(:issue2) { create(:issue, project: private_project) }
let(:note) { create(:note, project: project, noteable: issue, author: user, note: "Old note #{user2.to_reference}") }
before do
project.add_maintainer(user)
project.add_developer(user2)
project.add_developer(user3)
+ group.add_developer(user3)
+ private_group.add_developer(user)
+ private_group.add_developer(user2)
+ private_project.add_developer(user3)
end
describe '#execute' do
@@ -46,13 +54,17 @@ describe Notes::UpdateService do
end
context 'todos' do
- let!(:todo) { create(:todo, :assigned, user: user, project: project, target: issue, author: user2) }
+ shared_examples 'does not update todos' do
+ it 'keep todos' do
+ expect(todo.reload).to be_pending
+ end
- context 'when the note change' do
- before do
- update_note({ note: "New note #{user2.to_reference} #{user3.to_reference}" })
+ it 'does not create any new todos' do
+ expect(Todo.count).to eq(1)
end
+ end
+ shared_examples 'creates one todo' do
it 'marks todos as done' do
expect(todo.reload).to be_done
end
@@ -62,17 +74,75 @@ describe Notes::UpdateService do
end
end
- context 'when the note does not change' do
- before do
- update_note({ note: "Old note #{user2.to_reference}" })
+ context 'when note includes a user mention' do
+ let!(:todo) { create(:todo, :assigned, user: user, project: project, target: issue, author: user2) }
+
+ context 'when the note does not change mentions' do
+ before do
+ update_note({ note: "Old note #{user2.to_reference}" })
+ end
+
+ it_behaves_like 'does not update todos'
end
- it 'keep todos' do
- expect(todo.reload).to be_pending
+ context 'when the note changes to include one more user mention' do
+ before do
+ update_note({ note: "New note #{user2.to_reference} #{user3.to_reference}" })
+ end
+
+ it_behaves_like 'creates one todo'
end
- it 'does not create any new todos' do
- expect(Todo.count).to eq(1)
+ context 'when the note changes to include a group mentions' do
+ before do
+ update_note({ note: "New note #{private_group.to_reference}" })
+ end
+
+ it_behaves_like 'creates one todo'
+ end
+ end
+
+ context 'when note includes a group mention' do
+ context 'when the group is public' do
+ let(:note) { create(:note, project: project, noteable: issue, author: user, note: "Old note #{group.to_reference}") }
+ let!(:todo) { create(:todo, :assigned, user: user, project: project, target: issue, author: user2) }
+
+ context 'when the note does not change mentions' do
+ before do
+ update_note({ note: "Old note #{group.to_reference}" })
+ end
+
+ it_behaves_like 'does not update todos'
+ end
+
+ context 'when the note changes mentions' do
+ before do
+ update_note({ note: "New note #{user2.to_reference} #{user3.to_reference}" })
+ end
+
+ it_behaves_like 'creates one todo'
+ end
+ end
+
+ context 'when the group is private' do
+ let(:note) { create(:note, project: project, noteable: issue, author: user, note: "Old note #{private_group.to_reference}") }
+ let!(:todo) { create(:todo, :assigned, user: user, project: project, target: issue, author: user2) }
+
+ context 'when the note does not change mentions' do
+ before do
+ update_note({ note: "Old note #{private_group.to_reference}" })
+ end
+
+ it_behaves_like 'does not update todos'
+ end
+
+ context 'when the note changes mentions' do
+ before do
+ update_note({ note: "New note #{user2.to_reference} #{user3.to_reference}" })
+ end
+
+ it_behaves_like 'creates one todo'
+ end
end
end
end