1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe BulkImports::Export, type: :model, feature_category: :importers 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) }
it { is_expected.to have_many(:batches) }
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
describe '#portable' do
context 'when associated with project' do
it 'returns project' do
export = create(:bulk_import_export, project: create(:project), group: nil)
expect(export.portable).to be_instance_of(Project)
end
end
context 'when associated with group' do
it 'returns group' do
export = create(:bulk_import_export)
expect(export.portable).to be_instance_of(Group)
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)
expect(export.config).to be_instance_of(BulkImports::FileTransfer::ProjectConfig)
end
end
context 'when associated with group' do
it 'returns group config' do
export = create(:bulk_import_export)
expect(export.config).to be_instance_of(BulkImports::FileTransfer::GroupConfig)
end
end
end
describe '#remove_existing_upload!' do
context 'when upload exists' do
it 'removes the upload' do
export = create(:bulk_import_export)
upload = create(:bulk_import_export_upload, export: export)
upload.update!(export_file: fixture_file_upload('spec/fixtures/bulk_imports/gz/labels.ndjson.gz'))
expect_any_instance_of(BulkImports::ExportUpload) do |upload|
expect(upload).to receive(:remove_export_file!)
expect(upload).to receive(:save!)
end
export.remove_existing_upload!
end
end
context 'when upload does not exist' do
it 'returns' do
export = build(:bulk_import_export)
expect { export.remove_existing_upload! }.not_to change { export.upload }
end
end
end
end
|