<commit_before>require 'test_helper'

describe Lotus::Mailer do
  describe '.deliver' do
    before do
      Lotus::Mailer.deliveries.clear
    end

    it 'can deliver with specified charset' do
      CharsetMailer.deliver(charset: charset = 'iso-2022-jp')

      mail = Lotus::Mailer.deliveries.first
      mail.charset.must_equal             charset
      mail.parts.first.charset.must_equal charset
    end

    it "raises error when 'from' isn't specified" do
      -> { MissingFromMailer.deliver }.must_raise Lotus::Mailer::MissingDeliveryDataError
    end

    it "raises error when 'to' isn't specified" do
      -> { MissingToMailer.deliver }.must_raise Lotus::Mailer::MissingDeliveryDataError
    end

    describe 'test delivery with hardcoded values' do
      before do
        WelcomeMailer.deliver
        @mail = Lotus::Mailer.deliveries.first
      end

      after do
        Lotus::Mailer.deliveries.clear
      end

      it 'delivers the mail' do
        Lotus::Mailer.deliveries.length.must_equal 1
      end

      it 'sends the correct information' do
        @mail.from.must_equal ['<EMAIL>']
        @mail.to.must_equal   ['<EMAIL>', '<EMAIL>']
        @mail.subject.must_equal "Welcome"
      end

      it 'has the correct templates' do
        @mail.html_part.to_s.must_include %(template)
        @mail.text_part.to_s.must_include %(template)
      end

      it 'interprets the prepare statement' do
        attachment = @mail.attachments['invoice.pdf']

        attachment.must_be_kind_of(Mail::Part)

        attachment.must_be :attachment?
        attachment.wont_be :inline?
        attachment.wont_be :multipart?

        attachment.filename.must_equal     'invoice.pdf'
        attachment.content_type.must_equal 'application/pdf; charset=UTF-8; filename=invoice.pdf'
      end
    end

    describe 'test delivery with methods' do
      before do
        @user = User.new('Name', '<EMAIL>')
        MethodMailer.deliver(user: @user)

        @mail = Lotus::Mailer.deliveries.first
      end

      after do
        Lotus::Mailer.deliveries.clear
      end

      it 'delivers the mail' do
        Lotus::Mailer.deliveries.length.must_equal 1
      end

      it 'sends the correct information' do
        @mail.from.must_equal    ["hello-#{ @user.name.downcase }@<EMAIL>"]
        @mail.to.must_equal      [@user.email]
        @mail.subject.must_equal "Hello, #{ @user.name }"
      end
    end

    describe 'multipart' do
      after do
        Lotus::Mailer.deliveries.clear
      end

      it 'delivers all the parts by default' do
        WelcomeMailer.deliver

        mail = Lotus::Mailer.deliveries.first
        body = mail.body.encoded

        body.must_include %(<h1>Hello World!</h1>)
        body.must_include %(This is a txt template)
      end

      it 'can deliver only the text part' do
        WelcomeMailer.deliver(format: :txt)

        mail = Lotus::Mailer.deliveries.first
        body = mail.body.encoded

        body.wont_include %(<h1>Hello World!</h1>)
        body.must_include %(This is a txt template)
      end

      it 'can deliver only the html part' do
        WelcomeMailer.deliver(format: :html)

        mail = Lotus::Mailer.deliveries.first
        body = mail.body.encoded

        body.must_include %(<h1>Hello World!</h1>)
        body.wont_include %(This is a txt template)
      end
    end

    # describe 'custom delivery' do
    #   before do
    #     @options = options = { deliveries: [] }

    #     Lotus::Mailer.reset!
    #     Lotus::Mailer.configure do
    #       delivery_method MandrillDeliveryMethod, options
    #     end.load!

    #     WelcomeMailer.deliver

    #     @mail = options.fetch(:deliveries).first
    #   end

    #   after do
    #     Lotus::Mailer.reset!
    #   end

    #   it 'delivers the mail' do
    #     @options.fetch(:deliveries).length.must_equal 1
    #   end

    #   it 'sends the correct information' do
    #     @mail.from.must_equal ['<EMAIL>']
    #     @mail.to.must_equal ['<EMAIL>']
    #     @mail.subject.must_equal "Welcome"
    #   end

    #   it 'has the correct templates' do
    #     @mail.html_part.to_s.must_include %(template)
    #     @mail.text_part.to_s.must_include %(template)
    #     @mail.attachments['welcome_mailer.csv'].wont_be_nil
    #   end

    #   it 'interprets the prepare statement' do
    #     @mail.attachments['invoice.pdf'].wont_be_nil
    #   end

    #   it 'adds the attachment to the mail object' do
    #     @mail.attachments['render_mailer.html.erb'].wont_be_nil
    #   end
    # end
  end<commit_msg>Added pending test for custom delivery method<commit_after>require 'test_helper'

