Skip to content

Fix Allow header typo and Mail::Message.set guard bug#2318

Merged
nesquena merged 6 commits into
masterfrom
achiurizo-bug-fixes
Mar 28, 2026
Merged

Fix Allow header typo and Mail::Message.set guard bug#2318
nesquena merged 6 commits into
masterfrom
achiurizo-bug-fixes

Conversation

@achiurizo
Copy link
Copy Markdown
Member

@achiurizo achiurizo commented Mar 28, 2026

  • Fix Allow header typo in 405 response (was Allows)
  • Add .uniq to Allow header verbs to avoid duplicates
  • Fix Mail::Message.set guard to check method_defined?(name) instead of :erb
  • Fix Mail::Message.set to define methods on singleton_class instead of Class
  • Add test for Mail::Message.set defining accessor methods
  • Add test for Mail::Message.set not redefining an already defined method
  • Fix test ensure blocks to check/remove methods from Mail::Message.singleton_class (not Class)

💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses two correctness issues discovered during triage: (1) the HTTP 405 response header should be Allow (not Allows), and (2) Mail::Message.set should correctly guard method definition based on the provided setting name.

Changes:

  • Fix 405 responses to emit the RFC-compliant Allow header.
  • Fix Mail::Message.set to avoid incorrectly blocking subsequent set() calls after :erb is defined.
  • Add/extend tests to cover both fixes (405 Allow header assertion, and Mail::Message.set behavior).

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
padrino-mailer/test/test_message.rb Adds tests for Mail::Message.set defining/guarding setting accessors.
padrino-mailer/lib/padrino-mailer/ext.rb Fixes the set guard to check method_defined?(name) rather than :erb.
padrino-core/test/test_routing.rb Adds assertion for Allow header on 405.
padrino-core/lib/padrino-core/application/routing.rb Fixes header name from Allows to Allow on 405 responses.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread padrino-mailer/test/test_message.rb Outdated
Comment thread padrino-core/lib/padrino-core/application/routing.rb Outdated
Comment thread padrino-mailer/lib/padrino-mailer/ext.rb Outdated
Comment thread padrino-mailer/test/test_message.rb Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread padrino-mailer/test/test_message.rb Outdated
Comment thread padrino-mailer/test/test_message.rb Outdated
@nesquena
Copy link
Copy Markdown
Member

Tested locally — full suite passes across all sub-gems (1,443 runs, 0 failures, 0 errors). Both fixes verified manually:

Allow header: confirmed POST, PUT (unique, correct header name) on 405 responses
Mail::Message.set: confirmed methods land on Mail::Message.singleton_class, no longer pollute Class, and guard correctly prevents redefinition

One minor issue: the test ensure blocks clean up from Class but the methods are now on Mail::Message.singleton_class, so the cleanup is a no-op. Copilot's latest suggestion is correct — should be Mail::Message.singleton_class.method_defined? / Mail::Message.singleton_class.send(:remove_method, ...). Not blocking since the leaked settings are harmless, but worth a quick fix before merge.

Otherwise LGTM.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread padrino-mailer/test/test_message.rb Outdated
Comment on lines +175 to +176
ensure
Class.send(:remove_method, :_test_custom_setting) if Class.method_defined?(:_test_custom_setting)
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ensure cleanup is removing methods from Class, but Mail::Message.set defines a singleton method on Mail::Message (its singleton_class). This ensure currently won’t clean up the method and could also accidentally remove a real method from Class if one ever exists with that name. Please remove the method from Mail::Message.singleton_class (and check Mail::Message.singleton_class.method_defined?).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot apply changes based on this feedback

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed — the ensure block now checks and removes from Mail::Message.singleton_class instead of Class. Commit: the latest change to test_message.rb.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in commit 32dd813. Both ensure blocks now check and remove methods from Mail::Message.singleton_class instead of Class, matching where Mail::Message.set actually defines the methods.

Comment on lines +184 to +186
ensure
Class.send(:remove_method, :_test_another_setting) if Class.method_defined?(:_test_another_setting)
end
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same cleanup issue here: _test_another_setting is defined as a singleton method on Mail::Message, but the ensure block removes from Class. This will leave the test method defined across the suite and can cause cross-test pollution; remove it from Mail::Message.singleton_class instead.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot apply changes based on this feedback

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed — same correction applied here: cleanup now targets Mail::Message.singleton_class.send(:remove_method, ...) with the appropriate guard check.

Copy link
Copy Markdown

Copilot AI commented Mar 28, 2026

Tested locally — full suite passes across all sub-gems (1,443 runs, 0 failures, 0 errors). Both fixes verified manually:

Allow header: confirmed POST, PUT (unique, correct header name) on 405 res...

Fixed in commit 32dd813. The ensure blocks now use Mail::Message.singleton_class.method_defined? and Mail::Message.singleton_class.send(:remove_method, ...) to correctly clean up the methods defined by Mail::Message.set.

The ensure blocks were cleaning up from Class instead of
Mail::Message.singleton_class, making them no-ops since set()
defines methods on the singleton class.
@nesquena
Copy link
Copy Markdown
Member

Pushed one small fix — the test ensure blocks were cleaning up from Class but set() now defines methods on Mail::Message.singleton_class, so the cleanup was a no-op. Updated to target Mail::Message.singleton_class so the methods are actually removed after each test.

LGTM — merging as soon as CI is all green.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@nesquena nesquena merged commit e558248 into master Mar 28, 2026
16 checks passed
@nesquena nesquena deleted the achiurizo-bug-fixes branch March 28, 2026 17:16
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.

4 participants