From c472f8477b338d95545e824c929afe8ef1a43d3d Mon Sep 17 00:00:00 2001 From: Daniel Schmidt Date: Mon, 27 Jan 2025 15:23:30 -0800 Subject: [PATCH] Adds tests for the StagingInterceptor to boost coverage --- spec/mailers/staging_interceptor_spec.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 spec/mailers/staging_interceptor_spec.rb diff --git a/spec/mailers/staging_interceptor_spec.rb b/spec/mailers/staging_interceptor_spec.rb new file mode 100644 index 0000000..d831504 --- /dev/null +++ b/spec/mailers/staging_interceptor_spec.rb @@ -0,0 +1,24 @@ +require 'rails_helper' + +RSpec.describe Interceptors::StagingInterceptor, type: :mailer do + around do |test| + ActionMailer::Base.register_interceptor(Interceptors::StagingInterceptor) + test.run + ActionMailer::Base.unregister_interceptor(Interceptors::StagingInterceptor) + end + + it 'rewrites outbound mail to the test list' do + mail = NotificationsMailer.signup + mail.cc %w[a@berkeley.edu b@berkeley.edu] + mail.bcc %w[c@berkeley.edu d@berkeley.edu] + mail.deliver_now + + expect(mail.to).to eq %w[lib-testmail@lists.berkeley.edu] + expect(mail.cc).to be_empty + expect(mail.bcc).to be_empty + expect(mail.header[:x_lap_service].value).to eq 'geodata' + expect(mail.header[:x_original_to].value).to eq 'fake@berkeley.edu' + expect(mail.header[:x_original_cc].value).to eq 'a@berkeley.edu, b@berkeley.edu' + expect(mail.header[:x_original_bcc].value).to eq 'c@berkeley.edu, d@berkeley.edu' + end +end