Sha256: 65ce26f8522115700535eacb96147970976b3260b232db5a9eb4c96205043e3c

Contents?: true

Size: 1.31 KB

Versions: 4

Compression:

Stored size: 1.31 KB

Contents

require 'helper'
require 'fixtures/mailer_app/app'

class TestMailerPlugin < Test::Unit::TestCase
  def app
    MailerDemo.tap { |app| app.set :environment, :test }
  end

  context 'for mail delivery in sample application' do
    setup { MailerDemo::SampleMailer.smtp_settings = MailerDemo.smtp_settings }

    should 'be able to deliver plain text emails' do
      assert_email_sent(:to => 'john@fake.com', :from => 'noreply@birthday.com', :via => :smtp,
                        :subject => "Happy Birthday!", :body => "Happy Birthday Joey! \nYou are turning 21")
      visit '/deliver/plain', :post
      assert_equal 'mail delivered', last_response.body
    end

    should 'be able to deliver html emails' do
      assert_email_sent(:to => 'julie@fake.com', :from => 'noreply@anniversary.com', :type => 'html', :via => :smtp,
                        :subject => "Happy anniversary!", :body => "<p>Yay Joey & Charlotte!</p>\n<p>You have been married 16 years</p>")
      visit '/deliver/html', :post
      assert_equal 'mail delivered', last_response.body
    end
  end

  protected

  def assert_email_sent(mail_attributes)
    delivery_attributes = mail_attributes.merge(:smtp => MailerDemo.smtp_settings)
    Sinatra::MailerPlugin::MailObject.any_instance.expects(:send_mail).with(delivery_attributes).once.returns(true)
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
darkhelmet-sinatra_more-0.3.36 test/test_mailer_plugin.rb
darkhelmet-sinatra_more-0.3.35 test/test_mailer_plugin.rb
darkhelmet-sinatra_more-0.3.34 test/test_mailer_plugin.rb
darkhelmet-sinatra_more-0.3.33 test/test_mailer_plugin.rb