Browse Source

Follow up 58ec7e9 - Fixes: #5022 - Zammad should not write to the var/ folder

Mantas 11 months ago
parent
commit
b1d1f481ed
2 changed files with 17 additions and 1 deletions
  1. 1 1
      app/models/channel/email_parser.rb
  2. 16 0
      spec/models/channel/email_parser_spec.rb

+ 1 - 1
app/models/channel/email_parser.rb

@@ -120,7 +120,7 @@ returns
   def process(channel, msg, exception = true)
     process_with_timeout(channel, msg)
   rescue => e
-    failed_email = ::FailedEmail.create(data: msg, parsing_error: e)
+    failed_email = ::FailedEmail.create!(data: msg, parsing_error: e)
 
     message = <<~MESSAGE.chomp
       Can't process email. Run the following command to get the message for issue report at https://github.com/zammad/zammad/issues:

+ 16 - 0
spec/models/channel/email_parser_spec.rb

@@ -206,6 +206,22 @@ RSpec.describe Channel::EmailParser, type: :model do
           end
         end
       end
+
+      describe 'handle database failures' do
+        subject(:instance) { described_class.new }
+
+        let(:mail_data)    { attributes_for(:failed_email)[:data] }
+
+        before do
+          allow(instance).to receive(:process_with_timeout).and_raise('error')
+          allow_any_instance_of(FailedEmail).to receive(:valid?).and_return(false)
+        end
+
+        it 'raises error even if exception is false' do
+          expect { instance.process({}, mail_data, false) }
+            .to raise_error(ActiveRecord::ActiveRecordError)
+        end
+      end
     end
 
     describe 'creating new tickets' do