Fixed bug: OTRS import throws an exception if no Article From is present.

This commit is contained in:
Thorsten Eckel 2017-03-28 11:28:07 +02:00
parent a306078ebb
commit 68bab40c13
2 changed files with 23 additions and 1 deletions

View file

@ -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

View file

@ -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