Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/hook_data/project_builder_spec.rb')
-rw-r--r--spec/lib/gitlab/hook_data/project_builder_spec.rb120
1 files changed, 92 insertions, 28 deletions
diff --git a/spec/lib/gitlab/hook_data/project_builder_spec.rb b/spec/lib/gitlab/hook_data/project_builder_spec.rb
index f80faac563d..9d5eaf0608c 100644
--- a/spec/lib/gitlab/hook_data/project_builder_spec.rb
+++ b/spec/lib/gitlab/hook_data/project_builder_spec.rb
@@ -4,8 +4,8 @@ require 'spec_helper'
RSpec.describe Gitlab::HookData::ProjectBuilder do
let_it_be(:user) { create(:user, name: 'John', email: 'john@example.com') }
- let_it_be(:namespace) { create(:namespace, owner: user) }
- let_it_be(:project) { create(:project, :internal, name: 'my_project', namespace: namespace) }
+ let_it_be(:user2) { create(:user, name: 'Peter') }
+ let_it_be(:user3_non_owner) { create(:user, name: 'Not_Owner') }
describe '#build' do
let(:data) { described_class.new(project).build(event) }
@@ -24,13 +24,13 @@ RSpec.describe Gitlab::HookData::ProjectBuilder do
expect(data[:created_at]).to eq(project.created_at.xmlschema)
expect(data[:updated_at]).to eq(project.updated_at.xmlschema)
- expect(data[:name]).to eq('my_project')
+ expect(data[:name]).to eq(project.name)
expect(data[:path]).to eq(project.path)
expect(data[:path_with_namespace]).to eq(project.full_path)
expect(data[:project_id]).to eq(project.id)
- expect(data[:owner_name]).to eq('John')
- expect(data[:owner_email]).to eq(_('[REDACTED]'))
- expect(data[:owners]).to contain_exactly({ name: 'John', email: _('[REDACTED]') })
+ expect(data[:owner_name]).to eq(owner_name)
+ expect(data[:owner_email]).to eq(owner_email)
+ expect(data[:owners]).to match_array(owners_data)
expect(data[:project_visibility]).to eq('internal')
end
end
@@ -48,40 +48,104 @@ RSpec.describe Gitlab::HookData::ProjectBuilder do
end
end
- context 'on create' do
- let(:event) { :create }
+ context 'the project is created in a personal namespace' do
+ let(:owner_name) { user.name }
+ let(:owner_email) { _('[REDACTED]') }
+ let(:owners_data) { [{ name: 'John', email: _('[REDACTED]') }, { name: 'Peter', email: _('[REDACTED]') }] }
+ let_it_be(:namespace) { create(:namespace, owner: user) }
+ let_it_be(:project) { create(:project, :internal, name: 'personal project', namespace: namespace) }
- it { expect(event_name).to eq('project_create') }
+ before_all do
+ project.add_owner(user2)
+ project.add_maintainer(user3_non_owner)
+ end
- it_behaves_like 'includes the required attributes'
- it_behaves_like 'does not include `old_path_with_namespace` attribute'
- end
+ context 'on create' do
+ let(:event) { :create }
- context 'on destroy' do
- let(:event) { :destroy }
+ it { expect(event_name).to eq('project_create') }
- it { expect(event_name).to eq('project_destroy') }
+ it_behaves_like 'includes the required attributes'
+ it_behaves_like 'does not include `old_path_with_namespace` attribute'
+ end
- it_behaves_like 'includes the required attributes'
- it_behaves_like 'does not include `old_path_with_namespace` attribute'
- end
+ context 'on destroy' do
+ let(:event) { :destroy }
+
+ it { expect(event_name).to eq('project_destroy') }
+
+ it_behaves_like 'includes the required attributes'
+ it_behaves_like 'does not include `old_path_with_namespace` attribute'
+ end
- context 'on rename' do
- let(:event) { :rename }
+ context 'on rename' do
+ let(:event) { :rename }
- it { expect(event_name).to eq('project_rename') }
+ it { expect(event_name).to eq('project_rename') }
- it_behaves_like 'includes the required attributes'
- it_behaves_like 'includes `old_path_with_namespace` attribute'
+ it_behaves_like 'includes the required attributes'
+ it_behaves_like 'includes `old_path_with_namespace` attribute'
+ end
+
+ context 'on transfer' do
+ let(:event) { :transfer }
+
+ it { expect(event_name).to eq('project_transfer') }
+
+ it_behaves_like 'includes the required attributes'
+ it_behaves_like 'includes `old_path_with_namespace` attribute'
+ end
end
- context 'on transfer' do
- let(:event) { :transfer }
+ context 'the project is created in a group' do
+ let(:owner_name) { group.name }
+ let(:owner_email) { "" }
+ let_it_be(:group) { create(:group) }
+ let_it_be(:project) { create(:project, :internal, name: 'group project', namespace: group) }
+ let(:owners_data) { [{ name: 'John', email: _('[REDACTED]') }, { email: "[REDACTED]", name: "Peter" }] }
+
+ before_all do
+ group.add_owner(user)
+ group.add_owner(user2)
+ group.add_maintainer(user3_non_owner)
+ end
+
+ # Repeat the tests in the previous context
+ context 'on create' do
+ let(:event) { :create }
- it { expect(event_name).to eq('project_transfer') }
+ it { expect(event_name).to eq('project_create') }
- it_behaves_like 'includes the required attributes'
- it_behaves_like 'includes `old_path_with_namespace` attribute'
+ it_behaves_like 'includes the required attributes'
+ it_behaves_like 'does not include `old_path_with_namespace` attribute'
+ end
+
+ context 'on destroy' do
+ let(:event) { :destroy }
+
+ it { expect(event_name).to eq('project_destroy') }
+
+ it_behaves_like 'includes the required attributes'
+ it_behaves_like 'does not include `old_path_with_namespace` attribute'
+ end
+
+ context 'on rename' do
+ let(:event) { :rename }
+
+ it { expect(event_name).to eq('project_rename') }
+
+ it_behaves_like 'includes the required attributes'
+ it_behaves_like 'includes `old_path_with_namespace` attribute'
+ end
+
+ context 'on transfer' do
+ let(:event) { :transfer }
+
+ it { expect(event_name).to eq('project_transfer') }
+
+ it_behaves_like 'includes the required attributes'
+ it_behaves_like 'includes `old_path_with_namespace` attribute'
+ end
end
end
end