File: test_mailer.rb

package info (click to toggle)
ruby-mail 2.6.4%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 4,256 kB
  • ctags: 1,327
  • sloc: ruby: 44,678; makefile: 3
file content (45 lines) | stat: -rw-r--r-- 1,187 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# frozen_string_literal: true
require 'mail/check_delivery_params'

module Mail
  # The TestMailer is a bare bones mailer that does nothing.  It is useful
  # when you are testing.
  # 
  # It also provides a template of the minimum methods you require to implement
  # if you want to make a custom mailer for Mail
  class TestMailer
    include Mail::CheckDeliveryParams

    # Provides a store of all the emails sent with the TestMailer so you can check them.
    def TestMailer.deliveries
      @@deliveries ||= []
    end

    # Allows you to over write the default deliveries store from an array to some
    # other object.  If you just want to clear the store, 
    # call TestMailer.deliveries.clear.
    # 
    # If you place another object here, please make sure it responds to:
    # 
    # * << (message)
    # * clear
    # * length
    # * size
    # * and other common Array methods
    def TestMailer.deliveries=(val)
      @@deliveries = val
    end

    def initialize(values)
      @settings = values.dup
    end
    
    attr_accessor :settings

    def deliver!(mail)
      check_delivery_params(mail)
      Mail::TestMailer.deliveries << mail
    end
    
  end
end