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

Evaluate mailer from address at runtime #3684

Merged
merged 1 commit into from
Sep 10, 2019
Merged

Conversation

javierm
Copy link
Member

@javierm javierm commented Sep 6, 2019

References

Background

We're reading the value from the database, but the ApplicationMailer.default method is evaluated when the application is started. So if we don't use a Proc, we'll need to restart the server every time we change the value in the database, or else the old value will still be used.

Objectives

Make sure emails are sent using the from address currently defined in the database.

Notes

Before these changes, the following tests failed locally if executed right after running rake db:test:prepare, because the default from: was being evaluated before seeding the test database.

  1) Dashboards Rake #send_notifications Send notifications to proposal author when there are news actions actived for draft proposals
     Failure/Error: expect(email).to deliver_from("CONSUL <noreply@consul.dev>")

     NoMethodError:
       undefined method `addrs' for #<Mail::UnstructuredField:0x00562f174330e0>
     # ./spec/lib/tasks/dashboards_spec.rb:80:in `block (4 levels) in <top (required)>'

  2) Dashboards Rake #send_notifications Send notifications to proposal author  when there are news actions actived for published proposals
     Failure/Error: expect(email).to deliver_from("CONSUL <noreply@consul.dev>")

     NoMethodError:
       undefined method `addrs' for #<Mail::UnstructuredField:0x00562f0f85c250>
     # ./spec/lib/tasks/dashboards_spec.rb:67:in `block (4 levels) in <top (required)>'

  3) Dashboard::Mailer#new_actions_notification rake task #new_actions_notification_rake_published sends emails when detect new actions for proposal
     Failure/Error: expect(email).to deliver_from("CONSUL <noreply@consul.dev>")

     NoMethodError:
       undefined method `addrs' for #<Mail::UnstructuredField:0x007fd676f2c250>
     # ./spec/mailers/dashboard/mailer_spec.rb:125:in `block (4 levels) in <top (required)>'

  4) Dashboard::Mailer#new_actions_notification rake task #new_actions_notification_rake_created sends emails when detect new actions for draft proposal
     Failure/Error: expect(email).to deliver_from("CONSUL <noreply@consul.dev>")

     NoMethodError:
       undefined method `addrs' for #<Mail::UnstructuredField:0x00562f1bdc1068>
     # ./spec/mailers/dashboard/mailer_spec.rb:83:in `block (4 levels) in <top (required)>'

  5) Dashboard::Mailer#new_actions_notification_on_create sends emails if new actions detected when creating a proposal
     Failure/Error: expect(email).to deliver_from("CONSUL <noreply@consul.dev>")

     NoMethodError:
       undefined method `addrs' for #<Mail::UnstructuredField:0x007fd677494800>
     # ./spec/mailers/dashboard/mailer_spec.rb:181:in `block (3 levels) in <top (required)>'

  6) Dashboard::Mailer#new_actions_notification_on_published sends emails when detect new actions when publish a proposal
     Failure/Error: expect(email).to deliver_from("CONSUL <noreply@consul.dev>")

     NoMethodError:
       undefined method `addrs' for #<Mail::UnstructuredField:0x00562f1bef7040>
     # ./spec/mailers/dashboard/mailer_spec.rb:247:in `block (3 levels) in <top (required)>'

  7) Dashboard::Mailer#forward sends forward email
     Failure/Error: expect(email).to deliver_from("CONSUL <noreply@consul.dev>")

     NoMethodError:
       undefined method `addrs' for #<Mail::UnstructuredField:0x007fd6756b02d0>
     # ./spec/mailers/dashboard/mailer_spec.rb:40:in `block (3 levels) in <top (required)>'

@javierm javierm force-pushed the capybara_webmock branch 4 times, most recently from a784261 to 8bb5462 Compare September 7, 2019 11:23
@javierm javierm self-assigned this Sep 7, 2019
@javierm javierm changed the base branch from capybara_webmock to master September 10, 2019 12:50
We're reading the value from the database, but the
`ApplicationMailer.default` method is evaluated when the application is
started. So if we don't use a Proc, we'll need to restart the server
every time we change the value in the database, or else the old value
will still be used.

Using a Proc makes sure the mailer from address is evaluated at runtime,
so emails are sent using the from address currently defined in the
database.

The same situation took place using the devise mailer. Now we don't need
to check for the settings table being present because the Proc in the
devise initializer won't be evaluated before the settings table is
created and populated.
@javierm javierm merged commit e25d0eb into master Sep 10, 2019
@javierm javierm deleted the dynamic_from_mailer branch September 10, 2019 15:08
@javierm javierm added this to Release 1.1.0 in Roadmap Sep 10, 2019
@javierm javierm added the Bug label Sep 11, 2019
smarques pushed a commit to venetochevogliamo/consul that referenced this pull request Apr 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Roadmap
  
Release 1.1.0
Development

Successfully merging this pull request may close these issues.

None yet

1 participant