blob: f0df3794e2903fdb354b9ba828b60e61f1aed189 (
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
# frozen_string_literal: true
require 'spec_helper'
describe ::Gitlab::GitPostReceive do
set(:project) { create(:project, :repository) }
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
describe '#includes_default_branch?' do
context 'with no default branch' do
let(:changes) do
<<~EOF
654321 210987 refs/heads/test1
654322 210986 refs/tags/#{project.default_branch}
654323 210985 refs/heads/test3
EOF
end
it 'returns false' do
expect(subject.includes_default_branch?).to be_falsey
end
end
context 'with a project with no default branch' do
let(:changes) do
<<~EOF
654321 210987 refs/heads/test1
EOF
end
it 'returns true' do
expect(project).to receive(:default_branch).and_return(nil)
expect(subject.includes_default_branch?).to be_truthy
end
end
context 'with default branch' do
let(:changes) do
<<~EOF
654322 210986 refs/heads/test1
654321 210987 refs/tags/test2
654323 210985 refs/heads/#{project.default_branch}
EOF
end
it 'returns true' do
expect(subject.includes_default_branch?).to be_truthy
end
end
end
end
|