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

F
Felipe Artur 已提交
3 4
describe ChatMessage::PushMessage, models: true do
  subject { described_class.new(args) }
5

6
  let(:args) do
7 8 9 10 11
    {
      after: 'after',
      before: 'before',
      project_name: 'project_name',
      ref: 'refs/heads/master',
12
      user_name: 'test.user',
13 14
      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
        'test.user 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
        {
D
Douwe Maan 已提交
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
        after: 'after',
        before: Gitlab::Git::BLANK_SHA,
        project_name: 'project_name',
        ref: 'refs/tags/new_tag',
49
        user_name: 'test.user',
50
        project_url: 'url'
51
      }
52
    end
53 54

    it 'returns a message regarding pushes' do
55
      expect(subject.pretext).to eq('test.user pushed new tag ' \
56 57 58 59 60 61
       '<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
        'test.user 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
        'test.user removed branch master from <url|project_name>'
84 85
      )
      expect(subject.attachments).to be_empty
86 87 88
    end
  end
end