test/mailer_test.rb in ahoy_email-0.3.0 vs test/mailer_test.rb in ahoy_email-0.3.1
- old
+ new
@@ -1,18 +1,24 @@
require_relative "test_helper"
class UserMailer < ActionMailer::Base
- after_action :prevent_delivery_to_guests, only: [:welcome2]
+ 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
@@ -27,14 +33,22 @@
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.to # trigger creation
+ 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