Skip to content

Commit

Permalink
Fix mailer previews loading
Browse files Browse the repository at this point in the history
The previous attempt was failing because it was adding preview paths
before setting ActionMailer autoloads, causing Solidus previews folder
to be autoloaded by Zeitwerk without namespace, as the `lib` folder is
not a Zeitwerk root (and we cannot add it as one):

    Zeitwerk::NameError:
    expected file solidus/core/lib/spree/mailer_previews/carton_preview.rb
    to define constant CartonPreview, but didn't

Adding the previews path after setting the autoload fixes the issue
by having the same scenario we had before Rails 7.1, i.e. the file is
not autoloaded by Zeitwerk.
  • Loading branch information
spaghetticode committed Dec 15, 2023
1 parent 810e358 commit 5ee2c90
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions core/lib/spree/core/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ class Engine < ::Rails::Engine
end
end

initializer "spree.core.action_mailer.set_preview_path", before: "action_mailer.set_autoload_paths" do |app|
initializer "spree.core.action_mailer.set_preview_path", after: "action_mailer.set_autoload_paths" do |app|
if Rails.gem_version >= Gem::Version.new('7.1.0')
solidus_preview_path = Spree::Core::Engine.root.join 'lib/spree/mailer_previews'
app.config.action_mailer.preview_paths << solidus_preview_path.to_s
solidus_preview_path = Spree::Core::Engine.root.join('lib/spree/mailer_previews')
ActionMailer::Base.preview_paths << solidus_preview_path.to_s
end
end

Expand Down

0 comments on commit 5ee2c90

Please sign in to comment.