Add board settings fields to board JSON responses (#2788)

* Add board settings fields to board JSON responses

* Move public_description fields to board partial, gate on published

* Add index test for public_description fields on published boards

* Update app/views/boards/show.json.jbuilder

Prefer `unless` to `if !`

---------

Co-authored-by: Mike Dalessio <mike.dalessio@gmail.com>
This commit is contained in:
Rob Zolkos
2026-04-08 08:31:52 -04:00
committed by GitHub
parent 8201c2a4bd
commit 2a4adf3a2b
4 changed files with 64 additions and 3 deletions
@@ -217,6 +217,19 @@ class BoardsControllerTest < ActionDispatch::IntegrationTest
assert_equal users(:kevin).boards.count, @response.parsed_body.count
end
test "index as JSON includes public_description fields for published boards" do
board = boards(:writebook)
board.publish
board.update!(public_description: "<p>Public board description.</p>")
get boards_path, as: :json
assert_response :success
published_board = @response.parsed_body.find { |b| b["id"] == board.id }
assert_equal board.public_description.to_plain_text, published_board["public_description"]
assert_equal board.public_description.to_s, published_board["public_description_html"]
end
test "index as JSON paginates and preserves recently-accessed order" do
account = accounts("37s")
kevin = users(:kevin)
@@ -261,6 +274,43 @@ class BoardsControllerTest < ActionDispatch::IntegrationTest
assert_equal boards(:writebook).auto_postpone_period_in_days, @response.parsed_body["auto_postpone_period_in_days"]
end
test "show as JSON includes public_description fields when published" do
board = boards(:writebook)
board.publish
board.update!(public_description: "<p>This is a <strong>public</strong> note.</p>")
get board_path(board), as: :json
assert_response :success
assert_equal board.public_description.to_plain_text, @response.parsed_body["public_description"]
assert_equal board.public_description.to_s, @response.parsed_body["public_description_html"]
end
test "show as JSON excludes public_description fields when not published" do
board = boards(:writebook)
board.update!(public_description: "<p>This is a <strong>public</strong> note.</p>")
assert_not board.published?
get board_path(board), as: :json
assert_response :success
assert_nil @response.parsed_body["public_description"]
assert_nil @response.parsed_body["public_description_html"]
end
test "show as JSON includes granted user_ids when board is not all access" do
board = boards(:private)
board.accesses.revise granted: users(:david, :jz), revoked: []
get board_path(board), as: :json
assert_response :success
assert_equal board.users.ids.sort, @response.parsed_body["user_ids"].sort
end
test "show as JSON excludes user_ids when board is all access" do
get board_path(boards(:writebook)), as: :json
assert_response :success
assert_nil @response.parsed_body["user_ids"]
end
test "show as JSON includes public_url when published" do
board = boards(:writebook)
board.publish