Commit 8468e07d authored by Mark Chao's avatar Mark Chao

Merge branch '246857-fix-issuable-import-csv-service' into 'master'

Fix NoMethodError in issuable import CSV base service

See merge request gitlab-org/gitlab!47918
parents 0be059c2 cec29428
......@@ -38,7 +38,7 @@ module Issuable
def with_csv_lines
csv_data = @csv_io.open(&:read).force_encoding(Encoding::UTF_8)
verify_headers!(csv_data)
validate_headers_presence!(csv_data.lines.first)
csv_parsing_params = {
col_sep: detect_col_sep(csv_data.lines.first),
......@@ -49,9 +49,9 @@ module Issuable
CSV.new(csv_data, csv_parsing_params).each.with_index(2)
end
def verify_headers!(data)
headers = data.lines.first.downcase
return if headers.include?('title') && headers.include?('description')
def validate_headers_presence!(headers)
headers.downcase! if headers
return if headers && headers.include?('title') && headers.include?('description')
raise CSV::MalformedCSVError
end
......
---
title: Fix error in Issuable::ImportCsv::BaseService when CSV file is empty
merge_request: 47918
author:
type: fixed
......@@ -26,10 +26,7 @@ RSpec.shared_examples 'issuable import csv service' do |issuable_type|
end
end
describe '#execute' do
context 'invalid file' do
let(:file) { fixture_file_upload('spec/fixtures/banana_sample.gif') }
shared_examples_for 'invalid file' do
it 'returns invalid file error' do
expect(subject[:success]).to eq(0)
expect(subject[:parse_error]).to eq(true)
......@@ -39,16 +36,23 @@ RSpec.shared_examples 'issuable import csv service' do |issuable_type|
it_behaves_like 'an issuable importer'
end
context 'file without headers' do
let(:file) { fixture_file_upload('spec/fixtures/csv_no_headers.csv') }
describe '#execute' do
context 'invalid file extension' do
let(:file) { fixture_file_upload('spec/fixtures/banana_sample.gif') }
it 'returns invalid file error' do
expect(subject[:success]).to eq(0)
expect(subject[:parse_error]).to eq(true)
it_behaves_like 'invalid file'
end
it_behaves_like 'importer with email notification'
it_behaves_like 'an issuable importer'
context 'empty file' do
let(:file) { fixture_file_upload('spec/fixtures/csv_empty.csv') }
it_behaves_like 'invalid file'
end
context 'file without headers' do
let(:file) { fixture_file_upload('spec/fixtures/csv_no_headers.csv') }
it_behaves_like 'invalid file'
end
context 'with a file generated by Gitlab CSV export' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment