mirror of https://github.com/rails/rails
add attachments to the new inbound mail
This commit is contained in:
parent
1e09019088
commit
0419bc3504
|
@ -20,7 +20,11 @@ module Rails
|
|||
|
||||
private
|
||||
def new_mail
|
||||
Mail.new params.require(:mail).permit(:from, :to, :cc, :bcc, :in_reply_to, :subject, :body).to_h
|
||||
Mail.new(params.require(:mail).permit(:from, :to, :cc, :bcc, :in_reply_to, :subject, :body).to_h).tap do |mail|
|
||||
params[:mail][:attachments].to_a.each do |attachment|
|
||||
mail.attachments[attachment.original_filename] = { filename: attachment.path, content_type: attachment.content_type }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def create_inbound_email(mail)
|
||||
|
|
|
@ -38,5 +38,10 @@
|
|||
<%= form.text_area :body, size: "40x20" %>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<%= form.label :attachments, "Attachments" %><br>
|
||||
<%= form.file_field :attachments, multiple: true %>
|
||||
</div>
|
||||
|
||||
<%= form.submit "Deliver inbound email" %>
|
||||
<% end %>
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "test_helper"
|
||||
|
||||
class Rails::Conductor::ActionMailbox::InboundEmailsControllerTest < ActionDispatch::IntegrationTest
|
||||
test "create inbound email" do
|
||||
with_rails_env("development") do
|
||||
assert_difference -> { ActionMailbox::InboundEmail.count }, +1 do
|
||||
post rails_conductor_inbound_emails_path, params: {
|
||||
mail: {
|
||||
from: "Jason Fried <jason@37signals.com>",
|
||||
to: "Replies <replies@example.com>",
|
||||
bcc: "",
|
||||
in_reply_to: "<4e6e35f5a38b4_479f13bb90078178@small-app-01.mail>",
|
||||
subject: "Discussion: Let's debate these attachments",
|
||||
body: "Let's talk about these images:",
|
||||
attachments: [fixture_file_upload("files/avatar1.jpeg"), fixture_file_upload("files/avatar2.jpeg")]
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
assert_equal 2, ActionMailbox::InboundEmail.last.mail.attachments.size
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def with_rails_env(env)
|
||||
old_rails_env = Rails.env
|
||||
Rails.env = env
|
||||
yield
|
||||
ensure
|
||||
Rails.env = old_rails_env
|
||||
end
|
||||
end
|
Binary file not shown.
After Width: | Height: | Size: 20 KiB |
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
Loading…
Reference in New Issue