<commit_before>require_relative "test_helper"

class UserMailer < ActionMailer::Base
  def welcome
    mail to: "<EMAIL>", subject: "Hello", body: "World"
  end
end

class MailerTest < Minitest::Test
  def test_basic
    message = UserMailer.welcome
    message.to # trigger creation

    ahoy_message = Ahoy::Message.first
    assert_equal 1, Ahoy::Message.count
    assert_equal "<EMAIL>", ahoy_message.to
    assert_equal "UserMailer#welcome", ahoy_message.mailer
    assert_equal "Hello", ahoy_message.subject
    assert_equal "user_mailer", ahoy_message.utm_source
    assert_equal "email", ahoy_message.utm_medium
    assert_equal "welcome", ahoy_message.utm_campaign
  end
end<commit_msg>Added test for prevent delivery<commit_after>require_relative "test_helper"

class UserMailer < ActionMailer::Base
  after_action :prevent_delivery_to_guests, only: [:welcome2]

  def welcome
    mail to: "<EMAIL>", subject: "Hello", body: "World"
  end

  def welcome2
    mail to: "<EMAIL>", subject: "Hello", body: "World"
  end

  private

  def prevent_delivery_to_guests
    mail.perform_deliveries = false
  end
end

class MailerTest < Minitest::Test
  def setup
    Ahoy::Message.delete_all
  end

  def test_basic
    assert_message :welcome
  end

  def test_prevent_delivery
    assert_message :welcome2
  end

  def assert_message(method)
    message = UserMailer.send(method)
    message.to # trigger creation
    ahoy_message = Ahoy::Message.first
    assert_equal 1, Ahoy::Message.count
    assert_equal "<EMAIL>", ahoy_message.to
    assert_equal "UserMailer##{method}", ahoy_message.mailer
    assert_equal "Hello", ahoy_message.subject
    assert_equal "user_mailer", ahoy_message.utm_source
    assert_equal "email", ahoy_message.utm_medium
    assert_equal method.to_s, ahoy_message.utm_campaign
  end
end
{'fraction_non_alphanumeric': 0.08681318681318681, 'fraction_numerical': 0.0027472527472527475, 'mean_word_length': 4.468468468468468, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 8, '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': '468947', 'n_tokens_mistral': 613, 'n_tokens_neox': 600, 'n_words': 139}