Add JSON response format to board publication toggle (#2663)

This commit is contained in:
Rob Zolkos
2026-03-05 20:48:03 -05:00
committed by GitHub
parent e27c0c5fa1
commit e47f2d93eb
5 changed files with 103 additions and 1 deletions
@@ -27,6 +27,31 @@ class Boards::PublicationsControllerTest < ActionDispatch::IntegrationTest
assert_turbo_stream action: :replace, target: dom_id(@board, :publication)
end
test "publish a board via JSON" do
assert_not @board.published?
assert_changes -> { @board.reload.published? }, from: false, to: true do
post board_publication_path(@board), as: :json
end
assert_response :created
body = @response.parsed_body
@board.reload
assert_equal @board.name, body["name"]
assert_equal published_board_url(@board), body["public_url"]
end
test "unpublish a board via JSON" do
@board.publish
assert @board.published?
assert_changes -> { @board.reload.published? }, from: true, to: false do
delete board_publication_path(@board), as: :json
end
assert_response :no_content
end
test "publish requires board admin permission" do
logout_and_sign_in_as :jz
@@ -250,6 +250,24 @@ class BoardsControllerTest < ActionDispatch::IntegrationTest
assert_equal boards(:writebook).name, @response.parsed_body["name"]
end
test "show as JSON includes public_url when published" do
board = boards(:writebook)
board.publish
get board_path(board), as: :json
assert_response :success
assert_equal published_board_url(board), @response.parsed_body["public_url"]
end
test "show as JSON excludes public_url when not published" do
board = boards(:writebook)
assert_not board.published?
get board_path(board), as: :json
assert_response :success
assert_nil @response.parsed_body["public_url"]
end
test "create as JSON" do
assert_difference -> { Board.count }, +1 do
post boards_path, params: { board: { name: "My new board" } }, as: :json