summaryrefslogtreecommitdiff
path: root/spec/models/ci/project_services/slack_message_spec.rb
blob: 8adda6c86ccc84950f35290142b0e59dae010e43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
require 'spec_helper'

describe Ci::SlackMessage do
  subject { Ci::SlackMessage.new(commit) }

  let(:commit) { FactoryGirl.create(:ci_commit_with_two_jobs) }

  context 'when all matrix builds succeeded' do
    let(:color) { 'good' }

    it 'returns a message with success' do
      commit.create_builds('master', false, nil)
      commit.builds.update_all(status: "success")
      commit.reload

      expect(subject.color).to eq(color)
      expect(subject.fallback).to include('Commit')
      expect(subject.fallback).to include("\##{commit.id}")
      expect(subject.fallback).to include('succeeded')
      expect(subject.attachments.first[:fields]).to be_empty
    end
  end

  context 'when one of matrix builds failed' do
    let(:color) { 'danger' }

    it 'returns a message with information about failed build' do
      commit.create_builds('master', false, nil)
      first_build = commit.builds.first
      second_build = commit.builds.last
      first_build.update(status: "success")
      second_build.update(status: "failed")

      expect(subject.color).to eq(color)
      expect(subject.fallback).to include('Commit')
      expect(subject.fallback).to include("\##{commit.id}")
      expect(subject.fallback).to include('failed')
      expect(subject.attachments.first[:fields].size).to eq(1)
      expect(subject.attachments.first[:fields].first[:title]).to eq(second_build.name)
      expect(subject.attachments.first[:fields].first[:value]).to include("\##{second_build.id}")
    end
  end
end