aboutsummaryrefslogblamecommitdiffstats
path: root/lib/action_mailbox/test_helper.rb
blob: 23b2bb02caa601f0ec615b0e86c5aa6b504f438f (plain) (tree)
1
2
3
4
5
6
7
8
9

              
                    


                                                                                        
                                                                            
                                                                          
       
 
                                                                           
                                                                      

       

                                                                                       
       
 



                                                           


                                                           

     
require "mail"

module ActionMailbox
  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_from_fixture(fixture_name, status: :processing)
      create_inbound_email file_fixture(fixture_name).read, status: status
    end

    def create_inbound_email_from_mail(status: :processing, **mail_options)
      create_inbound_email Mail.new(mail_options).to_s, status: status
    end

    def create_inbound_email(source, status: :processing)
      ActionMailbox::InboundEmail.create_and_extract_message_id! source, status: status
    end

    def receive_inbound_email_from_fixture(*args)
      create_inbound_email_from_fixture(*args).tap(&:route)
    end

    def receive_inbound_email_from_mail(**kwargs)
      create_inbound_email_from_mail(**kwargs).tap(&:route)
    end
  end
end