Skip to content

Commit

Permalink
Fix preview paths to work with Rails 7.1
Browse files Browse the repository at this point in the history
Adding the previews path after setting the autoload ensures the file
is not autoloaded by Zeitwerk.

Co-Authored-By: andrea longhi <[email protected]>
  • Loading branch information
2 people authored and elia committed Dec 20, 2023
1 parent 534236a commit 1f7783a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
12 changes: 7 additions & 5 deletions core/lib/spree/core/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,14 @@ class Engine < ::Rails::Engine
end

# Load in mailer previews for apps to use in development.
initializer "spree.core.action_mailer.set_preview_path", after: "action_mailer.set_configs" do |app|
original_preview_path = app.config.action_mailer.preview_path
solidus_preview_path = Spree::Core::Engine.root.join 'lib/spree/mailer_previews'
initializer "spree.core.action_mailer.set_preview_path", after: "action_mailer.set_autoload_paths" do
solidus_preview_path = Spree::Core::Engine.root.join("lib/spree/mailer_previews")

app.config.action_mailer.preview_path = "{#{original_preview_path},#{solidus_preview_path}}"
ActionMailer::Base.preview_path = app.config.action_mailer.preview_path
if ActionMailer::Base.respond_to? :preview_paths # Rails 7.1+
ActionMailer::Base.preview_paths << solidus_preview_path.to_s
else
ActionMailer::Base.preview_path = "{#{ActionMailer::Base.preview_path},#{solidus_preview_path}}"
end
end

initializer "spree.deprecator" do |app|
Expand Down
6 changes: 5 additions & 1 deletion core/lib/spree/testing_support/dummy_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ class Application < ::Rails::Application
config.secret_key_base = 'SECRET_TOKEN'

# Set the preview path within the dummy app:
config.action_mailer.preview_path = File.expand_path('dummy_app/mailer_previews', __dir__)
if ActionMailer::Base.respond_to? :preview_paths # Rails 7.1+
config.action_mailer.preview_paths << File.expand_path('dummy_app/mailer_previews', __dir__)
else
config.action_mailer.preview_path = File.expand_path('dummy_app/mailer_previews', __dir__)
end

config.active_record.dump_schema_after_migration = false

Expand Down

0 comments on commit 1f7783a

Please sign in to comment.