-
Notifications
You must be signed in to change notification settings - Fork 236
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
Stop letter_opener when seeding the DB #117
Comments
You can put them in the environment-specific configuration files, so for development it is # Turn off deliveries
config.action_mailer.perfom_deliveries = false |
Thanks, it worked. I hope this helps people coming here with the same issue :) |
Uhm... it's working because I have disabled it for development. So if it's disabled for development, what's the point for letter_opener? It's intended for the development environment, so this solution is not ideal. I'm reopening the issue. |
Well, you can disable |
I seed it more often, because I create and update my models several times. What's more, other (non-technical) people in the team follow the instructions in the Readme to seed the DB. That's what we are going to do, but since it's not ideal I would love to know another more suitable solution. |
@davidmles can you try to change delivery method from |
@nashby I just tried it, same problem. Let me know if you need me to do something to debug this, please. |
@davidmles that's strange. Actually it works with adding only |
I have tried it with a new application, and it actually works. I'm thinking it's because I use Sidekiq. Maybe that cannot be controlled by the If that's the reason, I'm happy to close the issue. |
@davidmles hmm, that's strange. Looking at the code I can see that sidekiq uses |
I'm using the latest version of Rails and Sidekiq, and using the deliver_later method. |
Steps to reproduce the issue:
gem 'sidekiq'
gem 'sinatra', require: nil
group :development do
gem 'letter_opener'
end
---
:concurrency: 5
:queues:
- mailers
- default
config.action_mailer.delivery_method = :letter_opener
class ApplicationMailer < ActionMailer::Base
def sample_email
mail from: 'example@example.org', to: 'example@example.com', subject: 'This is an example'
end
end
ActionMailer::Base.perform_deliveries = false
ApplicationMailer.sample_email.deliver_later
You should see the email actually being sent and letter opener opening it in a browser. |
Hmmm ActionMailer::Base.perform_deliveries = false
ApplicationMailer.sample_email.deliver_later
ApplicationMailer.sample_email("Now").deliver_now # no email |
@davidmies Sidekiq will be running a separate instance of the environment so it will still have the usual configuration of You've only set that deliveries won't be performed in the instance of the environment where your seeds are being executed. That's why deliver_now isn't sending them: because it is running in the thread where you've set mails not to be delivered. |
Thanks @shadwell, that makes sense. So, isn't it possible to deny it to send them using |
No, not by temporarily changing the configuration I think. You've have to temporarily change it in the thread that actually sends the emails. You may have more luck skipping the actual delivery of the emails when seeding rather than trying to get letter_opener to suppress its delivery. |
@davidmles is it still an issue for you? I think you can try to disable sidekiq in the seed file somehow since you don't really need it there, do you?. Probably this would work https://github.com/mperham/sidekiq/wiki/Testing. Closing this for now. |
I'm late to the party on this one, but for what it's worth, my solution was to create a separate Rails environment require Rails.root.join('config/environments/development_base')
Rails.application.configure do
# Avoid async difficulties when seeding data
config.active_job.queue_adapter = :inline
# Do not pop up emails in browser when seeding (due to letter_opener gem)
config.action_mailer.delivery_method = :test
config.action_mailer.perform_deliveries = false
end |
Rather than having to rely on an extra environment, I just disable these in my seed script: ActiveJob::Base.queue_adapter = :inline
ActionMailer::Base.delivery_method = :test
ActionMailer::Base.perform_deliveries = false |
Is it possible to stop letter_opener when seeding the DB?
I have added this snippet at the beginning of my
seeds.rb
file:But lots of windows open. No matter where I move that snippet, I have tried to place it just before the code that triggers those emails, but I have the same problem.
This is happening on my development environment.
The text was updated successfully, but these errors were encountered: