2021-04-30 08:12:30 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe BulkImports::Export, type: :model do
|
|
|
|
describe 'associations' do
|
|
|
|
it { is_expected.to belong_to(:group) }
|
|
|
|
it { is_expected.to belong_to(:project) }
|
|
|
|
it { is_expected.to have_one(:upload) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'validations' do
|
|
|
|
it { is_expected.to validate_presence_of(:relation) }
|
|
|
|
it { is_expected.to validate_presence_of(:status) }
|
|
|
|
|
|
|
|
context 'when not associated with a group or project' do
|
|
|
|
it 'is invalid' do
|
|
|
|
export = build(:bulk_import_export, group: nil, project: nil)
|
|
|
|
|
|
|
|
expect(export).not_to be_valid
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when associated with a group' do
|
|
|
|
it 'is valid' do
|
|
|
|
export = build(:bulk_import_export, group: build(:group), project: nil)
|
|
|
|
|
|
|
|
expect(export).to be_valid
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when associated with a project' do
|
|
|
|
it 'is valid' do
|
|
|
|
export = build(:bulk_import_export, group: nil, project: build(:project))
|
|
|
|
|
|
|
|
expect(export).to be_valid
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when relation is invalid' do
|
|
|
|
it 'is invalid' do
|
|
|
|
export = build(:bulk_import_export, relation: 'unsupported')
|
|
|
|
|
|
|
|
expect(export).not_to be_valid
|
|
|
|
expect(export.errors).to include(:relation)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-05-12 05:10:19 -04:00
|
|
|
describe '#portable' do
|
2021-04-30 08:12:30 -04:00
|
|
|
context 'when associated with project' do
|
|
|
|
it 'returns project' do
|
|
|
|
export = create(:bulk_import_export, project: create(:project), group: nil)
|
|
|
|
|
2021-05-12 05:10:19 -04:00
|
|
|
expect(export.portable).to be_instance_of(Project)
|
2021-04-30 08:12:30 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when associated with group' do
|
|
|
|
it 'returns group' do
|
|
|
|
export = create(:bulk_import_export)
|
|
|
|
|
2021-05-12 05:10:19 -04:00
|
|
|
expect(export.portable).to be_instance_of(Group)
|
2021-04-30 08:12:30 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#config' do
|
|
|
|
context 'when associated with project' do
|
|
|
|
it 'returns project config' do
|
|
|
|
export = create(:bulk_import_export, project: create(:project), group: nil)
|
|
|
|
|
2021-05-12 05:10:19 -04:00
|
|
|
expect(export.config).to be_instance_of(BulkImports::FileTransfer::ProjectConfig)
|
2021-04-30 08:12:30 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when associated with group' do
|
|
|
|
it 'returns group config' do
|
|
|
|
export = create(:bulk_import_export)
|
|
|
|
|
2021-05-12 05:10:19 -04:00
|
|
|
expect(export.config).to be_instance_of(BulkImports::FileTransfer::GroupConfig)
|
2021-04-30 08:12:30 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|