diff --git a/app/models/webhook.rb b/app/models/webhook.rb index 10d2e383d..1eefb2cb5 100644 --- a/app/models/webhook.rb +++ b/app/models/webhook.rb @@ -50,7 +50,7 @@ class Webhook < ApplicationRecord end def renderer - @renderer ||= ApplicationController.renderer.new + @renderer ||= ApplicationController.renderer.new(script_name: "/#{tenant}", https: !Rails.env.local?) end def for_basecamp? diff --git a/app/models/webhook/delivery.rb b/app/models/webhook/delivery.rb index fbd3398b0..e90a8decb 100644 --- a/app/models/webhook/delivery.rb +++ b/app/models/webhook/delivery.rb @@ -116,6 +116,8 @@ class Webhook::Delivery < ApplicationRecord def content_type if webhook.for_campfire? "text/html" + elsif webhook.for_basecamp? + "application/x-www-form-urlencoded" else "application/json" end @@ -123,7 +125,7 @@ class Webhook::Delivery < ApplicationRecord def payload @payload ||= if webhook.for_basecamp? - { line: { content: render_payload(formats: :html) } }.to_json + { content: render_payload(formats: :html) }.to_query elsif webhook.for_campfire? render_payload(formats: :html) elsif webhook.for_slack? diff --git a/test/models/webhook/delivery_test.rb b/test/models/webhook/delivery_test.rb index 80c7af8af..54530bafb 100644 --- a/test/models/webhook/delivery_test.rb +++ b/test/models/webhook/delivery_test.rb @@ -126,9 +126,9 @@ class Webhook::DeliveryTest < ActiveSupport::TestCase request_stub = stub_request(:post, webhook.url) .with do |request| - body = JSON.parse(request.body) - body.key?("line") && body["line"].key?("content") && body["line"]["content"].present? && - request.headers["Content-Type"] == "application/json" + body = CGI.parse(request.body) + body.key?("content") && body["content"].first.present? && + request.headers["Content-Type"] == "application/x-www-form-urlencoded" end .to_return(status: 200)