<commit_before>require File.dirname(__FILE__) + '/../test_helper'

class BuildMailerTest < Test::Unit::TestCase
  FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures'
  CHARSET = "utf-8"

  include ActionMailer::Quoting

  def setup
    ActionMailer::Base.delivery_method = :test
    ActionMailer::Base.perform_deliveries = true
    ActionMailer::Base.deliveries = []

    @expected = TMail::Mail.new
    @expected.set_content_type "text", "plain", { "charset" => CHARSET }
    @expected.mime_version = '1.0'
  end

  def test_test
    @expected.subject = 'Test CI E-mail'
    @expected.body    = read_fixture('test')
    @expected.from    = "<EMAIL>"
    @expected.date    = Time.now
    @expected.to = "Joe"

    assert_equal @expected.encoded, BuildMailer.create_test("Joe", @expected.date).encoded
  end

  private
    def read_fixture(action)
      IO.readlines("#{FIXTURES_PATH}/build_mailer/#{action}")
    end

    def encode(subject)
      quoted_printable(subject, CHARSET)<commit_msg>Fixed an accidental correctness bug related to Time<commit_after>require File.dirname(__FILE__) + '/../test_helper'

class BuildMailerTest < Test::Unit::TestCase
  FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures'
  CHARSET = "utf-8"

  include ActionMailer::Quoting

  def setup
    ActionMailer::Base.delivery_method = :test
    ActionMailer::Base.perform_deliveries = true
    ActionMailer::Base.deliveries = []

    @expected = TMail::Mail.new
    @expected.set_content_type "text", "plain", { "charset" => CHARSET }
    @expected.mime_version = '1.0'
  end

  def test_test
    Time.stubs(:now).returns(Time.at(100000))
    @expected.subject = 'Test CI E-mail'
    @expected.body    = read_fixture('test')
    @expected.from    = "<EMAIL>"
    @expected.date    = Time.now
    @expected.to = "Joe"

    assert_equal @expected.encoded, BuildMailer.create_test("Joe", @expected.date).encoded
  end

  private
    def read_fixture(action)
      IO.readlines("#{FIXTURES_PATH}/build_mailer/#{action}")
    end

    def encode(subject)
      quoted_printable(subject, CHARSET)
{'fraction_non_alphanumeric': 0.13557692307692307, 'fraction_numerical': 0.0057692307692307696, 'mean_word_length': 3.7081447963800906, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '4308520', 'n_tokens_mistral': 720, 'n_tokens_neox': 681, 'n_words': 123}