diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-15 15:08:45 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-15 15:08:45 +0000 |
commit | d9e71b0d412fb9d2d7fc8b00dddac21617eaaf19 (patch) | |
tree | 704cd8a52cf1e068bcd2e82cc1a0112e9674ef5d /spec/models/bulk_imports | |
parent | 6ae38bb3b5dc719fb6a046dcbcce4671176395a2 (diff) | |
download | gitlab-ce-d9e71b0d412fb9d2d7fc8b00dddac21617eaaf19.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models/bulk_imports')
-rw-r--r-- | spec/models/bulk_imports/configuration_spec.rb | 17 | ||||
-rw-r--r-- | spec/models/bulk_imports/entity_spec.rb | 85 |
2 files changed, 102 insertions, 0 deletions
diff --git a/spec/models/bulk_imports/configuration_spec.rb b/spec/models/bulk_imports/configuration_spec.rb new file mode 100644 index 00000000000..1cbfef631ac --- /dev/null +++ b/spec/models/bulk_imports/configuration_spec.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe BulkImports::Configuration, type: :model do + describe 'associations' do + it { is_expected.to belong_to(:bulk_import).required } + end + + describe 'validations' do + it { is_expected.to validate_length_of(:url).is_at_most(255) } + it { is_expected.to validate_length_of(:access_token).is_at_most(255) } + + it { is_expected.to validate_presence_of(:url) } + it { is_expected.to validate_presence_of(:access_token) } + end +end diff --git a/spec/models/bulk_imports/entity_spec.rb b/spec/models/bulk_imports/entity_spec.rb new file mode 100644 index 00000000000..ad6e3ec6f30 --- /dev/null +++ b/spec/models/bulk_imports/entity_spec.rb @@ -0,0 +1,85 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe BulkImports::Entity, type: :model do + describe 'associations' do + it { is_expected.to belong_to(:bulk_import).required } + it { is_expected.to belong_to(:parent) } + it { is_expected.to belong_to(:group) } + it { is_expected.to belong_to(:project) } + end + + describe 'validations' do + it { is_expected.to validate_presence_of(:source_type) } + it { is_expected.to validate_presence_of(:source_full_path) } + it { is_expected.to validate_presence_of(:destination_name) } + it { is_expected.to validate_presence_of(:destination_namespace) } + + it { is_expected.to define_enum_for(:source_type).with_values(%i[group_entity project_entity]) } + + context 'when associated with a group and project' do + it 'is invalid' do + entity = build(:bulk_import_entity, group: build(:group), project: build(:project)) + + expect(entity).not_to be_valid + expect(entity.errors).to include(:project, :group) + end + end + + context 'when not associated with a group or project' do + it 'is valid' do + entity = build(:bulk_import_entity, group: nil, project: nil) + + expect(entity).to be_valid + end + end + + context 'when associated with a group and no project' do + it 'is valid as a group_entity' do + entity = build(:bulk_import_entity, :group_entity, group: build(:group), project: nil) + + expect(entity).to be_valid + end + + it 'is invalid as a project_entity' do + entity = build(:bulk_import_entity, :project_entity, group: build(:group), project: nil) + + expect(entity).not_to be_valid + expect(entity.errors).to include(:group) + end + end + + context 'when associated with a project and no group' do + it 'is valid' do + entity = build(:bulk_import_entity, :project_entity, group: nil, project: build(:project)) + + expect(entity).to be_valid + end + + it 'is invalid as a project_entity' do + entity = build(:bulk_import_entity, :group_entity, group: nil, project: build(:project)) + + expect(entity).not_to be_valid + expect(entity.errors).to include(:project) + end + end + + context 'when the parent is a group import' do + it 'is valid' do + entity = build(:bulk_import_entity, parent: build(:bulk_import_entity, :group_entity)) + + expect(entity).to be_valid + end + end + + context 'when the parent is a project import' do + it 'is invalid' do + entity = build(:bulk_import_entity, parent: build(:bulk_import_entity, :project_entity)) + + expect(entity).not_to be_valid + expect(entity.errors).to include(:parent) + end + end + end +end |