mailjet / mailjet-gem

[API v3] Mailjet official Ruby GEM
https://dev.mailjet.com
Other
130 stars 72 forks source link

Rails integration causes an "Initialization autoloaded the constants ActionText::ContentHelper" warning #213

Closed kemenaran closed 2 years ago

kemenaran commented 3 years ago

Summary

When adding the Mailjet gem to a Rails project through the Gemfile, it causes Rails to issue a warning in the console when starting the app:

DEPRECATION WARNING: Initialization autoloaded the constants ActionText::ContentHelper and ActionText::TagHelper.

Steps to reproduce

  1. Add mailjet to the Gemfile
    # Gemfile
    gem 'mailjet'
  2. Start the Rails app
    bin/rails server

Details

The issue occurs because Mailjet's Rail integration causes ActionMail to be loaded early.

This will in turn:

  1. trigger Rails' action_text.helpers initializer early,
  2. which will cause ActionController::Base to be loaded before ActionText,
  3. which will cause ActionText constants to be automatically discovered,
  4. which will cause the warning above.

Workaround

A workaround is to not require the mailjet gem automatically.

# Gemfile
gem 'mailjet', require: false
# config/initializers/mailjet
ActiveSupport.on_load(:action_mailer) do
  require 'mailjet'

  Mailjet.configure do |config|
    # …
  end
end
kemenaran commented 2 years ago

Thanks! 💚