Skip to content

Commit

Permalink
Add MailerHelper#case_reference
Browse files Browse the repository at this point in the history
A generic case reference ID generator for use in email Subject lines to
prevent incorrect threading by mail clients, and/or to use in the Body
for end user ease of reference.
  • Loading branch information
garethrees committed Oct 20, 2023
1 parent 634e562 commit b0a1b9e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
19 changes: 19 additions & 0 deletions app/helpers/mailer_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
module MailerHelper
# Generate a case reference number to differentiate subject lines and/or
# include in the body of emails.
#
# prefix - A String prefix to identify the general case type
# (default: 'CASE').
#
# Examples:
#
# case_reference
# # => "CASE/20231020-DF1I""
#
# case_reference('HELP')
# # => "HELP/20231020-QK3C""
#
# Returns a String case reference ID.
def case_reference(prefix = 'CASE')
"#{prefix}/#{Time.now.strftime('%Y%m%d')}-#{SecureRandom.base36(4).upcase}"
end

def contact_from_name_and_email
"#{AlaveteliConfiguration.contact_name} <#{AlaveteliConfiguration.contact_email}>"
end
Expand Down
17 changes: 17 additions & 0 deletions spec/helpers/mailer_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'spec_helper'

RSpec.describe MailerHelper do
include MailerHelper

describe '#case_reference' do
context 'with the default prefix' do
subject { case_reference }
it { is_expected.to match(/CASE\/\d{8}-[A-Z0-9]{4}/) }
end

context 'with a custom prefix' do
subject { case_reference('HELP') }
it { is_expected.to match(/HELP\/\d{8}-[A-Z0-9]{4}/) }
end
end
end

0 comments on commit b0a1b9e

Please sign in to comment.