summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorKamil Trzciński <ayufan@ayufan.eu>2016-12-15 11:08:45 +0000
committerKamil Trzciński <ayufan@ayufan.eu>2016-12-15 11:08:45 +0000
commit01ffcceb81f1a556cdce15ec89c15be12dba9732 (patch)
tree2f9d2df72247b21f47df8b8fcbab863a12a21ff8 /spec
parent51830b6659363e8d4410ea8d261538f4fe09697c (diff)
parent07d69d8a6763984536a590690bb58527f6175bc1 (diff)
downloadgitlab-ce-01ffcceb81f1a556cdce15ec89c15be12dba9732.tar.gz
Merge branch 'fix-slack-pipeline-message-by-api' into 'master'
Fix Slack pipeline message by API Pipelines triggered from API don't have a corresponding user, so we show that it's from API, same as from the web UI Closes #25609 See merge request !8059
Diffstat (limited to 'spec')
-rw-r--r--spec/models/project_services/slack_service/pipeline_message_spec.rb30
1 files changed, 21 insertions, 9 deletions
diff --git a/spec/models/project_services/slack_service/pipeline_message_spec.rb b/spec/models/project_services/slack_service/pipeline_message_spec.rb
index 363138a9454..4098500122f 100644
--- a/spec/models/project_services/slack_service/pipeline_message_spec.rb
+++ b/spec/models/project_services/slack_service/pipeline_message_spec.rb
@@ -2,6 +2,7 @@ require 'spec_helper'
describe SlackService::PipelineMessage do
subject { SlackService::PipelineMessage.new(args) }
+ let(:user) { { name: 'hacker' } }
let(:args) do
{
@@ -15,7 +16,7 @@ describe SlackService::PipelineMessage do
},
project: { path_with_namespace: 'project_name',
web_url: 'example.gitlab.com' },
- user: { name: 'hacker' }
+ user: user
}
end
@@ -28,9 +29,7 @@ describe SlackService::PipelineMessage do
let(:message) { build_message('passed') }
it 'returns a message with information about succeeded build' do
- expect(subject.pretext).to be_empty
- expect(subject.fallback).to eq(message)
- expect(subject.attachments).to eq([text: message, color: color])
+ verify_message
end
end
@@ -40,16 +39,29 @@ describe SlackService::PipelineMessage do
let(:duration) { 10 }
it 'returns a message with information about failed build' do
- expect(subject.pretext).to be_empty
- expect(subject.fallback).to eq(message)
- expect(subject.attachments).to eq([text: message, color: color])
+ verify_message
end
+
+ context 'when triggered by API therefore lacking user' do
+ let(:user) { nil }
+ let(:message) { build_message(status, 'API') }
+
+ it 'returns a message stating it is by API' do
+ verify_message
+ end
+ end
+ end
+
+ def verify_message
+ expect(subject.pretext).to be_empty
+ expect(subject.fallback).to eq(message)
+ expect(subject.attachments).to eq([text: message, color: color])
end
- def build_message(status_text = status)
+ def build_message(status_text = status, name = user[:name])
"<example.gitlab.com|project_name>:" \
" Pipeline <example.gitlab.com/pipelines/123|#123>" \
" of <example.gitlab.com/commits/develop|develop> branch" \
- " by hacker #{status_text} in #{duration} #{'second'.pluralize(duration)}"
+ " by #{name} #{status_text} in #{duration} #{'second'.pluralize(duration)}"
end
end