diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2018-09-18 17:28:35 -0700 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2018-09-18 17:28:35 -0700 |
commit | 26bfd1c59cf2dfa36fc02b87831449a8259c780e (patch) | |
tree | 672a7cb5a94b9353820dd0e43e74c2f069cf1f1b | |
parent | d1329efd815ea0be1d666b0c2b4664349a77e1a0 (diff) | |
download | rails-26bfd1c59cf2dfa36fc02b87831449a8259c780e.tar.gz rails-26bfd1c59cf2dfa36fc02b87831449a8259c780e.tar.bz2 rails-26bfd1c59cf2dfa36fc02b87831449a8259c780e.zip |
Only deliver pending emails to the mailroom
Makes it easier to test without triggering this behavior.
-rw-r--r-- | app/models/action_mailroom/inbound_email.rb | 2 | ||||
-rw-r--r-- | lib/action_mailroom/test_helper.rb | 4 | ||||
-rw-r--r-- | test/unit/inbound_email/deliver_to_mailroom.rb | 11 |
3 files changed, 14 insertions, 3 deletions
diff --git a/app/models/action_mailroom/inbound_email.rb b/app/models/action_mailroom/inbound_email.rb index bb3b0daff7..92f80f26e3 100644 --- a/app/models/action_mailroom/inbound_email.rb +++ b/app/models/action_mailroom/inbound_email.rb @@ -7,7 +7,7 @@ class ActionMailroom::InboundEmail < ActiveRecord::Base enum status: %i[ pending processing delivered failed bounced ] - # after_create_commit :deliver_to_mailroom_later + after_create_commit :deliver_to_mailroom_later, if: ->(r) { r.pending? } def mail diff --git a/lib/action_mailroom/test_helper.rb b/lib/action_mailroom/test_helper.rb index af9e3ad559..94321ecad3 100644 --- a/lib/action_mailroom/test_helper.rb +++ b/lib/action_mailroom/test_helper.rb @@ -2,8 +2,8 @@ module ActionMailroom module TestHelper # Create an InboundEmail record using an eml fixture in the format of message/rfc822 # referenced with +fixture_name+ located in +test/fixtures/files/fixture_name+. - def create_inbound_email(fixture_name) - ActionMailroom::InboundEmail.create!.tap do |inbound_email| + def create_inbound_email(fixture_name, status: :processing) + ActionMailroom::InboundEmail.create!(status: status).tap do |inbound_email| inbound_email.raw_email.attach \ ActiveStorage::Blob.create_after_upload! \ io: file_fixture(fixture_name).open, filename: fixture_name, content_type: 'message/rfc822' diff --git a/test/unit/inbound_email/deliver_to_mailroom.rb b/test/unit/inbound_email/deliver_to_mailroom.rb new file mode 100644 index 0000000000..c583f4a0a4 --- /dev/null +++ b/test/unit/inbound_email/deliver_to_mailroom.rb @@ -0,0 +1,11 @@ +require_relative '../../test_helper' + +class ActionMailroom::InboundEmail::DeliverToMailroomTest < ActiveSupport::TestCase + include ActiveJob::TestHelper + + test "pending emails are delivered to the mailroom" do + assert_enqueued_jobs 1, only: ActionMailroom::DeliverInboundEmailToMailroomJob do + create_inbound_email("welcome.eml", status: :pending) + end + end +end |