• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pulibrary / oawaiver / 40ca2f09-e694-44a5-b909-7cce179b9e67

11 Jul 2024 05:42PM UTC coverage: 0.0% (-80.4%) from 80.383%
40ca2f09-e694-44a5-b909-7cce179b9e67

push

circleci

jrgriffiniii
Trying to expand the RSpec test suite for EmployeesController#ajax_search

0 of 1206 relevant lines covered (0.0%)

0.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/app/mailers/waiver_mailer.rb
1
# frozen_string_literal: true
2

3
class WaiverMailer < ApplicationMailer
×
4
  class_attribute :initialized, default: false
×
5
  class_attribute :parameters
×
6
  class_attribute :options
×
7
  class_attribute :url
×
8
  class_attribute :from
×
9
  class_attribute :reply_to
×
10
  class_attribute :cc
×
11
  class_attribute :bcc
×
12
  class_attribute :send_to_author
×
13
  class_attribute :mail_templates
×
14

15
  def self.validate_email(address)
×
16
    valid = URI::MailTo::EMAIL_REGEXP.match(address)
×
17

18
    raise("Invalid email address: '#{address}'") unless valid
×
19
    valid
×
20
  end
×
21

22
  # initialize global variables based on Rails.application.config.waiver_mailer_parameters hash
23
  def self.bootstrap
×
24
    return if initialized
×
25

26
    parameters = Rails.application.config.waiver_mailer_parameters
×
27
    self.parameters = ActiveSupport::HashWithIndifferentAccess.new(parameters)
×
28
    env = self.parameters.fetch(Rails.env)
×
29
    self.options = ActiveSupport::HashWithIndifferentAccess.new(env)
×
30

31
    self.url = options.fetch("url", "")
×
32
    self.from = options.fetch("from", "")
×
33

34
    from_entries = Mail::FromField.new(from)
×
35
    from_entries.addresses.each { |e| validate_email(e) }
×
36

37
    self.reply_to = options.fetch("reply_to", "")
×
38
    reply_to_entries = Mail::ReplyToField.new(reply_to)
×
39
    reply_to_entries.addresses.each { |e| validate_email(e) }
×
40

41
    self.cc = options.fetch("cc", "")
×
42
    cc_entries = Mail::CcField.new(cc)
×
43
    cc_entries.addresses.each { |e| validate_email(e) }
×
44

45
    self.bcc = options.fetch("bcc", "")
×
46
    bcc_entries = Mail::BccField.new(bcc)
×
47
    bcc_entries.addresses.each { |e| validate_email(e) }
×
48

49
    self.send_to_author = options.fetch("send_to_author", "")
×
50

51
    mail_templates = parameters.fetch("mail_templates")
×
52
    raise("Failed to resolve the e-mail templates for: #{parameters}") if mail_templates.blank?
×
53

54
    mail_templates = ActiveSupport::HashWithIndifferentAccess.new(mail_templates)
×
55
    self.mail_templates = mail_templates
×
56

57
    required_keys = ["granted"]
×
58
    required_keys.each do |key|
×
59
      raise("Must define a '#{key}' mail template") unless mail_templates.key?(key)
×
60
    end
×
61

62
    self.mail_templates.keys.each do |k|
×
63
      key = k.to_sym
×
64

65
      parts = %w[body subject]
×
66
      parts.each do |part|
×
67
        fname = self.mail_templates[k][part]
×
68
        raise("Must define #{part} for #{key} mail template") if fname.blank?
×
69

70
        template_path = Rails.application.root.join("config", fname)
×
71
        template = File.read(template_path)
×
72
        raise("The file #{template_path} is empty") if template.empty?
×
73

74
        part_key = part.to_sym
×
75
        partial = ERB.new(template.strip)
×
76
        self.mail_templates[k][part_key] = partial
×
77
      end
×
78
    end
×
79

80
    self.initialized = true
×
81
    ActiveRecord::Base.logger.info("WaiverMailer has been initialized.")
×
82

83
    self
×
84
  end
×
85

86
  def self.default_author_email
×
87
    "author@princeton.edu"
×
88
  end
×
89

90
  # create WaiverMail from given waiver_info
91
  def initialize(waiver_info)
×
92
    self.class.bootstrap
×
93
    @waiver_info = waiver_info
×
94

95
    super()
×
96
  end
×
97

98
  def author_email
×
99
    return @waiver_info.author_email if self.class.send_to_author
×
100

101
    self.class.default_author_email
×
102
  end
×
103

104
  # compute to field for mail
105
  # depending on mail_to_authors use "author@princeton.edu" or waiver_info's author_email
106
  def to
×
107
    [
×
108
      @waiver_info.requester_email,
×
109
      author_email
×
110
    ]
×
111
  end
×
112

113
  def url
×
114
    @url ||= self.class.url
×
115
  end
×
116

117
  def waiver_info_url
×
118
    return if @waiver_info.nil? || !@waiver_info.persisted?
×
119

120
    @waiver_info_url ||= begin
×
121
                           pattern = /ID/
×
122
                           model_id = waiver_info.id
×
123
                           value = url.sub(pattern, model_id.to_s)
×
124
                           value
×
125
                         end
×
126
  end
×
127

128
  def mail_templates
×
129
    @mail_templates ||= self.class.mail_templates
×
130
  end
×
131

132
  def granted_mail_template
×
133
    raise("No \"granted\" template is specified within the e-mail templates: #{mail_templates}") unless mail_templates.key?(:granted)
×
134

135
    @granted_mail_template ||= mail_templates[:granted]
×
136
  end
×
137

138
  def body_template
×
139
    return unless granted_mail_template.key?(:body)
×
140

141
    @body_template ||= granted_mail_template[:body]
×
142
  end
×
143

144
  def body
×
145
    return if body_template.nil?
×
146

147
    @body ||= body_template.result(binding)
×
148
  end
×
149

150
  def subject_template
×
151
    raise("No subject header specified within the e-mail template: #{granted_mail_template}") unless granted_mail_template.key?(:subject)
×
152

153
    @subject_template ||= granted_mail_template[:subject]
×
154
  end
×
155

156
  def subject
×
157
    return if subject_template.nil?
×
158

159
    @subject ||= subject_template.result(binding)
×
160
  end
×
161

162
  def from
×
163
    @from ||= self.class.from
×
164
  end
×
165

166
  def reply_to
×
167
    @reply_to ||= self.class.reply_to
×
168
  end
×
169

170
  def bcc
×
171
    @bcc ||= self.class.bcc
×
172
  end
×
173

174
  def cc
×
175
    @cc ||= self.class.cc
×
176
  end
×
177

178
  def granted(cc_address = nil)
×
179
    # self.class.bootstrap
180

181
    # @cc = cc_address if cc_address.present?
182
    if cc_address.present?
×
183
      self.class.validate_email(cc_address)
×
184
      @cc = cc_address
×
185
    end
×
186

187
    mail(
×
188
      to: to,
×
189
      from: from,
×
190
      reply_to: reply_to,
×
191
      cc: cc,
×
192
      bcc: bcc,
×
193
      subject: subject,
×
194
      body: body
×
195
    )
×
196
  end
×
197
end
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc