From 68bab40c13b5a152808a112560563de9ecfb44d3 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Tue, 28 Mar 2017 11:28:07 +0200 Subject: [PATCH] Fixed bug: OTRS import throws an exception if no Article From is present. --- lib/import/otrs/article_customer.rb | 5 ++++- spec/lib/import/otrs/article_customer_sepc.rb | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/import/otrs/article_customer.rb b/lib/import/otrs/article_customer.rb index 22df4cafa..1ee83c56a 100644 --- a/lib/import/otrs/article_customer.rb +++ b/lib/import/otrs/article_customer.rb @@ -13,6 +13,7 @@ module Import def find(article) email = local_email(article['From']) + return if !email user = ::User.find_by(email: email) user ||= ::User.find_by(login: email) user @@ -20,7 +21,9 @@ module Import def local_email(from) # TODO: should get unified with User#check_email - extract_email(from).downcase + email = extract_email(from) + return if !email + email.downcase end private diff --git a/spec/lib/import/otrs/article_customer_sepc.rb b/spec/lib/import/otrs/article_customer_sepc.rb index 2bf091efc..0645271b0 100644 --- a/spec/lib/import/otrs/article_customer_sepc.rb +++ b/spec/lib/import/otrs/article_customer_sepc.rb @@ -47,4 +47,23 @@ RSpec.describe Import::OTRS::ArticleCustomer do expect(User.last.email).to eq('user@example.com') expect(User.last.login).to eq('user@example.com') end + + context '.find' do + + it 'returns nil if no email could be found' do + expect(described_class.find({})).to be nil + end + end + + context '.local_email' do + + it 'returns nil if no email could be found' do + expect(described_class.local_email(nil)).to be nil + end + + it 'returns the parameter if no email could be found' do + not_an_email = 'thisisnotanemail' + expect(described_class.local_email(not_an_email)).to eq(not_an_email) + end + end end