Sha256: ed5e215d850a224726c3acbe071e34ec4180bd41455a1d927649b37af3699269

Contents?: true

Size: 1.96 KB

Versions: 18

Compression:

Stored size: 1.96 KB

Contents

require File.join(File.dirname(__FILE__), "test_helper")

class Astrotrain::LoggedMailTest < Astrotrain::TestCase
  describe "being created from Message" do
    before :all do
      Astrotrain::Mapping.all.destroy!
      @mapping = Astrotrain::Mapping.create!(:email_user => '*')
      @raw     = mail(:custom)
      @message = Astrotrain::Message.parse(@raw)
      @logged  = Astrotrain::LoggedMail.from(@message, 'foo/bar') do |l|
        l.recipient = @message.recipients(%w(delivered_to)).first
        l.mapping   = @mapping
      end
    end

    it "sets recipient" do
      assert_equal @message.recipients(%w(delivered_to)).first, @logged.recipient
    end

    it "sets mail_file" do
      assert_equal 'foo/bar', @logged.mail_file
    end

    it "sets sender" do
      assert_equal 'user@example.com', @logged.sender
    end

    it "sets subject" do
      assert_equal @message.subject, @logged.subject
    end

    it "sets mapping" do
      assert_equal @mapping, @logged.mapping
    end
  end

  describe "attempted creation with badly encoded message" do
    before :all do
      Astrotrain::Mapping.all.destroy!
      @mapping = Astrotrain::Mapping.create!(:email_user => '*')
      @raw     = mail(:custom)
      @subject = "=?gb2312?B?usO80rXnubrO78341b68urjEsOajrLfJwPvG1tfu0MKxqLzbo6jUsbmkvNuj?= =?gb2312?B?qQ==?="
      @raw.sub! /Subject\: Fwd\: blah blah/, "Subject: #{@subject}"
      @message = Astrotrain::Message.parse(@raw)
      @logged  = Astrotrain::LoggedMail.from(@message) do |l|
        l.recipient = @message.recipients(%w(delivered_to)).first
        l.mapping   = @mapping
      end
    end

    it "sets recipient" do
      assert_equal @message.recipients(%w(delivered_to)).first, @logged.recipient
    end

    it "sets subject" do
      assert_equal @subject, @logged.subject
    end

    it "sets sender" do
      assert_equal 'user@example.com', @logged.sender
    end

    it "sets mapping" do
      assert_equal @mapping, @logged.mapping
    end
  end
end

Version data entries

18 entries across 18 versions & 2 rubygems

Version Path
entp-astrotrain-0.3.0 test/logged_mail_test.rb
entp-astrotrain-0.3.1 test/logged_mail_test.rb
entp-astrotrain-0.4.0 test/logged_mail_test.rb
entp-astrotrain-0.4.1 test/logged_mail_test.rb
entp-astrotrain-0.4.2 test/logged_mail_test.rb
entp-astrotrain-0.4.3 test/logged_mail_test.rb
astrotrain-0.5.4 test/logged_mail_test.rb
astrotrain-0.5.3 test/logged_mail_test.rb
astrotrain-0.5.2 test/logged_mail_test.rb
astrotrain-0.5.1 test/logged_mail_test.rb
astrotrain-0.5.0 test/logged_mail_test.rb
astrotrain-0.4.5 test/logged_mail_test.rb
astrotrain-0.4.4 test/logged_mail_test.rb
astrotrain-0.4.3 test/logged_mail_test.rb
astrotrain-0.4.2 test/logged_mail_test.rb
astrotrain-0.4.1 test/logged_mail_test.rb
astrotrain-0.4.0 test/logged_mail_test.rb
astrotrain-0.3.1 test/logged_mail_test.rb