mirror of
https://github.com/basecamp/once-campfire.git
synced 2026-11-25 18:16:28 +09:00
Merge pull request #306 from namespaceMarcello/post-webhook-attachments-only-on-success
Post a webhook reply as an attachment only when the bot answered 200
This commit is contained in:
2 files changed
+2
-2
No files matched your search
@@ -63,7 +63,7 @@ class Webhook < ApplicationRecord
|
||||
end
|
||||
|
||||
def extract_attachment_from(response)
|
||||
if response.content_type && mime_type = Mime::Type.lookup(response.content_type)
|
||||
if response.code == "200" && response.content_type && mime_type = Mime::Type.lookup(response.content_type)
|
||||
ActiveStorage::Blob.create_and_upload! \
|
||||
io: StringIO.new(response.body), filename: "attachment.#{mime_type.symbol}", content_type: mime_type.to_s
|
||||
end
|
||||
|
||||
@@ -41,7 +41,7 @@ class WebhookTest < ActiveSupport::TestCase
|
||||
|
||||
test "delivery with error reply" do
|
||||
assert_no_difference -> { Message.count } do
|
||||
WebMock.stub_request(:post, webhooks(:bender).url).to_return(status: 500, body: "Internal Error!", headers: {})
|
||||
WebMock.stub_request(:post, webhooks(:bender).url).to_return(status: 500, body: "<h1>Internal Error!</h1>", headers: { "Content-Type" => "text/html" })
|
||||
response = webhooks(:bender).deliver(messages(:first))
|
||||
end
|
||||
end
|
||||
|
||||
Reference in new issue
Block a user