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

Gracefully degrade when ActionMailer::Base#params is nil #47101

Merged
merged 1 commit into from
Jan 23, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions actionmailer/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
* Default `ActionMailer::Parameterized#params` to an empty `Hash`

*Sean Doyle*

* `assert_emails` now returns the emails that were sent.

This makes it easier to do further analysis on those emails:
Expand Down
6 changes: 5 additions & 1 deletion actionmailer/lib/action_mailer/parameterized.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ module Parameterized
extend ActiveSupport::Concern

included do
attr_accessor :params
attr_writer :params

def params
@params ||= {}
end
end

module ClassMethods
Expand Down
7 changes: 7 additions & 0 deletions actionmailer/test/parameterized_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ class DummyDeliveryJob < ActionMailer::MailDeliveryJob
assert_equal("So says david@basecamp.com", @mail.body.encoded)
end

test "degrade gracefully when .with is not called" do
@mail = ParamsMailer.invitation

assert_nil(@mail.to)
assert_nil(@mail.from)
end

test "enqueue the email with params" do
args = [
"ParamsMailer",
Expand Down