Sha256: 4e01c2f70fbeea43f8cbcaab6eadfcbf59a6af3a1c74a1c07f40af3de2c2a4d7

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

require 'uuid'

module Emailer
  
  class MockNetSmtp
    def start(*args); end
    def sendmail(*args); end
    def finish; end
    def started?; end
  end
  
  class MockSmtpFacade < SmtpFacade
  
    attr_reader :sent
    
    def initialize(settings = {})
      @sent = {}
      super
    end
    
    # Don't open connections...
    def get_net_smtp_instance
      MockNetSmtp.new
    end
    
    # And save, don't send, mail...
    def send_mail(options)
      raise ConnectionNotOpenError unless @open
      @sent[UUID.new.generate] = options
      true
    rescue ConnectionNotOpenError => e
      raise e
    rescue StandardError => e
      @error = e
      @offending_mail = options
      false
    end
    
    def last_email_sent
      @sent[@sent.keys.last.to_s]
    end
    
    def last_email_sent_key
      @sent.keys.last
    end
    
    def last_email_sent_url
      get_url_for last_email_sent_key
    end
    
    def get_url_for uuidString
       TestingMiddleware.testing_path+uuidString
    end
  end
  
end


Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bjornblomqvist-emailer-0.1.15 lib/emailer/mock_smtp_facade.rb