diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2016-07-29 19:59:54 +0300 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2016-07-29 19:59:54 +0300 |
commit | d27095a36a5d8c83182771d7548a13fcc9188e3c (patch) | |
tree | 74e08e2d59addd14f89892d70581e822b9d8bfbb /spec/models/project_services | |
parent | 4a431a266f8773c54a0f47292d4b9470a7d2acd3 (diff) |
Add pipeline_events to Slack service:
Also add Service#event_names so that we don't have to hard code all
event names in ServiceParams. Note that I don't know why we want to
call plural on issue_event and merge_request_event so that we still
need to hard code them for issues_event and merge_requests_event.
See app/helpers/services_helper.rb for those special rules.
Diffstat (limited to 'spec/models/project_services')
-rw-r--r-- | spec/models/project_services/slack_service/pipeline_message_spec.rb | 58 |
1 files changed, 58 insertions, 0 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 new file mode 100644 index 00000000000..2960a200e9d --- /dev/null +++ b/spec/models/project_services/slack_service/pipeline_message_spec.rb @@ -0,0 +1,58 @@ +require 'spec_helper' + +describe SlackService::PipelineMessage do + subject { SlackService::PipelineMessage.new(args) } + + let(:args) do + { + sha: '97de212e80737a608d939f648d959671fb0a0142', + tag: false, + ref: 'develop', + status: status, + project: { path_with_namespace: 'project_name', + web_url: 'somewhere.com' }, + commit: { author_name: 'hacker' }, + object_attributes: { duration: duration, + id: 123 } + } + end + + context 'succeeded' do + let(:status) { 'success' } + let(:color) { 'good' } + let(:duration) { 10 } + + it 'returns a message with information about succeeded build' do + message = '<somewhere.com|project_name>: Pipeline <somewhere.com/pipelines/123|97de212e> of <somewhere.com/commits/develop|develop> branch by hacker passed in 10 seconds' + expect(subject.pretext).to be_empty + expect(subject.fallback).to eq(message) + expect(subject.attachments).to eq([text: message, color: color]) + end + end + + context 'failed' do + let(:status) { 'failed' } + let(:color) { 'danger' } + let(:duration) { 10 } + + it 'returns a message with information about failed build' do + message = '<somewhere.com|project_name>: Pipeline <somewhere.com/pipelines/123|97de212e> of <somewhere.com/commits/develop|develop> branch by hacker failed in 10 seconds' + expect(subject.pretext).to be_empty + expect(subject.fallback).to eq(message) + expect(subject.attachments).to eq([text: message, color: color]) + end + end + + describe '#seconds_name' do + let(:status) { 'failed' } + let(:color) { 'danger' } + let(:duration) { 1 } + + it 'returns seconds as singular when there is only one' do + message = '<somewhere.com|project_name>: Pipeline <somewhere.com/pipelines/123|97de212e> of <somewhere.com/commits/develop|develop> branch by hacker failed in 1 second' + expect(subject.pretext).to be_empty + expect(subject.fallback).to eq(message) + expect(subject.attachments).to eq([text: message, color: color]) + end + end +end |