Sha256: 3e22df09b7b8de060e96d4d1d6e0fe837c808979c01fbe2436806b45e24c0871

Contents?: true

Size: 1.47 KB

Versions: 3

Compression:

Stored size: 1.47 KB

Contents

require_relative "test_helper"

class UserMailer < ActionMailer::Base
  default from: "from@example.com"
  after_action :prevent_delivery_to_guests, only: [:welcome2] if Rails.version >= "4.0.0"

  def welcome
    mail to: "test@example.org", subject: "Hello", body: "World"
  end

  def welcome2
    mail to: "test@example.org", subject: "Hello", body: "World"
  end

  def welcome3
    track message: false
    mail to: "test@example.org", 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
    if Rails.version >= "4.0.0"
      assert_nil Ahoy::Message.first.sent_at
    end
  end

  def test_no_message
    UserMailer.welcome3.to
    assert_equal 0, Ahoy::Message.count
  end

  def assert_message(method)
    message = UserMailer.send(method)
    message.respond_to?(:deliver_now) ? message.deliver_now : message.deliver
    ahoy_message = Ahoy::Message.first
    assert_equal 1, Ahoy::Message.count
    assert_equal "test@example.org", 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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ahoy_email-0.4.0 test/mailer_test.rb
ahoy_email-0.3.2 test/mailer_test.rb
ahoy_email-0.3.1 test/mailer_test.rb