Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ActionMailer preview loading #3901

Merged
merged 2 commits into from
Jan 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions core/lib/spree/core/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,14 @@ class Engine < ::Rails::Engine
caller
)
end
end

# Load in mailer previews for apps to use in development.
# We need to make sure we call `Preview.all` before requiring our
# previews, otherwise any previews the app attempts to add need to be
# manually required.
if Rails.env.development?
initializer "spree.mailer_previews" do
# Load in mailer previews for apps to use in development.
# We need to make sure we call `Preview.all` before requiring our
# previews, otherwise any previews the app attempts to add need to be
# manually required.
if Rails.env.development? || Rails.env.test?
ActionMailer::Preview.all

Dir[root.join("lib/spree/mailer_previews/**/*_preview.rb")].each do |file|
require_dependency file
end
Expand Down
1 change: 1 addition & 0 deletions core/lib/spree/testing_support/dummy_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class Application < ::Rails::Application
config.secret_key_base = 'SECRET_TOKEN'

config.action_mailer.delivery_job = "ActionMailer::MailDeliveryJob" if RAILS_6_OR_ABOVE
config.action_mailer.preview_path = File.expand_path('dummy_app/mailer_previews', __dir__)
config.active_record.sqlite3.represent_boolean_as_integer = true unless RAILS_6_OR_ABOVE

config.storage_path = Rails.root.join('tmp', 'storage')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class TestMailerPreview < ActionMailer::Preview
end
14 changes: 14 additions & 0 deletions core/spec/lib/spree/core/engine_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe Spree::Core::Engine do
it 'loads engine and app previews' do
expect(ActionMailer::Preview.all).to match_array([
TestMailerPreview,
Spree::MailerPreviews::ReimbursementPreview,
Spree::MailerPreviews::OrderPreview,
Spree::MailerPreviews::CartonPreview,
])
end
end