topographer 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/topographer/exceptions.rb +5 -3
- data/lib/topographer/importer.rb +25 -9
- data/lib/topographer/importer/helpers.rb +19 -13
- data/lib/topographer/importer/helpers/write_log_to_csv.rb +75 -67
- data/lib/topographer/importer/importable.rb +7 -3
- data/lib/topographer/importer/input.rb +11 -4
- data/lib/topographer/importer/input/base.rb +21 -15
- data/lib/topographer/importer/input/delimited_spreadsheet.rb +55 -0
- data/lib/topographer/importer/input/roo.rb +31 -24
- data/lib/topographer/importer/input/source_data.rb +14 -8
- data/lib/topographer/importer/logger.rb +10 -6
- data/lib/topographer/importer/logger/base.rb +75 -66
- data/lib/topographer/importer/logger/fatal_error_entry.rb +22 -16
- data/lib/topographer/importer/logger/log_entry.rb +31 -25
- data/lib/topographer/importer/logger/simple.rb +25 -19
- data/lib/topographer/importer/mapper.rb +58 -53
- data/lib/topographer/importer/mapper/default_field_mapping.rb +23 -17
- data/lib/topographer/importer/mapper/field_mapping.rb +56 -49
- data/lib/topographer/importer/mapper/ignored_field_mapping.rb +14 -7
- data/lib/topographer/importer/mapper/mapper_builder.rb +57 -44
- data/lib/topographer/importer/mapper/mapping_columns.rb +51 -44
- data/lib/topographer/importer/mapper/mapping_validator.rb +39 -32
- data/lib/topographer/importer/mapper/result.rb +21 -15
- data/lib/topographer/importer/mapper/validation_field_mapping.rb +35 -28
- data/lib/topographer/importer/strategy.rb +12 -6
- data/lib/topographer/importer/strategy/base.rb +43 -38
- data/lib/topographer/importer/strategy/create_or_update_record.rb +39 -34
- data/lib/topographer/importer/strategy/import_new_record.rb +16 -10
- data/lib/topographer/importer/strategy/import_status.rb +27 -20
- data/lib/topographer/importer/strategy/update_record.rb +28 -24
- data/lib/topographer/version.rb +1 -1
- data/spec/assets/test_files/a_csv.csv +3 -0
- data/spec/topographer/importer/helpers/write_log_to_csv_spec.rb +4 -4
- data/spec/topographer/importer/importer_spec.rb +21 -5
- data/spec/topographer/importer/input/delimited_spreadsheet_spec.rb +90 -0
- data/spec/topographer/importer/input/source_data_spec.rb +2 -2
- data/spec/topographer/importer/logger/base_spec.rb +19 -0
- data/spec/topographer/importer/logger/fatal_error_entry_spec.rb +2 -2
- data/spec/topographer/importer/logger/simple_spec.rb +3 -3
- data/spec/topographer/importer/mapper/default_field_mapping_spec.rb +2 -2
- data/spec/topographer/importer/mapper/field_mapping_spec.rb +21 -21
- data/spec/topographer/importer/mapper/mapper_builder_spec.rb +9 -9
- data/spec/topographer/importer/mapper/mapping_validator_spec.rb +10 -10
- data/spec/topographer/importer/mapper/validation_field_mapping_spec.rb +3 -3
- data/spec/topographer/importer/mapper_spec.rb +25 -25
- data/spec/topographer/importer/strategy/base_spec.rb +16 -5
- data/spec/topographer/importer/strategy/create_or_update_record_spec.rb +3 -3
- data/spec/topographer/importer/strategy/import_new_records_spec.rb +5 -5
- data/spec/topographer/importer/strategy/mapped_model.rb +9 -0
- data/spec/topographer/importer/strategy/update_record_spec.rb +3 -3
- data/topographer.gemspec +3 -2
- metadata +101 -102
data/lib/topographer/version.rb
CHANGED
@@ -55,14 +55,14 @@ describe Topographer::Importer::Helpers::WriteLogToCSV do
|
|
55
55
|
describe '#write_log_to_csv' do
|
56
56
|
it 'should write a passed logger instance to a CSV file' do
|
57
57
|
file = double('file')
|
58
|
-
CSV.
|
59
|
-
file.
|
58
|
+
expect(CSV).to receive(:open).with('fake_file_path', 'wb').and_yield(file)
|
59
|
+
expect(file).to receive(:<<).exactly(12).times
|
60
60
|
Topographer::Importer::Helpers::WriteLogToCSV.instance.write_log_to_csv(logger, 'fake_file_path', write_all: true)
|
61
61
|
end
|
62
62
|
it 'should only write failures and fatal errors if write_all is false' do
|
63
63
|
file = double('file')
|
64
|
-
CSV.
|
65
|
-
file.
|
64
|
+
expect(CSV).to receive(:open).with('fake_file_path', 'wb').and_yield(file)
|
65
|
+
expect(file).to receive(:<<).exactly(10).times
|
66
66
|
Topographer::Importer::Helpers::WriteLogToCSV.instance.write_log_to_csv(logger, 'fake_file_path', write_all: false)
|
67
67
|
end
|
68
68
|
end
|
@@ -108,28 +108,44 @@ describe Topographer::Importer do
|
|
108
108
|
end
|
109
109
|
|
110
110
|
it 'logs invalid data' do
|
111
|
-
expect(import_log.errors?).to
|
111
|
+
expect(import_log.errors?).to be_truthy
|
112
112
|
expect(import_log.failed_imports).to be 1
|
113
113
|
end
|
114
114
|
|
115
115
|
it 'does not import data with an invalid header' do
|
116
116
|
import_log = Topographer::Importer.import_data(bad_header_input, model_class, strategy_class, simple_logger)
|
117
|
-
expect(import_log.errors?).to
|
118
|
-
expect(import_log.fatal_error?).to
|
117
|
+
expect(import_log.errors?).to be_truthy
|
118
|
+
expect(import_log.fatal_error?).to be_truthy
|
119
119
|
expect(import_log.fatal_errors.first.message).
|
120
120
|
to match(/Invalid Input Header.+Missing Columns:\s+Field2.+Invalid Columns:\s+BadCol1.+BadCol2/)
|
121
121
|
end
|
122
122
|
|
123
123
|
it 'does import data with umapped columns when ignoring unmapped columns' do
|
124
124
|
extra_column_input = input
|
125
|
-
extra_column_input.
|
125
|
+
allow(extra_column_input).to receive(:get_header) { %w(Field1 Field2 Field3 UnknownField1) }
|
126
126
|
|
127
127
|
import_log = Topographer::Importer.import_data(extra_column_input, model_class, strategy_class, simple_logger, ignore_unmapped_columns: true)
|
128
128
|
|
129
|
-
expect(import_log.fatal_error?).to
|
129
|
+
expect(import_log.fatal_error?).to be_falsey
|
130
130
|
expect(import_log.total_imports).to be 4
|
131
131
|
expect(import_log.successful_imports).to be 3
|
132
132
|
end
|
133
|
+
context 'using an instance of a strategy class' do
|
134
|
+
let(:hash_strategy) do
|
135
|
+
HashImportStrategy.new(nil)
|
136
|
+
end
|
137
|
+
before do
|
138
|
+
allow(hash_strategy).to receive(:mapper=).and_call_original
|
139
|
+
end
|
140
|
+
it 'sets the mapper of the strategy class' do
|
141
|
+
Topographer::Importer.import_data(input, model_class, hash_strategy, simple_logger)
|
142
|
+
expect(hash_strategy).to have_received(:mapper=)
|
143
|
+
end
|
144
|
+
it 'imports data from valid import objects' do
|
145
|
+
import_log = Topographer::Importer.import_data(input, model_class, hash_strategy, simple_logger)
|
146
|
+
expect(import_log.total_imports).to be 4
|
147
|
+
end
|
148
|
+
end
|
133
149
|
end
|
134
150
|
describe '.build_mapper' do
|
135
151
|
it 'returns a mapper with the defined mappings' do
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Topographer::Importer::Input::DelimitedSpreadsheet do
|
4
|
+
let(:csv_path) do
|
5
|
+
File.expand_path(File.join(__dir__, '../../../assets/test_files/a_csv.csv'))
|
6
|
+
end
|
7
|
+
let(:csv_object) do
|
8
|
+
file = File.open(csv_path, 'r')
|
9
|
+
CSV.new(file, headers: true)
|
10
|
+
end
|
11
|
+
let(:name) do
|
12
|
+
'csv_name'
|
13
|
+
end
|
14
|
+
|
15
|
+
subject do
|
16
|
+
described_class.new(name, csv_object)
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#get_header' do
|
20
|
+
context 'headers read before input created' do
|
21
|
+
let(:csv_object) do
|
22
|
+
CSV.read(csv_path, headers: true)
|
23
|
+
end
|
24
|
+
it 'returns the headers that were previously read' do
|
25
|
+
expect(subject.get_header).to eql ['header 1', 'header 2']
|
26
|
+
end
|
27
|
+
end
|
28
|
+
context 'headers not read yet' do
|
29
|
+
let(:csv_object) do
|
30
|
+
file = File.open(csv_path, 'r')
|
31
|
+
CSV.new(file, headers: true)
|
32
|
+
end
|
33
|
+
it 'returns the headers that were previously read' do
|
34
|
+
expect(subject.get_header).to eql ['header 1', 'header 2']
|
35
|
+
end
|
36
|
+
end
|
37
|
+
context 'headers will never be read' do
|
38
|
+
let(:csv_object) do
|
39
|
+
file = File.open(csv_path, 'r')
|
40
|
+
CSV.new(file)
|
41
|
+
end
|
42
|
+
it 'returns an empty array' do
|
43
|
+
expect(subject.get_header).to eql []
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe '#input_identifier' do
|
49
|
+
it 'returns the csv name passed in' do
|
50
|
+
expect(subject.input_identifier).to eql name
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe '#each' do
|
55
|
+
it 'yields a SourceData object for each row in the sheet' do
|
56
|
+
expected_data = [
|
57
|
+
{
|
58
|
+
'header 1' => '1',
|
59
|
+
'header 2' => '2',
|
60
|
+
},
|
61
|
+
{
|
62
|
+
'header 1' => '3',
|
63
|
+
'header 2' => 'foo'
|
64
|
+
}
|
65
|
+
]
|
66
|
+
subject.each_with_index do |source_data, index|
|
67
|
+
expect(source_data.data).to eql expected_data[index]
|
68
|
+
end
|
69
|
+
end
|
70
|
+
it 'yields the same data with multiple calls' do
|
71
|
+
expected_data = [
|
72
|
+
{
|
73
|
+
'header 1' => '1',
|
74
|
+
'header 2' => '2',
|
75
|
+
},
|
76
|
+
{
|
77
|
+
'header 1' => '3',
|
78
|
+
'header 2' => 'foo'
|
79
|
+
}
|
80
|
+
]
|
81
|
+
subject.each_with_index do |source_data, index|
|
82
|
+
expect(source_data.data).to eql expected_data[index]
|
83
|
+
end
|
84
|
+
subject.each_with_index do |source_data, index|
|
85
|
+
expect(source_data.data).to eql expected_data[index]
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
@@ -12,10 +12,10 @@ describe Topographer::Importer::Input::SourceData do
|
|
12
12
|
|
13
13
|
describe '#empty?' do
|
14
14
|
it 'should return true if there is no data' do
|
15
|
-
expect(with_no_data.empty?).to
|
15
|
+
expect(with_no_data.empty?).to be_truthy
|
16
16
|
end
|
17
17
|
it 'should return false if there is data' do
|
18
|
-
expect(with_data.empty?).to
|
18
|
+
expect(with_data.empty?).to be_falsey
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
@@ -9,4 +9,23 @@ describe Topographer::Importer::Logger::Base do
|
|
9
9
|
expect(logger.fatal_errors.first)
|
10
10
|
end
|
11
11
|
end
|
12
|
+
describe '#success?' do
|
13
|
+
context 'no errors' do
|
14
|
+
before do
|
15
|
+
allow(subject).to receive(:errors?).and_return false
|
16
|
+
end
|
17
|
+
it 'returns true' do
|
18
|
+
expect(subject.success?).to be_truthy
|
19
|
+
end
|
20
|
+
end
|
21
|
+
context 'errors' do
|
22
|
+
before do
|
23
|
+
allow(subject).to receive(:errors?).and_return true
|
24
|
+
end
|
25
|
+
it 'returns false' do
|
26
|
+
expect(subject.success?).to be_falsey
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
12
31
|
end
|
@@ -4,12 +4,12 @@ describe Topographer::Importer::Logger::FatalErrorEntry do
|
|
4
4
|
let(:entry) { Topographer::Importer::Logger::FatalErrorEntry.new('test-input', 'failure message') }
|
5
5
|
describe '#failure?' do
|
6
6
|
it 'should return true' do
|
7
|
-
expect(entry.failure?).to
|
7
|
+
expect(entry.failure?).to be_truthy
|
8
8
|
end
|
9
9
|
end
|
10
10
|
describe '#success?' do
|
11
11
|
it 'should return false' do
|
12
|
-
expect(entry.success?).to
|
12
|
+
expect(entry.success?).to be_falsey
|
13
13
|
end
|
14
14
|
end
|
15
15
|
describe '#source_identifier' do
|
@@ -37,17 +37,17 @@ describe Topographer::Importer::Logger::Simple do
|
|
37
37
|
describe '#errors?' do
|
38
38
|
it 'returns true if there are fatal errors' do
|
39
39
|
logger.log_fatal('input', 'FATAL ERROR')
|
40
|
-
expect(logger.errors?).to
|
40
|
+
expect(logger.errors?).to be_truthy
|
41
41
|
end
|
42
42
|
it 'returns true if there are import errors' do
|
43
43
|
logger.log_failure({record_id: 2,
|
44
44
|
message: 'failure'})
|
45
|
-
expect(logger.errors?).to
|
45
|
+
expect(logger.errors?).to be_truthy
|
46
46
|
end
|
47
47
|
it 'returns false if there are no errors' do
|
48
48
|
logger.log_success({record_id: 2,
|
49
49
|
message: 'failure'})
|
50
|
-
expect(logger.errors?).to
|
50
|
+
expect(logger.errors?).to be_falsey
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
@@ -23,12 +23,12 @@ describe Topographer::Importer::Mapper::DefaultFieldMapping do
|
|
23
23
|
describe '#process_input' do
|
24
24
|
it 'should return the result of the behavior block' do
|
25
25
|
static_mapping.process_input({}, result)
|
26
|
-
expect(result.errors?).to
|
26
|
+
expect(result.errors?).to be_falsey
|
27
27
|
expect(result.data['field1']).to be 15
|
28
28
|
end
|
29
29
|
it 'should record any exceptions that occur within the block as errors' do
|
30
30
|
failed_static_mapping.process_input({}, result)
|
31
|
-
expect(result.errors?).to
|
31
|
+
expect(result.errors?).to be_truthy
|
32
32
|
expect(result.errors.values).to include('FAILURE')
|
33
33
|
end
|
34
34
|
it 'should not rescue Exceptions that do not inherit from standard error' do
|
@@ -37,82 +37,82 @@ describe Topographer::Importer::Mapper::FieldMapping do
|
|
37
37
|
context 'required mappings' do
|
38
38
|
it 'maps required simple mappings when input is valid' do
|
39
39
|
required_simple_mapping.process_input(valid_input, result)
|
40
|
-
expect(result.errors?).to
|
40
|
+
expect(result.errors?).to be_falsey
|
41
41
|
expect(result.data['output_column']).to eql(4)
|
42
42
|
end
|
43
43
|
it 'maps required complex mappings when input is valid' do
|
44
44
|
required_complex_mapping.process_input(valid_input, result)
|
45
|
-
expect(result.errors?).to
|
45
|
+
expect(result.errors?).to be_falsey
|
46
46
|
expect(result.data['output_column']).to eql(15)
|
47
47
|
end
|
48
48
|
it 'returns an error for required simple mappings when the input key is missing' do
|
49
49
|
required_simple_mapping.process_input({}, result)
|
50
|
-
expect(result.errors?).to
|
50
|
+
expect(result.errors?).to be_truthy
|
51
51
|
expect(result.errors.values).to include('Missing required input(s): `field1` for `output_column`')
|
52
|
-
expect(result.data.empty?).to
|
52
|
+
expect(result.data.empty?).to be_truthy
|
53
53
|
end
|
54
54
|
it 'returns an error for required simple mappings when the input data is blank' do
|
55
55
|
required_simple_mapping.process_input({'field1' => nil}, result)
|
56
|
-
expect(result.errors?).to
|
56
|
+
expect(result.errors?).to be_truthy
|
57
57
|
expect(result.errors.values).to include('Missing required input(s): `field1` for `output_column`')
|
58
58
|
expect(result.data['output_column']).to be_nil
|
59
59
|
end
|
60
60
|
it 'returns an error for required simple mappings when the mapping block raises an exception' do
|
61
61
|
required_simple_mapping_with_validation.process_input({'field1' => 3}, result)
|
62
|
-
expect(result.errors?).to
|
62
|
+
expect(result.errors?).to be_truthy
|
63
63
|
expect(result.errors.values).to include('Field1 MUST BE 4')
|
64
|
-
expect(result.data.empty?).to
|
64
|
+
expect(result.data.empty?).to be_truthy
|
65
65
|
end
|
66
66
|
it 'returns an error for required complex mappings when the input key is missing' do
|
67
67
|
required_complex_mapping.process_input({'field1' => 4}, result)
|
68
|
-
expect(result.errors?).to
|
68
|
+
expect(result.errors?).to be_truthy
|
69
69
|
expect(result.errors.values).to include('Missing required input(s): `field2, field3` for `output_column`')
|
70
|
-
expect(result.data.empty?).to
|
70
|
+
expect(result.data.empty?).to be_truthy
|
71
71
|
end
|
72
72
|
it 'returns an error for required complex mappings when the mapping block raises an exception' do
|
73
73
|
required_complex_mapping.process_input(invalid_complex_input, result)
|
74
|
-
expect(result.errors?).to
|
74
|
+
expect(result.errors?).to be_truthy
|
75
75
|
expect(result.errors.values).to include('Field1 MUST BE 4')
|
76
|
-
expect(result.data.empty?).to
|
76
|
+
expect(result.data.empty?).to be_truthy
|
77
77
|
end
|
78
78
|
end
|
79
79
|
context 'optional mappings' do
|
80
80
|
it 'maps optional simple mappings when input is valid' do
|
81
81
|
optional_simple_mapping.process_input(valid_input, result)
|
82
|
-
expect(result.errors?).to
|
82
|
+
expect(result.errors?).to be_falsey
|
83
83
|
expect(result.data['output_column']).to eql(4)
|
84
84
|
end
|
85
85
|
it 'maps optional complex mappings when input is valid' do
|
86
86
|
optional_complex_mapping.process_input(valid_input, result)
|
87
|
-
expect(result.errors?).to
|
87
|
+
expect(result.errors?).to be_falsey
|
88
88
|
expect(result.data['output_column']).to eql(15)
|
89
89
|
end
|
90
90
|
it 'does not return an error for optional simple mappings when the input key is missing' do
|
91
91
|
optional_simple_mapping.process_input({}, result)
|
92
|
-
expect(result.errors?).to
|
93
|
-
expect(result.data.empty?).to
|
92
|
+
expect(result.errors?).to be_falsey
|
93
|
+
expect(result.data.empty?).to be_truthy
|
94
94
|
end
|
95
95
|
it 'does not return an error for optional simple mappings when the input data is blank' do
|
96
96
|
optional_simple_mapping.process_input({'field1' => nil}, result)
|
97
|
-
expect(result.errors?).to
|
97
|
+
expect(result.errors?).to be_falsey
|
98
98
|
expect(result.data['output_column']).to be_nil
|
99
99
|
end
|
100
100
|
it 'does not return an error for optional complex mappings when an input key is missing' do
|
101
101
|
optional_complex_mapping.process_input({'field1' => 4}, result)
|
102
|
-
expect(result.errors?).to
|
103
|
-
expect(result.data.empty?).to
|
102
|
+
expect(result.errors?).to be_falsey
|
103
|
+
expect(result.data.empty?).to be_truthy
|
104
104
|
end
|
105
105
|
it 'returns an error for optional complex mappings when the mapping block raises an exception' do
|
106
106
|
optional_complex_mapping.process_input(invalid_complex_input, result)
|
107
|
-
expect(result.errors?).to
|
107
|
+
expect(result.errors?).to be_truthy
|
108
108
|
expect(result.errors.values).to include('Field1 MUST BE 4')
|
109
|
-
expect(result.data.empty?).to
|
109
|
+
expect(result.data.empty?).to be_truthy
|
110
110
|
end
|
111
111
|
end
|
112
112
|
it 'maps data when the result of the mapping is a false value' do
|
113
113
|
#required_simple_mapping.stub(:apply_mapping).and_return(false)
|
114
114
|
required_simple_mapping.process_input({'field1' => false}, result)
|
115
|
-
expect(result.errors?).to
|
115
|
+
expect(result.errors?).to be_falsey
|
116
116
|
expect(result.data['output_column']).to eql(false)
|
117
117
|
end
|
118
118
|
it 'should not rescue Exceptions that do not inherit from standard error' do
|
@@ -21,7 +21,7 @@ describe Topographer::Importer::Mapper::MapperBuilder do
|
|
21
21
|
builder.required_mapping('input_column1', 'output_field1')
|
22
22
|
expect{
|
23
23
|
builder.required_mapping('input_column2', 'output_field1')
|
24
|
-
}.to raise_error
|
24
|
+
}.to raise_error Topographer::InvalidMappingError
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
@@ -42,7 +42,7 @@ describe Topographer::Importer::Mapper::MapperBuilder do
|
|
42
42
|
builder.optional_mapping('input_column1', 'output_field1')
|
43
43
|
expect{
|
44
44
|
builder.optional_mapping('input_column2', 'output_field1')
|
45
|
-
}.to raise_error
|
45
|
+
}.to raise_error Topographer::InvalidMappingError
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
@@ -57,7 +57,7 @@ describe Topographer::Importer::Mapper::MapperBuilder do
|
|
57
57
|
it 'should raise an error if there is no behavior block provided' do
|
58
58
|
expect {
|
59
59
|
builder.validation_field('validation_1', 'input_column1')
|
60
|
-
}.to raise_error
|
60
|
+
}.to raise_error Topographer::InvalidMappingError
|
61
61
|
end
|
62
62
|
it 'should raise an error if a validation mapping already exists with a given name' do
|
63
63
|
builder.validation_field('validation_1', 'input_column1') do
|
@@ -67,7 +67,7 @@ describe Topographer::Importer::Mapper::MapperBuilder do
|
|
67
67
|
builder.validation_field('validation_1', 'input_column1') do
|
68
68
|
return true
|
69
69
|
end
|
70
|
-
}.to raise_error
|
70
|
+
}.to raise_error Topographer::InvalidMappingError
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
@@ -82,7 +82,7 @@ describe Topographer::Importer::Mapper::MapperBuilder do
|
|
82
82
|
it 'should raise an error if there is no behavior block provided' do
|
83
83
|
expect {
|
84
84
|
builder.default_value('output_field1')
|
85
|
-
}.to raise_error
|
85
|
+
}.to raise_error Topographer::InvalidMappingError
|
86
86
|
end
|
87
87
|
it 'should raise an error if a default value mapping already exists for a column' do
|
88
88
|
builder.default_value('output_field1') do
|
@@ -92,7 +92,7 @@ describe Topographer::Importer::Mapper::MapperBuilder do
|
|
92
92
|
builder.default_value('output_field1') do
|
93
93
|
return true
|
94
94
|
end
|
95
|
-
}.to raise_error
|
95
|
+
}.to raise_error Topographer::InvalidMappingError
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
@@ -107,7 +107,7 @@ describe Topographer::Importer::Mapper::MapperBuilder do
|
|
107
107
|
expect {
|
108
108
|
|
109
109
|
builder.key_field('output_field1')
|
110
|
-
}.to raise_error
|
110
|
+
}.to raise_error Topographer::InvalidMappingError
|
111
111
|
end
|
112
112
|
end
|
113
113
|
|
@@ -122,10 +122,10 @@ describe Topographer::Importer::Mapper::MapperBuilder do
|
|
122
122
|
builder.required_mapping('column2', 'field1')
|
123
123
|
expect {
|
124
124
|
builder.ignored_column('column1')
|
125
|
-
}.to raise_error
|
125
|
+
}.to raise_error Topographer::InvalidMappingError
|
126
126
|
expect {
|
127
127
|
builder.ignored_column('column2')
|
128
|
-
}.to raise_error
|
128
|
+
}.to raise_error Topographer::InvalidMappingError
|
129
129
|
end
|
130
130
|
end
|
131
131
|
end
|
@@ -35,7 +35,7 @@ describe Topographer::Importer::Mapper::MappingValidator do
|
|
35
35
|
it 'should raise an error if a name is in the validation list' do
|
36
36
|
expect {
|
37
37
|
validator.validate_unique_validation_name('Field1')
|
38
|
-
}.to raise_error
|
38
|
+
}.to raise_error Topographer::InvalidMappingError
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
@@ -48,7 +48,7 @@ describe Topographer::Importer::Mapper::MappingValidator do
|
|
48
48
|
it 'should raise an error if a field is already an output field' do
|
49
49
|
expect {
|
50
50
|
validator.validate_unique_output_mapping('output_field2')
|
51
|
-
}.to raise_error
|
51
|
+
}.to raise_error Topographer::InvalidMappingError
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
@@ -66,15 +66,15 @@ describe Topographer::Importer::Mapper::MappingValidator do
|
|
66
66
|
it 'should raise an error if a field is already ignored' do
|
67
67
|
expect {
|
68
68
|
validator.validate_unique_column_mapping_type('ignored_column1')
|
69
|
-
}.to raise_error
|
69
|
+
}.to raise_error Topographer::InvalidMappingError
|
70
70
|
end
|
71
71
|
it 'should raise an error when validating an ignored column that has already been mapped' do
|
72
72
|
expect {
|
73
73
|
validator.validate_unique_column_mapping_type('input_column1', ignored: true)
|
74
|
-
}.to raise_error
|
74
|
+
}.to raise_error Topographer::InvalidMappingError
|
75
75
|
expect {
|
76
76
|
validator.validate_unique_column_mapping_type('ignored_column1', ignored: true)
|
77
|
-
}.to raise_error
|
77
|
+
}.to raise_error Topographer::InvalidMappingError
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
@@ -87,30 +87,30 @@ describe Topographer::Importer::Mapper::MappingValidator do
|
|
87
87
|
it 'should raise an error if a new mapping does not have a unique output field' do
|
88
88
|
expect {
|
89
89
|
validator.validate_unique_mapping('input_column2', 'output_field2')
|
90
|
-
}.to raise_error
|
90
|
+
}.to raise_error Topographer::InvalidMappingError
|
91
91
|
end
|
92
92
|
it 'should raise an error if a new mapping includes an already ignored column' do
|
93
93
|
expect {
|
94
94
|
validator.validate_unique_mapping('ignored_column2', 'output_field2')
|
95
|
-
}.to raise_error
|
95
|
+
}.to raise_error Topographer::InvalidMappingError
|
96
96
|
end
|
97
97
|
end
|
98
98
|
it 'should raise an error if a new mapping includes many output fields' do
|
99
99
|
expect {
|
100
100
|
validator.validate_unique_mapping('ignored_column2', %w(output_field2 output_field3))
|
101
|
-
}.to raise_error
|
101
|
+
}.to raise_error Topographer::InvalidMappingError
|
102
102
|
end
|
103
103
|
|
104
104
|
describe '#validate_key_field' do
|
105
105
|
it 'should raise an error if a new key field includes multiple fields' do
|
106
106
|
expect {
|
107
107
|
validator.validate_key_field(%w(output_field2 output_field3))
|
108
|
-
}.to raise_error
|
108
|
+
}.to raise_error Topographer::InvalidMappingError
|
109
109
|
end
|
110
110
|
it 'should raise an error if a key field is duplicated' do
|
111
111
|
expect {
|
112
112
|
validator.validate_key_field('key_field1')
|
113
|
-
}.to raise_error
|
113
|
+
}.to raise_error Topographer::InvalidMappingError
|
114
114
|
end
|
115
115
|
it 'should not raise an error if a key field is not already mapped' do
|
116
116
|
expect {
|