create_failed_emails_spec.rb 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe CreateFailedEmails, db_strategy: :reset, type: :db_migration do
  4. before do
  5. ActiveRecord::Migration[7.0].drop_table :failed_emails
  6. # make sure folder does not exist
  7. FileUtils.rm_rf(dir)
  8. end
  9. describe '#up', system_init_done: true do
  10. let(:dir) { described_class::OLD_FAILED_EMAIL_DIRECTORY }
  11. context 'when unprocessable email files exist' do
  12. let(:content) { attributes_for(:failed_email)[:data] }
  13. before do
  14. FileUtils.mkdir_p dir
  15. File.binwrite dir.join('test.eml'), content
  16. end
  17. it 'imports unprocessable email form files' do
  18. migrate
  19. expect(FailedEmail.first).to have_attributes(data: content)
  20. end
  21. it 'removes unprocessable email directory' do
  22. expect { migrate }
  23. .to change { Dir.exist? dir }
  24. .to false
  25. end
  26. end
  27. context 'when unprocessable emails directory does not exist' do
  28. it 'does not crash' do
  29. expect { migrate }.not_to raise_error
  30. end
  31. end
  32. end
  33. end