Commit c67f2ec8 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Prevent duplicate issues when importing from CSV

We send the notification email in a separate job so that we do not
insert the issues again when the job is retried because email sending
failed
parent cdacec1f
......@@ -46,7 +46,7 @@ module Issues
end
def email_results_to_user
Notify.import_issues_csv_email(@user.id, @project.id, @results).deliver_now
Notify.import_issues_csv_email(@user.id, @project.id, @results).deliver_later
end
def detect_col_sep(header)
......
---
title: Prevent duplicate issues when importing from CSV
merge_request: 33626
author:
type: fixed
......@@ -18,9 +18,7 @@ describe Issues::ImportCsvService do
let(:file) { fixture_file_upload('spec/fixtures/banana_sample.gif') }
it 'returns invalid file error' do
expect_next_instance_of(Notify) do |instance|
expect(instance).to receive(:import_issues_csv_email)
end
expect(Notify).to receive_message_chain(:import_issues_csv_email, :deliver_later)
expect(subject[:success]).to eq(0)
expect(subject[:parse_error]).to eq(true)
......@@ -31,9 +29,7 @@ describe Issues::ImportCsvService do
let(:file) { fixture_file_upload('spec/fixtures/csv_gitlab_export.csv') }
it 'imports the CSV without errors' do
expect_next_instance_of(Notify) do |instance|
expect(instance).to receive(:import_issues_csv_email)
end
expect(Notify).to receive_message_chain(:import_issues_csv_email, :deliver_later)
expect(subject[:success]).to eq(4)
expect(subject[:error_lines]).to eq([])
......@@ -54,9 +50,7 @@ describe Issues::ImportCsvService do
let(:file) { fixture_file_upload('spec/fixtures/csv_comma.csv') }
it 'imports CSV without errors' do
expect_next_instance_of(Notify) do |instance|
expect(instance).to receive(:import_issues_csv_email)
end
expect(Notify).to receive_message_chain(:import_issues_csv_email, :deliver_later)
expect(subject[:success]).to eq(3)
expect(subject[:error_lines]).to eq([])
......@@ -77,9 +71,7 @@ describe Issues::ImportCsvService do
let(:file) { fixture_file_upload('spec/fixtures/csv_tab.csv') }
it 'imports CSV with some error rows' do
expect_next_instance_of(Notify) do |instance|
expect(instance).to receive(:import_issues_csv_email)
end
expect(Notify).to receive_message_chain(:import_issues_csv_email, :deliver_later)
expect(subject[:success]).to eq(2)
expect(subject[:error_lines]).to eq([3])
......@@ -100,9 +92,7 @@ describe Issues::ImportCsvService do
let(:file) { fixture_file_upload('spec/fixtures/csv_semicolon.csv') }
it 'imports CSV with a blank row' do
expect_next_instance_of(Notify) do |instance|
expect(instance).to receive(:import_issues_csv_email)
end
expect(Notify).to receive_message_chain(:import_issues_csv_email, :deliver_later)
expect(subject[:success]).to eq(3)
expect(subject[:error_lines]).to eq([4])
......
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