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
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe ImportCsv::BaseService, feature_category: :importers do
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project) }
let_it_be(:csv_io) { double }
subject { described_class.new(user, project, csv_io) }
shared_examples 'abstract method' do |method, args|
it "raises NotImplemented error when #{method} is called" do
if args
expect { subject.send(method, args) }.to raise_error(NotImplementedError)
else
expect { subject.send(method) }.to raise_error(NotImplementedError)
end
end
end
it_behaves_like 'abstract method', :email_results_to_user
it_behaves_like 'abstract method', :attributes_for, "any"
it_behaves_like 'abstract method', :validate_headers_presence!, "any"
it_behaves_like 'abstract method', :create_object_class
describe '#detect_col_sep' do
context 'when header contains invalid separators' do
it 'raises error' do
header = 'Name&email'
expect { subject.send(:detect_col_sep, header) }.to raise_error(CSV::MalformedCSVError)
end
end
context 'when header is valid' do
shared_examples 'header with valid separators' do
let(:header) { "Name#{separator}email" }
it 'returns separator value' do
expect(subject.send(:detect_col_sep, header)).to eq(separator)
end
end
context 'with ; as separator' do
let(:separator) { ';' }
it_behaves_like 'header with valid separators'
end
context 'with \t as separator' do
let(:separator) { "\t" }
it_behaves_like 'header with valid separators'
end
context 'with , as separator' do
let(:separator) { ',' }
it_behaves_like 'header with valid separators'
end
end
end
end
|