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>2019-10-03 18:07:07 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2019-10-03 18:07:07 +0300
commit9a1c5456747a7b5b218b8b44e4b43396bf7fd705 (patch)
treedc5873f33437c897389e923a59365fb192d87fb8 /spec
parent927cfbfe63dd3dc64df9d341d7c4328a2fe3597f (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/features/projects/environments/environment_spec.rb8
-rw-r--r--spec/lib/gitlab/git/changes_spec.rb81
-rw-r--r--spec/services/git/base_hooks_service_spec.rb3
-rw-r--r--spec/services/git/branch_hooks_service_spec.rb4
-rw-r--r--spec/services/git/branch_push_service_spec.rb96
-rw-r--r--spec/services/git/tag_hooks_service_spec.rb2
-rw-r--r--spec/services/git/tag_push_service_spec.rb2
-rw-r--r--spec/services/issues/close_service_spec.rb11
-rw-r--r--spec/services/merge_requests/post_merge_service_spec.rb6
-rw-r--r--spec/support/helpers/cycle_analytics_helpers.rb14
10 files changed, 164 insertions, 63 deletions
diff --git a/spec/features/projects/environments/environment_spec.rb b/spec/features/projects/environments/environment_spec.rb
index 497880a7835..25823b75d18 100644
--- a/spec/features/projects/environments/environment_spec.rb
+++ b/spec/features/projects/environments/environment_spec.rb
@@ -304,9 +304,11 @@ describe 'Environment' do
#
def remove_branch_with_hooks(project, user, branch)
params = {
- oldrev: project.commit(branch).id,
- newrev: Gitlab::Git::BLANK_SHA,
- ref: "refs/heads/#{branch}"
+ change: {
+ oldrev: project.commit(branch).id,
+ newrev: Gitlab::Git::BLANK_SHA,
+ ref: "refs/heads/#{branch}"
+ }
}
yield
diff --git a/spec/lib/gitlab/git/changes_spec.rb b/spec/lib/gitlab/git/changes_spec.rb
new file mode 100644
index 00000000000..7f56d30cb48
--- /dev/null
+++ b/spec/lib/gitlab/git/changes_spec.rb
@@ -0,0 +1,81 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Gitlab::Git::Changes do
+ let(:changes) { described_class.new }
+
+ describe '#includes_branches?' do
+ subject { changes.includes_branches? }
+
+ context 'has changes for branches' do
+ before do
+ changes.add_branch_change(oldrev: 'abc123', newrev: 'def456', ref: 'branch')
+ end
+
+ it { is_expected.to be_truthy }
+ end
+
+ context 'has no changes for branches' do
+ before do
+ changes.add_tag_change(oldrev: 'abc123', newrev: 'def456', ref: 'tag')
+ end
+
+ it { is_expected.to be_falsey }
+ end
+ end
+
+ describe '#includes_tags?' do
+ subject { changes.includes_tags? }
+
+ context 'has changes for tags' do
+ before do
+ changes.add_tag_change(oldrev: 'abc123', newrev: 'def456', ref: 'tag')
+ end
+
+ it { is_expected.to be_truthy }
+ end
+
+ context 'has no changes for tags' do
+ before do
+ changes.add_branch_change(oldrev: 'abc123', newrev: 'def456', ref: 'branch')
+ end
+
+ it { is_expected.to be_falsey }
+ end
+ end
+
+ describe '#add_branch_change' do
+ let(:change) { { oldrev: 'abc123', newrev: 'def456', ref: 'branch' } }
+
+ subject { changes.add_branch_change(change) }
+
+ it 'adds the branch change to the collection' do
+ expect(subject).to include(change)
+ expect(subject.refs).to include(change[:ref])
+ expect(subject.repository_data).to include(before: change[:oldrev], after: change[:newrev], ref: change[:ref])
+ expect(subject.branch_changes).to include(change)
+ end
+
+ it 'does not add the change as a tag change' do
+ expect(subject.tag_changes).not_to include(change)
+ end
+ end
+
+ describe '#add_tag_change' do
+ let(:change) { { oldrev: 'abc123', newrev: 'def456', ref: 'tag' } }
+
+ subject { changes.add_tag_change(change) }
+
+ it 'adds the tag change to the collection' do
+ expect(subject).to include(change)
+ expect(subject.refs).to include(change[:ref])
+ expect(subject.repository_data).to include(before: change[:oldrev], after: change[:newrev], ref: change[:ref])
+ expect(subject.tag_changes).to include(change)
+ end
+
+ it 'does not add the change as a branch change' do
+ expect(subject.branch_changes).not_to include(change)
+ end
+ end
+end
diff --git a/spec/services/git/base_hooks_service_spec.rb b/spec/services/git/base_hooks_service_spec.rb
index 6dc0353299b..e71900e3c0d 100644
--- a/spec/services/git/base_hooks_service_spec.rb
+++ b/spec/services/git/base_hooks_service_spec.rb
@@ -8,7 +8,6 @@ describe Git::BaseHooksService do
let(:user) { create(:user) }
let(:project) { create(:project, :repository) }
- let(:service) { described_class.new(project, user, oldrev: oldrev, newrev: newrev, ref: ref) }
let(:oldrev) { Gitlab::Git::BLANK_SHA }
let(:newrev) { "8a2a6eb295bb170b34c24c76c49ed0e9b2eaf34b" } # gitlab-test: git rev-parse refs/tags/v1.1.0
@@ -27,7 +26,7 @@ describe Git::BaseHooksService do
let(:project) { create(:project, :repository) }
- subject { TestService.new(project, user, oldrev: oldrev, newrev: newrev, ref: ref) }
+ subject { TestService.new(project, user, change: { oldrev: oldrev, newrev: newrev, ref: ref }) }
context '#execute_hooks' do
before do
diff --git a/spec/services/git/branch_hooks_service_spec.rb b/spec/services/git/branch_hooks_service_spec.rb
index 206b87fb889..085b49f31ab 100644
--- a/spec/services/git/branch_hooks_service_spec.rb
+++ b/spec/services/git/branch_hooks_service_spec.rb
@@ -16,7 +16,7 @@ describe Git::BranchHooksService do
let(:newrev) { commit.id }
let(:service) do
- described_class.new(project, user, oldrev: oldrev, newrev: newrev, ref: ref)
+ described_class.new(project, user, change: { oldrev: oldrev, newrev: newrev, ref: ref })
end
describe "Git Push Data" do
@@ -350,7 +350,7 @@ describe Git::BranchHooksService do
let(:forked_project) { fork_project(upstream_project, user, repository: true) }
let!(:forked_service) do
- described_class.new(forked_project, user, oldrev: oldrev, newrev: newrev, ref: ref)
+ described_class.new(forked_project, user, change: { oldrev: oldrev, newrev: newrev, ref: ref })
end
context 'when commits already exists in the upstream project' do
diff --git a/spec/services/git/branch_push_service_spec.rb b/spec/services/git/branch_push_service_spec.rb
index f4d1a1e34cd..bf68eb0af20 100644
--- a/spec/services/git/branch_push_service_spec.rb
+++ b/spec/services/git/branch_push_service_spec.rb
@@ -19,7 +19,7 @@ describe Git::BranchPushService, services: true do
describe 'Push branches' do
subject do
- execute_service(project, user, oldrev, newrev, ref)
+ execute_service(project, user, oldrev: oldrev, newrev: newrev, ref: ref)
end
context 'new branch' do
@@ -70,7 +70,7 @@ describe Git::BranchPushService, services: true do
end
describe "Pipelines" do
- subject { execute_service(project, user, oldrev, newrev, ref) }
+ subject { execute_service(project, user, oldrev: oldrev, newrev: newrev, ref: ref) }
before do
stub_ci_pipeline_to_return_yaml_file
@@ -121,7 +121,7 @@ describe Git::BranchPushService, services: true do
.to receive(:perform_async)
.with(project.id, user.id, blankrev, 'newrev', ref)
- execute_service(project, user, blankrev, 'newrev', ref )
+ execute_service(project, user, oldrev: blankrev, newrev: 'newrev', ref: ref)
end
end
@@ -130,13 +130,13 @@ describe Git::BranchPushService, services: true do
it "calls the copy attributes method for the first push to the default branch" do
expect(project.repository).to receive(:copy_gitattributes).with('master')
- execute_service(project, user, blankrev, 'newrev', ref)
+ execute_service(project, user, oldrev: blankrev, newrev: 'newrev', ref: ref)
end
it "calls the copy attributes method for changes to the default branch" do
expect(project.repository).to receive(:copy_gitattributes).with(ref)
- execute_service(project, user, 'oldrev', 'newrev', ref)
+ execute_service(project, user, oldrev: 'oldrev', newrev: 'newrev', ref: ref)
end
end
@@ -149,7 +149,7 @@ describe Git::BranchPushService, services: true do
it "does not call copy attributes method" do
expect(project.repository).not_to receive(:copy_gitattributes)
- execute_service(project, user, oldrev, newrev, ref)
+ execute_service(project, user, oldrev: oldrev, newrev: newrev, ref: ref)
end
end
end
@@ -163,7 +163,7 @@ describe Git::BranchPushService, services: true do
it "when pushing a branch for the first time" do
expect(project).to receive(:execute_hooks)
expect(project.default_branch).to eq("master")
- execute_service(project, user, blankrev, 'newrev', ref)
+ execute_service(project, user, oldrev: blankrev, newrev: 'newrev', ref: ref)
expect(project.protected_branches).not_to be_empty
expect(project.protected_branches.first.push_access_levels.map(&:access_level)).to eq([Gitlab::Access::MAINTAINER])
expect(project.protected_branches.first.merge_access_levels.map(&:access_level)).to eq([Gitlab::Access::MAINTAINER])
@@ -174,7 +174,7 @@ describe Git::BranchPushService, services: true do
expect(project).to receive(:execute_hooks)
expect(project.default_branch).to eq("master")
- execute_service(project, user, blankrev, 'newrev', ref)
+ execute_service(project, user, oldrev: blankrev, newrev: 'newrev', ref: ref)
expect(project.protected_branches).to be_empty
end
@@ -184,7 +184,7 @@ describe Git::BranchPushService, services: true do
expect(project).to receive(:execute_hooks)
expect(project.default_branch).to eq("master")
- execute_service(project, user, blankrev, 'newrev', ref)
+ execute_service(project, user, oldrev: blankrev, newrev: 'newrev', ref: ref)
expect(project.protected_branches).not_to be_empty
expect(project.protected_branches.last.push_access_levels.map(&:access_level)).to eq([Gitlab::Access::DEVELOPER])
@@ -199,7 +199,7 @@ describe Git::BranchPushService, services: true do
expect(project.default_branch).to eq("master")
expect(ProtectedBranches::CreateService).not_to receive(:new)
- execute_service(project, user, blankrev, 'newrev', ref)
+ execute_service(project, user, oldrev: blankrev, newrev: 'newrev', ref: ref)
expect(project.protected_branches).not_to be_empty
expect(project.protected_branches.last.push_access_levels.map(&:access_level)).to eq([Gitlab::Access::NO_ACCESS])
@@ -211,7 +211,7 @@ describe Git::BranchPushService, services: true do
expect(project).to receive(:execute_hooks)
expect(project.default_branch).to eq("master")
- execute_service(project, user, blankrev, 'newrev', ref)
+ execute_service(project, user, oldrev: blankrev, newrev: 'newrev', ref: ref)
expect(project.protected_branches).not_to be_empty
expect(project.protected_branches.first.push_access_levels.map(&:access_level)).to eq([Gitlab::Access::MAINTAINER])
expect(project.protected_branches.first.merge_access_levels.map(&:access_level)).to eq([Gitlab::Access::DEVELOPER])
@@ -219,7 +219,7 @@ describe Git::BranchPushService, services: true do
it "when pushing new commits to existing branch" do
expect(project).to receive(:execute_hooks)
- execute_service(project, user, 'oldrev', 'newrev', ref)
+ execute_service(project, user, oldrev: 'oldrev', newrev: 'newrev', ref: ref)
end
end
end
@@ -249,7 +249,7 @@ describe Git::BranchPushService, services: true do
it "creates a note if a pushed commit mentions an issue" do
expect(SystemNoteService).to receive(:cross_reference).with(issue, commit, commit_author)
- execute_service(project, user, oldrev, newrev, ref)
+ execute_service(project, user, oldrev: oldrev, newrev: newrev, ref: ref)
end
it "only creates a cross-reference note if one doesn't already exist" do
@@ -257,7 +257,7 @@ describe Git::BranchPushService, services: true do
expect(SystemNoteService).not_to receive(:cross_reference).with(issue, commit, commit_author)
- execute_service(project, user, oldrev, newrev, ref)
+ execute_service(project, user, oldrev: oldrev, newrev: newrev, ref: ref)
end
it "defaults to the pushing user if the commit's author is not known" do
@@ -267,7 +267,7 @@ describe Git::BranchPushService, services: true do
)
expect(SystemNoteService).to receive(:cross_reference).with(issue, commit, user)
- execute_service(project, user, oldrev, newrev, ref)
+ execute_service(project, user, oldrev: oldrev, newrev: newrev, ref: ref)
end
it "finds references in the first push to a non-default branch" do
@@ -276,7 +276,7 @@ describe Git::BranchPushService, services: true do
expect(SystemNoteService).to receive(:cross_reference).with(issue, commit, commit_author)
- execute_service(project, user, blankrev, newrev, 'refs/heads/other')
+ execute_service(project, user, oldrev: blankrev, newrev: newrev, ref: 'refs/heads/other')
end
end
@@ -306,14 +306,14 @@ describe Git::BranchPushService, services: true do
context "while saving the 'first_mentioned_in_commit_at' metric for an issue" do
it 'sets the metric for referenced issues' do
- execute_service(project, user, oldrev, newrev, ref)
+ execute_service(project, user, oldrev: oldrev, newrev: newrev, ref: ref)
expect(issue.reload.metrics.first_mentioned_in_commit_at).to be_like_time(commit_time)
end
it 'does not set the metric for non-referenced issues' do
non_referenced_issue = create(:issue, project: project)
- execute_service(project, user, oldrev, newrev, ref)
+ execute_service(project, user, oldrev: oldrev, newrev: newrev, ref: ref)
expect(non_referenced_issue.reload.metrics.first_mentioned_in_commit_at).to be_nil
end
@@ -345,18 +345,18 @@ describe Git::BranchPushService, services: true do
context "to default branches" do
it "closes issues" do
- execute_service(project, commit_author, oldrev, newrev, ref)
+ execute_service(project, commit_author, oldrev: oldrev, newrev: newrev, ref: ref)
expect(Issue.find(issue.id)).to be_closed
end
it "adds a note indicating that the issue is now closed" do
expect(SystemNoteService).to receive(:change_status).with(issue, project, commit_author, "closed", closing_commit)
- execute_service(project, commit_author, oldrev, newrev, ref)
+ execute_service(project, commit_author, oldrev: oldrev, newrev: newrev, ref: ref)
end
it "doesn't create additional cross-reference notes" do
expect(SystemNoteService).not_to receive(:cross_reference)
- execute_service(project, commit_author, oldrev, newrev, ref)
+ execute_service(project, commit_author, oldrev: oldrev, newrev: newrev, ref: ref)
end
end
@@ -368,11 +368,11 @@ describe Git::BranchPushService, services: true do
it "creates cross-reference notes" do
expect(SystemNoteService).to receive(:cross_reference).with(issue, closing_commit, commit_author)
- execute_service(project, user, oldrev, newrev, ref)
+ execute_service(project, user, oldrev: oldrev, newrev: newrev, ref: ref)
end
it "doesn't close issues" do
- execute_service(project, user, oldrev, newrev, ref)
+ execute_service(project, user, oldrev: oldrev, newrev: newrev, ref: ref)
expect(Issue.find(issue.id)).to be_opened
end
end
@@ -408,7 +408,7 @@ describe Git::BranchPushService, services: true do
let(:message) { "this is some work.\n\nrelated to JIRA-1" }
it "initiates one api call to jira server to mention the issue" do
- execute_service(project, user, oldrev, newrev, ref)
+ execute_service(project, user, oldrev: oldrev, newrev: newrev, ref: ref)
expect(WebMock).to have_requested(:post, jira_api_comment_url('JIRA-1')).with(
body: /mentioned this issue in/
@@ -436,13 +436,13 @@ describe Git::BranchPushService, services: true do
context "using right markdown" do
it "initiates one api call to jira server to close the issue" do
- execute_service(project, commit_author, oldrev, newrev, ref)
+ execute_service(project, commit_author, oldrev: oldrev, newrev: newrev, ref: ref)
expect(WebMock).to have_requested(:post, jira_api_transition_url('JIRA-1')).once
end
it "initiates one api call to jira server to comment on the issue" do
- execute_service(project, commit_author, oldrev, newrev, ref)
+ execute_service(project, commit_author, oldrev: oldrev, newrev: newrev, ref: ref)
expect(WebMock).to have_requested(:post, jira_api_comment_url('JIRA-1')).with(
body: comment_body
@@ -459,13 +459,13 @@ describe Git::BranchPushService, services: true do
let(:message) { "this is some work.\n\ncloses #1" }
it "does not initiates one api call to jira server to close the issue" do
- execute_service(project, commit_author, oldrev, newrev, ref)
+ execute_service(project, commit_author, oldrev: oldrev, newrev: newrev, ref: ref)
expect(WebMock).not_to have_requested(:post, jira_api_transition_url('JIRA-1'))
end
it "does not initiates one api call to jira server to comment on the issue" do
- execute_service(project, commit_author, oldrev, newrev, ref)
+ execute_service(project, commit_author, oldrev: oldrev, newrev: newrev, ref: ref)
expect(WebMock).not_to have_requested(:post, jira_api_comment_url('JIRA-1')).with(
body: comment_body
@@ -478,13 +478,13 @@ describe Git::BranchPushService, services: true do
let(:message) { "this is some work.\n\ncloses JIRA-1 \n\n closes #{issue.to_reference}" }
it "initiates one api call to jira server to close the jira issue" do
- execute_service(project, commit_author, oldrev, newrev, ref)
+ execute_service(project, commit_author, oldrev: oldrev, newrev: newrev, ref: ref)
expect(WebMock).to have_requested(:post, jira_api_transition_url('JIRA-1')).once
end
it "initiates one api call to jira server to comment on the jira issue" do
- execute_service(project, commit_author, oldrev, newrev, ref)
+ execute_service(project, commit_author, oldrev: oldrev, newrev: newrev, ref: ref)
expect(WebMock).to have_requested(:post, jira_api_comment_url('JIRA-1')).with(
body: comment_body
@@ -492,14 +492,14 @@ describe Git::BranchPushService, services: true do
end
it "closes the internal issue" do
- execute_service(project, commit_author, oldrev, newrev, ref)
+ execute_service(project, commit_author, oldrev: oldrev, newrev: newrev, ref: ref)
expect(issue.reload).to be_closed
end
it "adds a note indicating that the issue is now closed" do
expect(SystemNoteService).to receive(:change_status)
.with(issue, project, commit_author, "closed", closing_commit)
- execute_service(project, commit_author, oldrev, newrev, ref)
+ execute_service(project, commit_author, oldrev: oldrev, newrev: newrev, ref: ref)
end
end
end
@@ -517,7 +517,7 @@ describe Git::BranchPushService, services: true do
end
it 'push to first branch updates HEAD' do
- execute_service(project, user, blankrev, newrev, new_ref)
+ execute_service(project, user, oldrev: blankrev, newrev: newrev, ref: new_ref)
end
end
@@ -542,7 +542,7 @@ describe Git::BranchPushService, services: true do
it 'does not perform housekeeping when not needed' do
expect(housekeeping).not_to receive(:execute)
- execute_service(project, user, oldrev, newrev, ref)
+ execute_service(project, user, oldrev: oldrev, newrev: newrev, ref: ref)
end
context 'when housekeeping is needed' do
@@ -553,20 +553,20 @@ describe Git::BranchPushService, services: true do
it 'performs housekeeping' do
expect(housekeeping).to receive(:execute)
- execute_service(project, user, oldrev, newrev, ref)
+ execute_service(project, user, oldrev: oldrev, newrev: newrev, ref: ref)
end
it 'does not raise an exception' do
allow(housekeeping).to receive(:try_obtain_lease).and_return(false)
- execute_service(project, user, oldrev, newrev, ref)
+ execute_service(project, user, oldrev: oldrev, newrev: newrev, ref: ref)
end
end
it 'increments the push counter' do
expect(housekeeping).to receive(:increment!)
- execute_service(project, user, oldrev, newrev, ref)
+ execute_service(project, user, oldrev: oldrev, newrev: newrev, ref: ref)
end
end
@@ -577,7 +577,7 @@ describe Git::BranchPushService, services: true do
it 'does nothing' do
expect(::Ci::StopEnvironmentsService).not_to receive(:new)
- execute_service(project, user, oldrev, newrev, ref)
+ execute_service(project, user, oldrev: oldrev, newrev: newrev, ref: ref)
end
end
@@ -585,7 +585,7 @@ describe Git::BranchPushService, services: true do
it 'does nothing' do
expect(::Ci::StopEnvironmentsService).not_to receive(:new)
- execute_service(project, user, oldrev, newrev, ref)
+ execute_service(project, user, oldrev: oldrev, newrev: newrev, ref: ref)
end
end
@@ -599,7 +599,7 @@ describe Git::BranchPushService, services: true do
expect(stop_service).to receive(:execute).with(branch)
end
- execute_service(project, user, oldrev, newrev, ref)
+ execute_service(project, user, oldrev: oldrev, newrev: newrev, ref: ref)
end
end
end
@@ -611,15 +611,17 @@ describe Git::BranchPushService, services: true do
expect(hooks_service.project).to eq(project)
expect(hooks_service.current_user).to eq(user)
expect(hooks_service.params).to include(
- oldrev: oldrev,
- newrev: newrev,
- ref: ref
+ change: {
+ oldrev: oldrev,
+ newrev: newrev,
+ ref: ref
+ }
)
expect(hooks_service).to receive(:execute)
end
- execute_service(project, user, oldrev, newrev, ref)
+ execute_service(project, user, oldrev: oldrev, newrev: newrev, ref: ref)
end
end
@@ -629,13 +631,13 @@ describe Git::BranchPushService, services: true do
it 'does nothing' do
expect(::Git::BranchHooksService).not_to receive(:new)
- execute_service(project, user, oldrev, newrev, ref)
+ execute_service(project, user, oldrev: oldrev, newrev: newrev, ref: ref)
end
end
end
- def execute_service(project, user, oldrev, newrev, ref)
- service = described_class.new(project, user, oldrev: oldrev, newrev: newrev, ref: ref)
+ def execute_service(project, user, change)
+ service = described_class.new(project, user, change: change)
service.execute
service
end
diff --git a/spec/services/git/tag_hooks_service_spec.rb b/spec/services/git/tag_hooks_service_spec.rb
index 1b8e0675f1b..c97d4d38b1c 100644
--- a/spec/services/git/tag_hooks_service_spec.rb
+++ b/spec/services/git/tag_hooks_service_spec.rb
@@ -15,7 +15,7 @@ describe Git::TagHooksService, :service do
let(:commit) { tag.dereferenced_target }
let(:service) do
- described_class.new(project, user, oldrev: oldrev, newrev: newrev, ref: ref)
+ described_class.new(project, user, change: { oldrev: oldrev, newrev: newrev, ref: ref })
end
describe 'System hooks' do
diff --git a/spec/services/git/tag_push_service_spec.rb b/spec/services/git/tag_push_service_spec.rb
index 7e008637182..9688041c08c 100644
--- a/spec/services/git/tag_push_service_spec.rb
+++ b/spec/services/git/tag_push_service_spec.rb
@@ -8,7 +8,7 @@ describe Git::TagPushService do
let(:user) { create(:user) }
let(:project) { create(:project, :repository) }
- let(:service) { described_class.new(project, user, oldrev: oldrev, newrev: newrev, ref: ref) }
+ let(:service) { described_class.new(project, user, change: { oldrev: oldrev, newrev: newrev, ref: ref }) }
let(:oldrev) { Gitlab::Git::BLANK_SHA }
let(:newrev) { "8a2a6eb295bb170b34c24c76c49ed0e9b2eaf34b" } # gitlab-test: git rev-parse refs/tags/v1.1.0
diff --git a/spec/services/issues/close_service_spec.rb b/spec/services/issues/close_service_spec.rb
index 642a49d57d5..1f7d564b6ec 100644
--- a/spec/services/issues/close_service_spec.rb
+++ b/spec/services/issues/close_service_spec.rb
@@ -8,6 +8,7 @@ describe Issues::CloseService do
let(:user2) { create(:user, email: "user2@example.com") }
let(:guest) { create(:user) }
let(:issue) { create(:issue, title: "My issue", project: project, assignees: [user2], author: create(:user)) }
+ let(:external_issue) { ExternalIssue.new('JIRA-123', project) }
let(:closing_merge_request) { create(:merge_request, source_project: project) }
let(:closing_commit) { create(:commit, project: project) }
let!(:todo) { create(:todo, :assigned, user: user, project: project, target: issue, author: user2) }
@@ -36,6 +37,16 @@ describe Issues::CloseService do
expect(service.execute(issue)).to eq(issue)
end
+ it 'closes the external issue even when the user is not authorized to do so' do
+ allow(service).to receive(:can?).with(user, :update_issue, external_issue)
+ .and_return(false)
+
+ expect(service).to receive(:close_issue)
+ .with(external_issue, closed_via: nil, notifications: true, system_note: true)
+
+ service.execute(external_issue)
+ end
+
it 'closes the issue when the user is authorized to do so' do
allow(service).to receive(:can?).with(user, :update_issue, issue)
.and_return(true)
diff --git a/spec/services/merge_requests/post_merge_service_spec.rb b/spec/services/merge_requests/post_merge_service_spec.rb
index ffc86f68469..fff6ddf3928 100644
--- a/spec/services/merge_requests/post_merge_service_spec.rb
+++ b/spec/services/merge_requests/post_merge_service_spec.rb
@@ -56,9 +56,11 @@ describe MergeRequests::PostMergeService do
issue = create(:issue, project: project)
allow(merge_request).to receive(:visible_closing_issues_for).and_return([issue])
- allow_any_instance_of(Issues::CloseService).to receive(:execute).with(issue, commit: merge_request).and_raise
+ expect_next_instance_of(Issues::CloseService) do |service|
+ allow(service).to receive(:execute).with(issue, commit: merge_request).and_raise(RuntimeError)
+ end
- expect { described_class.new(project, user, {}).execute(merge_request) }.to raise_error
+ expect { described_class.new(project, user).execute(merge_request) }.to raise_error(RuntimeError)
expect(merge_request.reload).to be_merged
end
diff --git a/spec/support/helpers/cycle_analytics_helpers.rb b/spec/support/helpers/cycle_analytics_helpers.rb
index 575b2e779c5..b2817f9c14a 100644
--- a/spec/support/helpers/cycle_analytics_helpers.rb
+++ b/spec/support/helpers/cycle_analytics_helpers.rb
@@ -25,11 +25,15 @@ module CycleAnalyticsHelpers
return if skip_push_handler
- Git::BranchPushService.new(project,
- user,
- oldrev: oldrev,
- newrev: commit_shas.last,
- ref: 'refs/heads/master').execute
+ Git::BranchPushService.new(
+ project,
+ user,
+ change: {
+ oldrev: oldrev,
+ newrev: commit_shas.last,
+ ref: 'refs/heads/master'
+ }
+ ).execute
end
def create_cycle(user, project, issue, mr, milestone, pipeline)