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

Conversation

seanpdoyle
Copy link
Contributor

@seanpdoyle seanpdoyle commented Jan 21, 2023

Motivation / Background

Prior to this change, access to params on ActionMailer::Base instances prior to being decorated by ActionMailer::Parameterized.with calls results in a NoMethodError:

Error:
ParameterizedTest#test_degrade_gracefully_when_.with_is_not_called:
NoMethodError: undefined method `[]' for nil:NilClass

  before_action { @inviter, @invitee = params[:inviter], params[:invitee] }
                                             ^^^^^^^^^^

Detail

This change modifies the attr_accessor :params to be an attr_writer paired with a params method that assigns @params to an empty Hash whenever it's accessed without being otherwise initialized.

Checklist

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one change. Changes that are unrelated should be opened in separate PRs.
  • Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: [Fix #issue-number]
  • Tests are added or updated if you fix a bug or add a feature.
  • CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included.

Prior to this change, access to `params` on `ActionMailer::Base`
instances prior to being decorated by `ActionMailer::Parameterized.with`
calls results in a `NoMethodError`:

```
Error:
ParameterizedTest#test_degrade_gracefully_when_.with_is_not_called:
NoMethodError: undefined method `[]' for nil:NilClass

  before_action { @Inviter, @invitee = params[:inviter], params[:invitee] }
                                             ^^^^^^^^^^
```

This change modifies the `attr_accessor :params` to be an `attr_writer`
paired with a `params` method that assigns `@params` to an empty `Hash`
whenever it's accessed without being otherwise initialized.
@rafaelfranca rafaelfranca merged commit b308a99 into rails:main Jan 23, 2023
@seanpdoyle seanpdoyle deleted the action-mailer-params-default branch January 23, 2023 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants