Skip to content

Commit

Permalink
Merge branch 'case-reference-mailer-helper' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
gbp committed Nov 3, 2023
2 parents 53fa606 + 576fbd6 commit a95d9fe
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 a95d9fe

Please sign in to comment.