Sha256: 5040ff29fa807faa1a1b00aa7aa484e2b1815d3cb6a2976900a7146340c80de7

Contents?: true

Size: 1.85 KB

Versions: 2

Compression:

Stored size: 1.85 KB

Contents

require 'spec_helper'
require 'flapjack/gateways/email'

describe Flapjack::Gateways::Email, :logger => true do

  before(:each) do
    Flapjack::Gateways::Email.instance_variable_set('@config', {})
    Flapjack::Gateways::Email.instance_variable_set('@logger', @logger)
    Flapjack::Gateways::Email.start
  end

  it "sends a mail with text and html parts" do
    email = mock('email')

    entity_check = mock(Flapjack::Data::EntityCheck)
    entity_check.should_receive(:in_scheduled_maintenance?).and_return(false)
    entity_check.should_receive(:in_unscheduled_maintenance?).and_return(false)
    entity_check.should_receive(:last_change).and_return(Time.now.to_i)

    redis = mock('redis')
    ::Resque.should_receive(:redis).and_return(redis)

    Flapjack::Data::EntityCheck.should_receive(:for_event_id).
      with('example.com:ping', :redis => redis).and_return(entity_check)

    # TODO better checking of what gets passed here
    EM::P::SmtpClient.should_receive(:send).with(
      hash_including(:host    => 'localhost',
                     :port    => 25)).and_return(email)

    response = mock(response)
    response.should_receive(:"respond_to?").with(:code).and_return(true)
    response.should_receive(:code).and_return(250)

    EM::Synchrony.should_receive(:sync).with(email).and_return(response)

    notification = {'notification_type'   => 'recovery',
                    'contact_first_name'  => 'John',
                    'contact_last_name'   => 'Smith',
                    'state'               => 'ok',
                    'summary'             => 'smile',
                    'last_state'          => 'problem',
                    'last_summary'        => 'frown',
                    'time'                => Time.now.to_i,
                    'event_id'            => 'example.com:ping'}

    Flapjack::Gateways::Email.perform(notification)
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
flapjack-0.7.22 spec/lib/flapjack/gateways/email_spec.rb
flapjack-0.7.21 spec/lib/flapjack/gateways/email_spec.rb