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
Support multiple preview paths for mailers #31595
Conversation
Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @kamipo (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review. Please see the contribution instructions for more information. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
Please use preview_paths instead. | ||
MSG | ||
self.class.preview_paths.first | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This instance method is currently private, so I think it can be removed without deprecation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like instance reader is public
mattr_accessor :preview_path, instance_writer: false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You‘re right, sorry. 😅
assert_match '<li><a href="/rails/mailers/notifier/foo">foo</a></li>', last_response.body | ||
assert_match '<h3><a href="/rails/mailers/confirm">Confirm</a></h3>', last_response.body | ||
assert_match '<li><a href="/rails/mailers/confirm/foo">foo</a></li>', last_response.body | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test can be combined with the existing one for loading previews from custom preview paths above.
833d4c9
to
6db2c09
Compare
6db2c09
to
d2332af
Compare
@georgeclaghorn, thanks for review. Fixed your notes, squashed and rebased. |
d2332af
to
a74b349
Compare
Friendly ping to revive 👋 We have a use case for this to support some GitLab Enterprise Edition specific email previews which are namespaced under the config.action_mailer.preview_paths = [
'spec/mailers/previews',
'ee/spec/mailers/previews'
] Here is the current config, https://gitlab.com/gitlab-org/gitlab-ce/blob/b17457a7f7fb390c829ff5feed7e4635bf2b4521/config/environments/development.rb#L42 |
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
@georgeclaghorn Wdyt about moving this forward? |
I was just looking for the implementation details. Since it pass ActionMailer::Base.preview_path = "{/etc,/tmp}" Anyway it is just non-intuitive workaround. Introducing |
@@ -25,7 +25,31 @@ module Previews #:nodoc: | |||
mattr_accessor :preview_interceptors, instance_writer: false, default: [ActionMailer::InlinePreviewInterceptor] | |||
end | |||
|
|||
def preview_path | |||
ActiveSupport::Deprecation.warn(<<-MSG.squish) | |||
Using preview_path option is deprecated and will be removed in Rails 6.0. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⌛ Rails 6.1 now
511ffc1
to
c3da463
Compare
@eugeneius please, review 🙏 |
Did this part not work out? It sounds useful, since that's the main motivating use case for supporting multiple preview paths. |
Yeah that, and engines auto include controllers/routes etc in the main app. So this would fit right with that. |
d8f34be
to
8f8c78c
Compare
@eugeneius thanks! Updated. Re:
I initially implemented that. Then something went wrong and I decided to remove this and allow for engines to manually add preview paths. And now everything went right ( 😄 )and I added back engine initializer (and tests for it). |
This would be super useful for Rails Engines that add mailer previews in the host application as we do in Solidus. We worked around the issue with this PR but would be great to have support for that in Rails directly. Any chance to move this forward? |
@fatkodima could you fix the merge conflicts and update the deprecations from |
8fa0a8c
to
4671550
Compare
@p8 Rebased and changed |
Thanks @fatkodima ! |
4671550
to
fd7e999
Compare
fb22c79
to
64ad045
Compare
I believe this needs a revision, it introduces a regression. Since I would consider removing the newly introduced |
Let me illustrate the regression. In Rails 7.0, if you have a directory config.autoload_paths
config.action_mailer.preview_path = "#{Rails.root}/lib/mailer_previews" then
With this patch, Besides being a regression, conceptually this does not look good. It wouldn't be right even if the feature was new. (EDIT: In |
Please, feel free to provide a PR, if you will, since you better know how to implement it properly. 🙏 |
@fatkodima let me understand your patch better. The initializer initializer "action_mailer.set_autoload_paths", before: :set_autoload_paths do |app|
options = app.config.action_mailer
app.config.paths["test/mailers/previews"].concat(options.preview_paths)
end adds preview paths from the application/global configuration point |
These changes https://github.com/rails/rails/pull/31595/files#diff-c72ea90e9c6b7c60285006ea4c34548ae9257dffcda0c1b2f41fffd75a14363b are expected to do that. |
So engines do not have configuration API for it, right? (I don't consider |
Right. |
For those coming here because their Previews no longer got autoloaded after upgrading to Rails 7.1 and that use RSpec (so your previews are under In the meantime, config.action_mailer.preview_paths << "#{Rails.root}/spec/mailers/previews" |
It should be great to see mailer previews from engines. This PR allows to do this.
Originated from a bit outdated #16836.
Notable changes compared to that PR:
config.action_mailer.preview_path
deprecatingThanks in advance.