summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/git_post_receive_spec.rb
blob: 4c20d945585bb74c7b2f39f77a851edd7953687f (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# frozen_string_literal: true

require 'spec_helper'

describe ::Gitlab::GitPostReceive do
  let(:project) { create(:project) }

  subject { described_class.new(project, "project-#{project.id}", changes.dup, {}) }

  describe '#includes_branches?' do
    context 'with no branches' do
      let(:changes) do
        <<~EOF
          654321 210987 refs/nobranches/tag1
          654322 210986 refs/tags/test1
          654323 210985 refs/merge-requests/mr1
        EOF
      end

      it 'returns false' do
        expect(subject.includes_branches?).to be_falsey
      end
    end

    context 'with branches' do
      let(:changes) do
        <<~EOF
          654322 210986 refs/heads/test1
          654321 210987 refs/tags/tag1
          654323 210985 refs/merge-requests/mr1
        EOF
      end

      it 'returns true' do
        expect(subject.includes_branches?).to be_truthy
      end
    end

    context 'with malformed changes' do
      let(:changes) do
        <<~EOF
          ref/heads/1 a
          somebranch refs/heads/2
        EOF
      end

      it 'returns false' do
        expect(subject.includes_branches?).to be_falsey
      end
    end
  end

  describe '#includes_tags?' do
    context 'with no tags' do
      let(:changes) do
        <<~EOF
          654321 210987 refs/notags/tag1
          654322 210986 refs/heads/test1
          654323 210985 refs/merge-requests/mr1
        EOF
      end

      it 'returns false' do
        expect(subject.includes_tags?).to be_falsey
      end
    end

    context 'with tags' do
      let(:changes) do
        <<~EOF
          654322 210986 refs/heads/test1
          654321 210987 refs/tags/tag1
          654323 210985 refs/merge-requests/mr1
        EOF
      end

      it 'returns true' do
        expect(subject.includes_tags?).to be_truthy
      end
    end

    context 'with malformed changes' do
      let(:changes) do
        <<~EOF
          ref/tags/1 a
          sometag refs/tags/2
        EOF
      end

      it 'returns false' do
        expect(subject.includes_tags?).to be_falsey
      end
    end
  end
end