gitlab_spec.rb
1.79 KB
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
require 'rails_helper'
require 'webhooks'
RSpec.describe Webhooks::GitLab do
let(:request) { FactoryGirl.build(:gitlab_webhook_request).request }
let(:repository) { FactoryGirl.build(:repository) }
subject { described_class.new(request, repository) }
describe 'valid_request?' do
context 'with the correct Gitlab header value' do
it 'is expected to return true' do
expect(subject.valid_request?).to be(true)
end
end
context 'with an incorrect Gitlab header value' do
let(:request) { FactoryGirl.build(:gitlab_webhook_request, headers: { 'X-Gitlab-Event' => 'Merge Hook' }).request }
it 'is expected to return false' do
expect(subject.valid_request?).to be(false)
end
end
context 'without a GitLab header' do
let(:request) { FactoryGirl.build(:gitlab_webhook_request, headers: {}).request }
it 'is expected to return false' do
expect(subject.valid_request?).to be(false)
end
end
end
describe 'webhook_address' do
context 'the git URL is present' do
it 'is expected to return the URL' do
expect(subject.webhook_address).to eq(request.params[:project][:git_http_url])
end
end
context'the git URL is not present' do
it 'is expected to return nil' do
request.expects(:params).returns({})
expect(subject.webhook_address).to be_nil
end
end
end
describe 'webhook_branch' do
context 'the git ref is present' do
it 'is expected to return the branch from the ref' do
expect(subject.webhook_branch).to eq('master')
end
end
context 'the git ref is not present' do
it 'is expected to return nil' do
request.expects(:params).returns({})
expect(subject.webhook_branch).to be_nil
end
end
end
end