Browse Source

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

Thorsten Eckel 8 years ago
parent
commit
68bab40c13
2 changed files with 23 additions and 1 deletions
  1. 4 1
      lib/import/otrs/article_customer.rb
  2. 19 0
      spec/lib/import/otrs/article_customer_sepc.rb

+ 4 - 1
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

+ 19 - 0
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