describe Lotus::Mailer do
  describe '.deliver' do
    before do
      Lotus::Mailer.deliveries.clear
    end

    it 'can deliver with specified charset' do
      CharsetMailer.deliver(charset: charset = 'iso-2022-jp')

      mail = Lotus::Mailer.deliveries.first
      mail.charset.must_equal             charset
      mail.parts.first.charset.must_equal charset
    end

    it "raises error when 'from' isn't specified" do
      -> { MissingFromMailer.deliver }.must_raise Lotus::Mailer::MissingDeliveryDataError
    end

    it "raises error when 'to' isn't specified" do
      -> { MissingToMailer.deliver }.must_raise Lotus::Mailer::MissingDeliveryDataError
    end

    describe 'test delivery with hardcoded values' do
      before do
        WelcomeMailer.deliver
        @mail = Lotus::Mailer.deliveries.first
      end

      after do
        Lotus::Mailer.deliveries.clear
      end

      it 'delivers the mail' do
        Lotus::Mailer.deliveries.length.must_equal 1
      end

      it 'sends the correct information' do
        @mail.from.must_equal ['<EMAIL>']
        @mail.to.must_equal   ['<EMAIL>', '<EMAIL>']
        @mail.subject.must_equal "Welcome"
      end

      it 'has the correct templates' do
        @mail.html_part.to_s.must_include %(template)
        @mail.text_part.to_s.must_include %(template)
      end

      it 'interprets the prepare statement' do
        attachment = @mail.attachments['invoice.pdf']

        attachment.must_be_kind_of(Mail::Part)

        attachment.must_be :attachment?
        attachment.wont_be :inline?
        attachment.wont_be :multipart?

        attachment.filename.must_equal     'invoice.pdf'
        attachment.content_type.must_equal 'application/pdf; charset=UTF-8; filename=invoice.pdf'
      end
    end

    describe 'test delivery with methods' do
      before do
        @user = User.new('Name', '<EMAIL>')
        MethodMailer.deliver(user: @user)

        @mail = Lotus::Mailer.deliveries.first
      end

      after do
        Lotus::Mailer.deliveries.clear
      end

      it 'delivers the mail' do
        Lotus::Mailer.deliveries.length.must_equal 1
      end

      it 'sends the correct information' do
        @mail.from.must_equal    ["hello-#{ @user.name.downcase }@example.<EMAIL>"]
        @mail.to.must_equal      [@user.email]
        @mail.subject.must_equal "Hello, #{ @user.name }"
      end
    end

    describe 'multipart' do
      after do
        Lotus::Mailer.deliveries.clear
      end

      it 'delivers all the parts by default' do
        WelcomeMailer.deliver

        mail = Lotus::Mailer.deliveries.first
        body = mail.body.encoded

        body.must_include %(<h1>Hello World!</h1>)
        body.must_include %(This is a txt template)
      end

      it 'can deliver only the text part' do
        WelcomeMailer.deliver(format: :txt)

        mail = Lotus::Mailer.deliveries.first
        body = mail.body.encoded

        body.wont_include %(<h1>Hello World!</h1>)
        body.must_include %(This is a txt template)
      end

      it 'can deliver only the html part' do
        WelcomeMailer.deliver(format: :html)

        mail = Lotus::Mailer.deliveries.first
        body = mail.body.encoded

        body.must_include %(<h1>Hello World!</h1>)
        body.wont_include %(This is a txt template)
      end
    end

    describe 'custom delivery' do
      before do
        @options = options = { deliveries: [] }

        # Lotus::Mailer.reset!
        # Lotus::Mailer.configure do
        #   delivery_method MandrillDeliveryMethod, options
        # end.load!

        WelcomeMailer.deliver

        @mail = options.fetch(:deliveries).first
      end

      it 'delivers the mail'
      # it 'delivers the mail' do
      #   @options.fetch(:deliveries).length.must_equal 1
      # end

      # it 'sends the correct information' do
      #   @mail.from.must_equal ['<EMAIL>']
      #   @mail.to.must_equal ['<EMAIL>']
      #   @mail.subject.must_equal "Welcome"
      # end

      # it 'has the correct templates' do
      #   @mail.html_part.to_s.must_include %(template)
      #   @mail.text_part.to_s.must_include %(template)
      # end

      # it 'interprets the prepare statement' do
      #   @mail.attachments['invoice.pdf'].wont_be_nil
      # end

      # it 'adds the attachment to the mail object' do
      #   @mail.attachments['render_mailer.html.erb'].wont_be_nil
      # end
    end
  end
{'fraction_non_alphanumeric': 0.10272168568920105, 'fraction_numerical': 0.0030728709394205445, 'mean_word_length': 2.288704438830747, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5178674', 'n_tokens_mistral': 2986, 'n_tokens_neox': 2871, 'n_words': 660}