Merge pull request #45103 from dorianmariefr/issue-45088-error-when-submitting-action-mailbox-conductor-form

Fixes development Action Mailbox new mail form
This commit is contained in:
Jean Boussier 2022-05-15 17:07:06 -04:00 committed by GitHub
commit 85cd509084
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 1 deletions

View File

@ -22,7 +22,7 @@ module Rails
def new_mail
Mail.new(mail_params.except(:attachments).to_h).tap do |mail|
mail[:bcc]&.include_in_headers = true
mail_params[:attachments].to_a.each do |attachment|
mail_params[:attachments]&.select(&:present?)&.each do |attachment|
mail.add_file(filename: attachment.original_filename, content: attachment.read)
end
end

View File

@ -72,6 +72,29 @@ class Rails::Conductor::ActionMailbox::InboundEmailsControllerTest < ActionDispa
end
end
test "create inbound email with empty attachment" do
with_rails_env("development") do
assert_difference -> { ActionMailbox::InboundEmail.count }, +1 do
post rails_conductor_inbound_emails_path, params: {
mail: {
from: "",
to: "",
cc: "",
bcc: "",
x_original_to: "",
subject: "",
in_reply_to: "",
body: "",
attachments: [ "" ],
}
}
end
mail = ActionMailbox::InboundEmail.last.mail
assert_equal 0, mail.attachments.count
end
end
private
def with_rails_env(env)
old_rails_env = Rails.env