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:
authorPeter Leitzen <pl@neopoly.de>2018-07-23 22:05:38 +0300
committerPeter Leitzen <pl@neopoly.de>2018-08-10 17:45:11 +0300
commit18611f0eebe0bb3646c7f32bd333b92c184771eb (patch)
tree441e047ba51ae08d2f80b439f25cb5bea33d594b /spec/services/commits
parentd331377af5e2a8aae9db365b8a4892ad027dcfa7 (diff)
Refactor spec for Commits::UpdateService
Diffstat (limited to 'spec/services/commits')
-rw-r--r--spec/services/commits/update_service_spec.rb78
1 files changed, 51 insertions, 27 deletions
diff --git a/spec/services/commits/update_service_spec.rb b/spec/services/commits/update_service_spec.rb
index 05d1e4ec254..b4f260096ad 100644
--- a/spec/services/commits/update_service_spec.rb
+++ b/spec/services/commits/update_service_spec.rb
@@ -4,46 +4,75 @@ describe Commits::UpdateService do
let(:project) { create(:project, :repository) }
let(:user) { create(:user) }
- let(:commit) { create(:commit, project: project) }
+ let(:commit) { project.commit }
before do
project.add_maintainer(user)
end
- describe 'execute' do
+ describe '#execute' do
let(:service) { described_class.new(project, user, opts) }
+ shared_examples 'tagging fails' do
+ it 'returns nil' do
+ tagged_commit = service.execute(commit)
+
+ expect(tagged_commit).to be_nil
+ end
+
+ it 'does not add a system note' do
+ service.execute(commit)
+
+ description_notes = find_notes('tag')
+ expect(description_notes).to be_empty
+ end
+ end
+
+ def find_notes(action)
+ commit
+ .notes
+ .joins(:system_note_metadata)
+ .where(system_note_metadata: { action: action })
+ end
+
context 'valid params' do
let(:opts) do
{
- tag_name: '1.2.3',
+ tag_name: 'v1.2.3',
tag_message: 'Release'
}
end
- it 'tags a commit' do
- tag_double = double(name: opts[:tag_name])
- tag_stub = instance_double(Tags::CreateService)
- allow(Tags::CreateService).to receive(:new).and_return(tag_stub)
- allow(tag_stub).to receive(:execute)
- .with(opts[:tag_name], commit.sha, opts[:tag_message], nil)
- .and_return({ status: :success, tag: tag_double })
+ def find_notes(action)
+ commit
+ .notes
+ .joins(:system_note_metadata)
+ .where(system_note_metadata: { action: action })
+ end
- expect(SystemNoteService).to receive(:tag_commit).with(commit, project, user, opts[:tag_name])
+ context 'when tagging succeeds' do
+ it 'returns the commit' do
+ tagged_commit = service.execute(commit)
- service.execute(commit)
- end
+ expect(tagged_commit).to eq(commit)
+ end
- it 'fails to tag the commit' do
- tag_stub = instance_double(Tags::CreateService)
- allow(Tags::CreateService).to receive(:new).and_return(tag_stub)
- allow(tag_stub).to receive(:execute)
- .with(opts[:tag_name], commit.sha, opts[:tag_message], nil)
- .and_return({ status: :error })
+ it 'adds a system note' do
+ service.execute(commit)
- expect(SystemNoteService).not_to receive(:tag_commit)
+ description_notes = find_notes('tag')
+ expect(description_notes.length).to eq(1)
+ end
+ end
- service.execute(commit)
+ context 'when tagging fails' do
+ before do
+ tag_stub = instance_double(Tags::CreateService)
+ allow(Tags::CreateService).to receive(:new).and_return(tag_stub)
+ allow(tag_stub).to receive(:execute).and_return({ status: :error })
+ end
+
+ include_examples 'tagging fails'
end
end
@@ -52,12 +81,7 @@ describe Commits::UpdateService do
{}
end
- it 'does not call the tag create service' do
- expect(Tags::CreateService).not_to receive(:new)
- expect(SystemNoteService).not_to receive(:tag_commit)
-
- service.execute(commit)
- end
+ include_examples 'tagging fails'
end
end
end