diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-18 13:34:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-18 13:34:06 +0300 |
commit | 859a6fb938bb9ee2a317c46dfa4fcc1af49608f0 (patch) | |
tree | d7f2700abe6b4ffcb2dcfc80631b2d87d0609239 /spec/lib/gitlab/hook_data | |
parent | 446d496a6d000c73a304be52587cd9bbc7493136 (diff) |
Add latest changes from gitlab-org/gitlab@13-9-stable-eev13.9.0-rc42
Diffstat (limited to 'spec/lib/gitlab/hook_data')
-rw-r--r-- | spec/lib/gitlab/hook_data/group_builder_spec.rb | 68 | ||||
-rw-r--r-- | spec/lib/gitlab/hook_data/subgroup_builder_spec.rb | 52 |
2 files changed, 120 insertions, 0 deletions
diff --git a/spec/lib/gitlab/hook_data/group_builder_spec.rb b/spec/lib/gitlab/hook_data/group_builder_spec.rb new file mode 100644 index 00000000000..d7347ff99d4 --- /dev/null +++ b/spec/lib/gitlab/hook_data/group_builder_spec.rb @@ -0,0 +1,68 @@ +# 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 + ] + 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[: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 diff --git a/spec/lib/gitlab/hook_data/subgroup_builder_spec.rb b/spec/lib/gitlab/hook_data/subgroup_builder_spec.rb new file mode 100644 index 00000000000..89e5dffd7b4 --- /dev/null +++ b/spec/lib/gitlab/hook_data/subgroup_builder_spec.rb @@ -0,0 +1,52 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::HookData::SubgroupBuilder do + let_it_be(:parent_group) { create(:group) } + let_it_be(:subgroup) { create(:group, parent: parent_group) } + + describe '#build' do + let(:data) { described_class.new(subgroup).build(event) } + let(:event_name) { data[:event_name] } + let(:attributes) do + [ + :event_name, :created_at, :updated_at, :name, :path, :full_path, :group_id, + :parent_group_id, :parent_name, :parent_path, :parent_full_path + ] + 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(subgroup.name) + expect(data[:path]).to eq(subgroup.path) + expect(data[:full_path]).to eq(subgroup.full_path) + expect(data[:group_id]).to eq(subgroup.id) + expect(data[:created_at]).to eq(subgroup.created_at.xmlschema) + expect(data[:updated_at]).to eq(subgroup.updated_at.xmlschema) + expect(data[:parent_name]).to eq(parent_group.name) + expect(data[:parent_path]).to eq(parent_group.path) + expect(data[:parent_full_path]).to eq(parent_group.full_path) + expect(data[:parent_group_id]).to eq(parent_group.id) + end + end + + context 'on create' do + let(:event) { :create } + + it { expect(event_name).to eq('subgroup_create') } + it_behaves_like 'includes the required attributes' + end + + context 'on destroy' do + let(:event) { :destroy } + + it { expect(event_name).to eq('subgroup_destroy') } + it_behaves_like 'includes the required attributes' + end + end + end +end |