Ditch module syntax and use namespacing instead. Here we will use an existing mailer as an example, but you can namespace anything in our project: controller, models, helpers, you name it!
Place the mailer in the subdirectory ex mailers/users/
Add the namespace to the mailer class itself
class Users::AvailabilityMailingListNewSubscriptionMailer < ApplicationMailer
Wherever the mailer is called in the application, preface it with the namespace
def perform(zipcode, email)
@zipcode = zipcode
@email = email
Users::AvailabilityMailingListNewSubscriptionMailer.send_subscribed_notice(
@zipcode,
@email
)
.deliver_later
end
namespace the appropriate spec folder to match the subfolder in the application spec/mailers/users/
namespace the spec file
require "rails_helper"
RSpec.describe Users::AvailabilityMailingListNewSubscriptionMailer, type: :mailer do
namespace the mailer preview as well spec/mailers/previews/users/
namespace the mailer preview file
class Users::AvailabilityMailingListNewSubscriptionPreview < ActionMailer::Preview