blob: d95669d502f218a03708e2c52d7812a77c8bb5a3 (
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
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::HookData::GroupBuilder do
let_it_be(:group) { create(:group) }
describe '#build' do
let(:data) { described_class.new(group).build(event) }
let(:event_name) { data[:event_name] }
let(:attributes) do
[
:event_name, :created_at, :updated_at, :name, :path, :full_path, :group_id,
:owner_name, :owner_email
]
end
context 'data' do
shared_examples_for 'includes the required attributes' do
it 'includes the required attributes' do
expect(data).to include(*attributes)
expect(data[:name]).to eq(group.name)
expect(data[:path]).to eq(group.path)
expect(data[:full_path]).to eq(group.full_path)
expect(data[:group_id]).to eq(group.id)
expect(data[:owner_name]).to eq(nil)
expect(data[:owner_email]).to eq(nil)
expect(data[:created_at]).to eq(group.created_at.xmlschema)
expect(data[:updated_at]).to eq(group.updated_at.xmlschema)
end
end
shared_examples_for 'does not include old path attributes' do
it 'does not include old path attributes' do
expect(data).not_to include(:old_path, :old_full_path)
end
end
context 'on create' do
let(:event) { :create }
it { expect(event_name).to eq('group_create') }
it_behaves_like 'includes the required attributes'
it_behaves_like 'does not include old path attributes'
end
context 'on destroy' do
let(:event) { :destroy }
it { expect(event_name).to eq('group_destroy') }
it_behaves_like 'includes the required attributes'
it_behaves_like 'does not include old path attributes'
end
context 'on rename' do
let(:event) { :rename }
it { expect(event_name).to eq('group_rename') }
it_behaves_like 'includes the required attributes'
it 'includes old path details' do
allow(group).to receive(:path_before_last_save).and_return('old-path')
expect(data[:old_path]).to eq(group.path_before_last_save)
expect(data[:old_full_path]).to eq(group.path_before_last_save)
end
end
end
end
end
|