summaryrefslogtreecommitdiff
path: root/spec/presenters
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-17 18:09:44 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-17 18:09:44 +0000
commit2c156e3c7bbade01c36eee18327f1ced6eebea79 (patch)
tree115fa8dbf6bc05037378b380311d31acb805f54c /spec/presenters
parent8e129497b2565b8c595ef4f806d9a9595ca654e5 (diff)
downloadgitlab-ce-2c156e3c7bbade01c36eee18327f1ced6eebea79.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/presenters')
-rw-r--r--spec/presenters/projects/import_export/project_export_presenter_spec.rb92
1 files changed, 92 insertions, 0 deletions
diff --git a/spec/presenters/projects/import_export/project_export_presenter_spec.rb b/spec/presenters/projects/import_export/project_export_presenter_spec.rb
new file mode 100644
index 00000000000..052ca36974a
--- /dev/null
+++ b/spec/presenters/projects/import_export/project_export_presenter_spec.rb
@@ -0,0 +1,92 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Projects::ImportExport::ProjectExportPresenter do
+ let_it_be(:group) { create(:group) }
+ let_it_be(:project) { create(:project, group: group) }
+ let_it_be(:user) { create(:user) }
+
+ subject { described_class.new(project, current_user: user) }
+
+ describe '#description' do
+ context "override_description not provided" do
+ it "keeps original description" do
+ expect(subject.description).to eq(project.description)
+ end
+ end
+
+ context "override_description provided" do
+ let(:description) { "overridden description" }
+
+ subject { described_class.new(project, current_user: user, override_description: description) }
+
+ it "overrides description" do
+ expect(subject.description).to eq(description)
+ end
+ end
+ end
+
+ describe '#as_json' do
+ context "override_description not provided" do
+ it "keeps original description" do
+ expect(subject.as_json["description"]).to eq(project.description)
+ end
+ end
+
+ context "override_description provided" do
+ let(:description) { "overridden description" }
+
+ subject { described_class.new(project, current_user: user, override_description: description) }
+
+ it "overrides description" do
+ expect(subject.as_json["description"]).to eq(description)
+ end
+ end
+ end
+
+ describe '#project_members' do
+ let(:user2) { create(:user, email: 'group@member.com') }
+ let(:member_emails) do
+ subject.project_members.map do |pm|
+ pm.user.email
+ end
+ end
+
+ before do
+ group.add_developer(user2)
+ end
+
+ it 'does not export group members if it has no permission' do
+ group.add_developer(user)
+
+ expect(member_emails).not_to include('group@member.com')
+ end
+
+ it 'does not export group members as maintainer' do
+ group.add_maintainer(user)
+
+ expect(member_emails).not_to include('group@member.com')
+ end
+
+ it 'exports group members as group owner' do
+ group.add_owner(user)
+
+ expect(member_emails).to include('group@member.com')
+ end
+
+ context 'as admin' do
+ let(:user) { create(:admin) }
+
+ it 'exports group members as admin' do
+ expect(member_emails).to include('group@member.com')
+ end
+
+ it 'exports group members as project members' do
+ member_types = subject.project_members.map { |pm| pm.source_type }
+
+ expect(member_types).to all(eq('Project'))
+ end
+ end
+ end
+end