diff options
Diffstat (limited to 'spec/lib/gitlab/import_export')
5 files changed, 67 insertions, 123 deletions
diff --git a/spec/lib/gitlab/import_export/all_models.yml b/spec/lib/gitlab/import_export/all_models.yml index 3126d87a0d6..7c33f29ebf3 100644 --- a/spec/lib/gitlab/import_export/all_models.yml +++ b/spec/lib/gitlab/import_export/all_models.yml @@ -51,6 +51,7 @@ issues: - status_page_published_incident - namespace - note_authors +- issue_email_participants events: - author - project @@ -242,6 +243,7 @@ ci_pipelines: - latest_builds_report_results - messages - pipeline_artifacts +- latest_statuses ci_refs: - project - ci_pipelines @@ -536,6 +538,8 @@ project: - vulnerability_historical_statistics - product_analytics_events - pipeline_artifacts +- terraform_states +- alert_management_http_integrations award_emoji: - awardable - user diff --git a/spec/lib/gitlab/import_export/fast_hash_serializer_spec.rb b/spec/lib/gitlab/import_export/fast_hash_serializer_spec.rb index 93b6f93f0ec..d084b9d7f7e 100644 --- a/spec/lib/gitlab/import_export/fast_hash_serializer_spec.rb +++ b/spec/lib/gitlab/import_export/fast_hash_serializer_spec.rb @@ -10,14 +10,17 @@ RSpec.describe Gitlab::ImportExport::FastHashSerializer do # all items are properly serialized while traversing the simple hash. subject { Gitlab::Json.parse(Gitlab::Json.generate(described_class.new(project, tree).execute)) } - let!(:project) { setup_project } - let(:user) { create(:user) } + let_it_be(:user) { create(:user) } + let_it_be(:project) { setup_project } let(:shared) { project.import_export_shared } let(:reader) { Gitlab::ImportExport::Reader.new(shared: shared) } let(:tree) { reader.project_tree } - before do + before_all do project.add_maintainer(user) + end + + before do allow_any_instance_of(MergeRequest).to receive(:source_branch_sha).and_return('ABCD') allow_any_instance_of(MergeRequest).to receive(:target_branch_sha).and_return('DCBA') end @@ -224,7 +227,6 @@ RSpec.describe Gitlab::ImportExport::FastHashSerializer do group: group, approvals_before_merge: 1 ) - allow(project).to receive(:commit).and_return(Commit.new(RepoHelpers.sample_commit, project)) issue = create(:issue, assignees: [user], project: project) snippet = create(:project_snippet, project: project) diff --git a/spec/lib/gitlab/import_export/group/relation_factory_spec.rb b/spec/lib/gitlab/import_export/group/relation_factory_spec.rb index eb9a3fa9bd8..6b2f80cc80a 100644 --- a/spec/lib/gitlab/import_export/group/relation_factory_spec.rb +++ b/spec/lib/gitlab/import_export/group/relation_factory_spec.rb @@ -5,16 +5,19 @@ require 'spec_helper' RSpec.describe Gitlab::ImportExport::Group::RelationFactory do let(:group) { create(:group) } let(:members_mapper) { double('members_mapper').as_null_object } - let(:user) { create(:admin) } + let(:admin) { create(:admin) } + let(:importer_user) { admin } let(:excluded_keys) { [] } let(:created_object) do - described_class.create(relation_sym: relation_sym, - relation_hash: relation_hash, - members_mapper: members_mapper, - object_builder: Gitlab::ImportExport::Group::ObjectBuilder, - user: user, - importable: group, - excluded_keys: excluded_keys) + described_class.create( + relation_sym: relation_sym, + relation_hash: relation_hash, + members_mapper: members_mapper, + object_builder: Gitlab::ImportExport::Group::ObjectBuilder, + user: importer_user, + importable: group, + excluded_keys: excluded_keys + ) end context 'label object' do @@ -24,18 +27,18 @@ RSpec.describe Gitlab::ImportExport::Group::RelationFactory do let(:relation_hash) do { - 'id' => 123456, - 'title' => 'Bruffefunc', - 'color' => '#1d2da4', - 'project_id' => nil, - 'created_at' => '2019-11-20T17:02:20.546Z', - 'updated_at' => '2019-11-20T17:02:20.546Z', - 'template' => false, + 'id' => 123456, + 'title' => 'Bruffefunc', + 'color' => '#1d2da4', + 'project_id' => nil, + 'created_at' => '2019-11-20T17:02:20.546Z', + 'updated_at' => '2019-11-20T17:02:20.546Z', + 'template' => false, 'description' => 'Description', - 'group_id' => original_group_id, - 'type' => 'GroupLabel', - 'priorities' => [], - 'textColor' => '#FFFFFF' + 'group_id' => original_group_id, + 'type' => 'GroupLabel', + 'priorities' => [], + 'textColor' => '#FFFFFF' } end @@ -60,58 +63,28 @@ RSpec.describe Gitlab::ImportExport::Group::RelationFactory do end end - context 'Notes user references' do - let(:relation_sym) { :notes } - let(:new_user) { create(:user) } - let(:exported_member) do - { - 'id' => 111, - 'access_level' => 30, - 'source_id' => 1, - 'source_type' => 'Namespace', - 'user_id' => 3, - 'notification_level' => 3, - 'created_at' => '2016-11-18T09:29:42.634Z', - 'updated_at' => '2016-11-18T09:29:42.634Z', - 'user' => { - 'id' => 999, - 'email' => new_user.email, - 'username' => new_user.username - } - } - end - + it_behaves_like 'Notes user references' do + let(:importable) { group } let(:relation_hash) do { - 'id' => 4947, - 'note' => 'note', + 'id' => 4947, + 'note' => 'note', 'noteable_type' => 'Epic', - 'author_id' => 999, - 'created_at' => '2016-11-18T09:29:42.634Z', - 'updated_at' => '2016-11-18T09:29:42.634Z', - 'project_id' => 1, - 'attachment' => { + 'author_id' => 999, + 'created_at' => '2016-11-18T09:29:42.634Z', + 'updated_at' => '2016-11-18T09:29:42.634Z', + 'project_id' => 1, + 'attachment' => { 'url' => nil }, - 'noteable_id' => 377, - 'system' => true, - 'author' => { + 'noteable_id' => 377, + 'system' => true, + 'author' => { 'name' => 'Administrator' }, 'events' => [] } end - - let(:members_mapper) do - Gitlab::ImportExport::MembersMapper.new( - exported_members: [exported_member], - user: user, - importable: group) - end - - it 'maps the right author to the imported note' do - expect(created_object.author).to eq(new_user) - end end def random_id diff --git a/spec/lib/gitlab/import_export/lfs_saver_spec.rb b/spec/lib/gitlab/import_export/lfs_saver_spec.rb index db76eb9538b..55b4f7479b8 100644 --- a/spec/lib/gitlab/import_export/lfs_saver_spec.rb +++ b/spec/lib/gitlab/import_export/lfs_saver_spec.rb @@ -74,14 +74,6 @@ RSpec.describe Gitlab::ImportExport::LfsSaver do } ) end - - it 'does not save a json file if feature is disabled' do - stub_feature_flags(export_lfs_objects_projects: false) - - saver.save - - expect(File.exist?(lfs_json_file)).to eq(false) - end end end diff --git a/spec/lib/gitlab/import_export/project/relation_factory_spec.rb b/spec/lib/gitlab/import_export/project/relation_factory_spec.rb index 31cf2362628..50bc6a30044 100644 --- a/spec/lib/gitlab/import_export/project/relation_factory_spec.rb +++ b/spec/lib/gitlab/import_export/project/relation_factory_spec.rb @@ -3,19 +3,22 @@ require 'spec_helper' RSpec.describe Gitlab::ImportExport::Project::RelationFactory do - let(:group) { create(:group) } + let(:group) { create(:group) } let(:project) { create(:project, :repository, group: group) } let(:members_mapper) { double('members_mapper').as_null_object } - let(:user) { create(:admin) } + let(:admin) { create(:admin) } + let(:importer_user) { admin } let(:excluded_keys) { [] } let(:created_object) do - described_class.create(relation_sym: relation_sym, - relation_hash: relation_hash, - object_builder: Gitlab::ImportExport::Project::ObjectBuilder, - members_mapper: members_mapper, - user: user, - importable: project, - excluded_keys: excluded_keys) + described_class.create( + relation_sym: relation_sym, + relation_hash: relation_hash, + object_builder: Gitlab::ImportExport::Project::ObjectBuilder, + members_mapper: members_mapper, + user: importer_user, + importable: project, + excluded_keys: excluded_keys + ) end before do @@ -113,9 +116,9 @@ RSpec.describe Gitlab::ImportExport::Project::RelationFactory do "created_at" => "2016-11-18T09:29:42.634Z", "updated_at" => "2016-11-18T09:29:42.634Z", "user" => { - "id" => user.id, - "email" => user.email, - "username" => user.username + "id" => admin.id, + "email" => admin.email, + "username" => admin.username } } end @@ -123,7 +126,7 @@ RSpec.describe Gitlab::ImportExport::Project::RelationFactory do let(:members_mapper) do Gitlab::ImportExport::MembersMapper.new( exported_members: [exported_member], - user: user, + user: importer_user, importable: project) end @@ -134,9 +137,9 @@ RSpec.describe Gitlab::ImportExport::Project::RelationFactory do 'source_branch' => "feature_conflict", 'source_project_id' => project.id, 'target_project_id' => project.id, - 'author_id' => user.id, - 'assignee_id' => user.id, - 'updated_by_id' => user.id, + 'author_id' => admin.id, + 'assignee_id' => admin.id, + 'updated_by_id' => admin.id, 'title' => "MR1", 'created_at' => "2016-06-14T15:02:36.568Z", 'updated_at' => "2016-06-14T15:02:56.815Z", @@ -151,11 +154,11 @@ RSpec.describe Gitlab::ImportExport::Project::RelationFactory do end it 'has preloaded author' do - expect(created_object.author).to equal(user) + expect(created_object.author).to equal(admin) end it 'has preloaded updated_by' do - expect(created_object.updated_by).to equal(user) + expect(created_object.updated_by).to equal(admin) end it 'has preloaded source project' do @@ -264,27 +267,8 @@ RSpec.describe Gitlab::ImportExport::Project::RelationFactory do end end - context 'Notes user references' do - let(:relation_sym) { :notes } - let(:new_user) { create(:user) } - let(:exported_member) do - { - "id" => 111, - "access_level" => 30, - "source_id" => 1, - "source_type" => "Project", - "user_id" => 3, - "notification_level" => 3, - "created_at" => "2016-11-18T09:29:42.634Z", - "updated_at" => "2016-11-18T09:29:42.634Z", - "user" => { - "id" => 999, - "email" => new_user.email, - "username" => new_user.username - } - } - end - + it_behaves_like 'Notes user references' do + let(:importable) { project } let(:relation_hash) do { "id" => 4947, @@ -305,17 +289,6 @@ RSpec.describe Gitlab::ImportExport::Project::RelationFactory do "events" => [] } end - - let(:members_mapper) do - Gitlab::ImportExport::MembersMapper.new( - exported_members: [exported_member], - user: user, - importable: project) - end - - it 'maps the right author to the imported note' do - expect(created_object.author).to eq(new_user) - end end context 'encrypted attributes' do |