BigW Consortium Gitlab

push_message_spec.rb 2.21 KB
Newer Older
1
require 'spec_helper'
2

Douwe Maan committed
3 4
describe SlackService::PushMessage do
  subject { SlackService::PushMessage.new(args) }
5

6
  let(:args) do
7 8 9 10 11 12 13 14
    {
      after: 'after',
      before: 'before',
      project_name: 'project_name',
      ref: 'refs/heads/master',
      user_name: 'user_name',
      project_url: 'url'
    }
15
  end
16

17 18
  let(:color) { '#345' }

19 20 21
  context 'push' do
    before do
      args[:commits] = [
22 23
        { message: 'message1', url: 'url1', id: 'abcdefghijkl', author: { name: 'author1' } },
        { message: 'message2', url: 'url2', id: '123456789012', author: { name: 'author2' } },
24 25 26 27
      ]
    end

    it 'returns a message regarding pushes' do
28
      expect(subject.pretext).to eq(
29
        'user_name pushed to branch <url/commits/master|master> of '\
30
        '<url|project_name> (<url/compare/before...after|Compare changes>)'
31 32
      )
      expect(subject.attachments).to eq([
33
        {
Douwe Maan committed
34 35
          text: "<url1|abcdefgh>: message1 - author1\n"\
                "<url2|12345678>: message2 - author2",
36 37
          color: color,
        }
38
      ])
39 40 41
    end
  end

42
  context 'tag push' do
43
    let(:args) do
44
      {
45 46 47 48 49 50
        after: 'after',
        before: Gitlab::Git::BLANK_SHA,
        project_name: 'project_name',
        ref: 'refs/tags/new_tag',
        user_name: 'user_name',
        project_url: 'url'
51
      }
52
    end
53 54 55 56 57 58 59 60 61

    it 'returns a message regarding pushes' do
      expect(subject.pretext).to eq('user_name pushed new tag ' \
       '<url/commits/new_tag|new_tag> to ' \
       '<url|project_name>')
      expect(subject.attachments).to be_empty
    end
  end

62 63
  context 'new branch' do
    before do
64
      args[:before] = Gitlab::Git::BLANK_SHA
65 66 67
    end

    it 'returns a message regarding a new branch' do
68
      expect(subject.pretext).to eq(
69
        'user_name pushed new branch <url/commits/master|master> to '\
70
        '<url|project_name>'
71 72
      )
      expect(subject.attachments).to be_empty
73 74 75 76 77
    end
  end

  context 'removed branch' do
    before do
78
      args[:after] = Gitlab::Git::BLANK_SHA
79 80 81
    end

    it 'returns a message regarding a removed branch' do
82
      expect(subject.pretext).to eq(
83
        'user_name removed branch master from <url|project_name>'
84 85
      )
      expect(subject.attachments).to be_empty
86 87 88
    end
  end
end