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 ...@@ -38,7 +38,7 @@ module Issuable
def with_csv_lines def with_csv_lines
csv_data = @csv_io.open(&:read).force_encoding(Encoding::UTF_8) 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 = { csv_parsing_params = {
col_sep: detect_col_sep(csv_data.lines.first), col_sep: detect_col_sep(csv_data.lines.first),
...@@ -49,9 +49,9 @@ module Issuable ...@@ -49,9 +49,9 @@ module Issuable
CSV.new(csv_data, csv_parsing_params).each.with_index(2) CSV.new(csv_data, csv_parsing_params).each.with_index(2)
end end
def verify_headers!(data) def validate_headers_presence!(headers)
headers = data.lines.first.downcase headers.downcase! if headers
return if headers.include?('title') && headers.include?('description') return if headers && headers.include?('title') && headers.include?('description')
raise CSV::MalformedCSVError raise CSV::MalformedCSVError
end end
......
---
title: Fix error in Issuable::ImportCsv::BaseService when CSV file is empty
merge_request: 47918
author:
type: fixed
...@@ -26,29 +26,33 @@ RSpec.shared_examples 'issuable import csv service' do |issuable_type| ...@@ -26,29 +26,33 @@ RSpec.shared_examples 'issuable import csv service' do |issuable_type|
end end
end end
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)
end
it_behaves_like 'importer with email notification'
it_behaves_like 'an issuable importer'
end
describe '#execute' do describe '#execute' do
context 'invalid file' do context 'invalid file extension' do
let(:file) { fixture_file_upload('spec/fixtures/banana_sample.gif') } let(:file) { fixture_file_upload('spec/fixtures/banana_sample.gif') }
it 'returns invalid file error' do it_behaves_like 'invalid file'
expect(subject[:success]).to eq(0) end
expect(subject[:parse_error]).to eq(true)
end
it_behaves_like 'importer with email notification' context 'empty file' do
it_behaves_like 'an issuable importer' let(:file) { fixture_file_upload('spec/fixtures/csv_empty.csv') }
it_behaves_like 'invalid file'
end end
context 'file without headers' do context 'file without headers' do
let(:file) { fixture_file_upload('spec/fixtures/csv_no_headers.csv') } let(:file) { fixture_file_upload('spec/fixtures/csv_no_headers.csv') }
it 'returns invalid file error' do it_behaves_like 'invalid file'
expect(subject[:success]).to eq(0)
expect(subject[:parse_error]).to eq(true)
end
it_behaves_like 'importer with email notification'
it_behaves_like 'an issuable importer'
end end
context 'with a file generated by Gitlab CSV export' do 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