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 email generator #938

Merged
merged 1 commit into from
Oct 19, 2018
Merged

Conversation

rikkipitt
Copy link
Contributor

The email generator attempts to inject SMTP config into config/environments/production.rb after the line config.action_mailer.raise_delivery_errors = false. This line is not found anymore and thus fails (NB: find reference).

I propose the code is injected after config.action_mailer.perform_caching = false instead.

In production, you may experience the following error as action mailer attempts to use the default port 25:

Connection refused - connect(2) for "localhost" port 25
/app/vendor/ruby-2.5.1/lib/ruby/2.5.0/net/smtp.rb:539:in `initialize'
/app/vendor/ruby-2.5.1/lib/ruby/2.5.0/net/smtp.rb:539:in `open'
/app/vendor/ruby-2.5.1/lib/ruby/2.5.0/net/smtp.rb:539:in `tcp_socket'
/app/vendor/ruby-2.5.1/lib/ruby/2.5.0/net/smtp.rb:549:in `block in do_start'
/app/vendor/ruby-2.5.1/lib/ruby/2.5.0/timeout.rb:93:in `block in timeout'
/app/vendor/ruby-2.5.1/lib/ruby/2.5.0/timeout.rb:103:in `timeout'
/app/vendor/ruby-2.5.1/lib/ruby/2.5.0/net/smtp.rb:548:in `do_start'
/app/vendor/ruby-2.5.1/lib/ruby/2.5.0/net/smtp.rb:518:in `start'
...
...

The email generator attempts to inject SMTP config into `config/environments/production.rb` after the line `config.action_mailer.raise_delivery_errors = false`. This line is not found anymore and thus fails (NB: find reference). I propose the code is injected after `config.action_mailer.perform_caching = false` instead.

In production, you may experience the following error as action mailer attempts to use the default port 25:

```
Connection refused - connect(2) for "localhost" port 25
/app/vendor/ruby-2.5.1/lib/ruby/2.5.0/net/smtp.rb:539:in `initialize'
/app/vendor/ruby-2.5.1/lib/ruby/2.5.0/net/smtp.rb:539:in `open'
/app/vendor/ruby-2.5.1/lib/ruby/2.5.0/net/smtp.rb:539:in `tcp_socket'
/app/vendor/ruby-2.5.1/lib/ruby/2.5.0/net/smtp.rb:549:in `block in do_start'
/app/vendor/ruby-2.5.1/lib/ruby/2.5.0/timeout.rb:93:in `block in timeout'
/app/vendor/ruby-2.5.1/lib/ruby/2.5.0/timeout.rb:103:in `timeout'
/app/vendor/ruby-2.5.1/lib/ruby/2.5.0/net/smtp.rb:548:in `do_start'
/app/vendor/ruby-2.5.1/lib/ruby/2.5.0/net/smtp.rb:518:in `start'
...
...
```
@rikkipitt
Copy link
Contributor Author

Further investigation:

config.action_mailer.perform_caching = false is in the default Rails production.rb config file (commented out), thus works via tests. It seems that the comment removal task is being run before the email_generator, hence the problem I'm finding and why the email_generator_spec works. An ordering issue?

Explicitly adding:

it "configs email delivery method for production" do
    expect(production_config).
      to match(/^ +config.action_mailer.delivery_method = :smtp$/)
end

To the new_project_spec.rb shows the expected failure...

@composerinteralia
Copy link
Contributor

composerinteralia commented Oct 19, 2018

Thanks! I ran into this problem this week.

https://github.com/thoughtbot/suspenders/blob/master/spec/features/production/email_spec.rb runs the email generator directly without going through the rest of the suspenders setup, so indeed the comments are still in the file for that test.

Another option would be to add the configuration at the end, like we do here:

before: "\nend"

I'll go ahead and merge as is. We can maybe revisit with #946

@composerinteralia composerinteralia merged commit e09a56d into thoughtbot:master Oct 19, 2018
@rikkipitt
Copy link
Contributor Author

Thanks for merging in. I was wondering about the tests, I came back to it to add in a case for it but didn't have enough time to fully figure it out...

@composerinteralia
Copy link
Contributor

composerinteralia commented Oct 19, 2018

Thanks for the PR! We ended up with a failing test once I rebased on master 🤷‍♂️ , so I added 476dabb. Hopefully that commit will future proof this a bit.

I just released 1.49.0, which includes this change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants