From 71a1ee703160945f1844740a68d4d6f23258b044 Mon Sep 17 00:00:00 2001 From: Jeremy Daer Date: Mon, 9 Mar 2026 17:02:08 -0700 Subject: [PATCH] Wrap comment params for flat JSON payloads (#2679) * Wrap comment params for flat JSON payloads The SDK sends flat JSON ({"body": "..."}) but Rails wrap_parameters auto-detection misses :body since it's a virtual ActionText attribute, not in Comment.attribute_names. Explicitly declare wrap_parameters so params.expect(comment: [...]) works with both wrapped and flat payloads. * Test comment create and update with flat JSON params --- app/controllers/cards/comments_controller.rb | 1 + .../cards/comments_controller_test.rb | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/app/controllers/cards/comments_controller.rb b/app/controllers/cards/comments_controller.rb index 6a377bc2c..7aed33c8c 100644 --- a/app/controllers/cards/comments_controller.rb +++ b/app/controllers/cards/comments_controller.rb @@ -1,4 +1,5 @@ class Cards::CommentsController < ApplicationController + wrap_parameters :comment, include: %i[ body created_at ] include CardScoped before_action :set_comment, only: %i[ show edit update destroy ] diff --git a/test/controllers/cards/comments_controller_test.rb b/test/controllers/cards/comments_controller_test.rb index eebd62a9c..be5831e39 100644 --- a/test/controllers/cards/comments_controller_test.rb +++ b/test/controllers/cards/comments_controller_test.rb @@ -84,6 +84,26 @@ class Cards::CommentsControllerTest < ActionDispatch::IntegrationTest assert_equal card_comment_url(comment.card, comment), @response.parsed_body["url"] end + test "create as JSON with flat params" do + card = cards(:logo) + + assert_difference -> { card.comments.count }, +1 do + post card_comments_path(card), params: { body: "Flat comment" }, as: :json + end + + assert_response :created + assert_equal "Flat comment", Comment.last.body.to_plain_text + end + + test "update as JSON with flat params" do + comment = comments(:logo_agreement_kevin) + + put card_comment_path(cards(:logo), comment), params: { body: "Flat update" }, as: :json + + assert_response :success + assert_equal "Flat update", comment.reload.body.to_plain_text + end + test "update as JSON" do comment = comments(:logo_agreement_kevin)