From 235a94355e99a0219fc92ace8dbca660bdc66574 Mon Sep 17 00:00:00 2001 From: "Stanko K.R." Date: Fri, 5 Dec 2025 13:36:21 +0100 Subject: [PATCH] Add card update & delete actions --- app/controllers/cards_controller.rb | 11 ++++++++++- test/controllers/cards_controller_test.rb | 16 ++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/app/controllers/cards_controller.rb b/app/controllers/cards_controller.rb index 361415dec..a3098b4b0 100644 --- a/app/controllers/cards_controller.rb +++ b/app/controllers/cards_controller.rb @@ -32,11 +32,20 @@ class CardsController < ApplicationController def update @card.update! card_params + + respond_to do |format| + format.turbo_stream + format.json { render :show } + end end def destroy @card.destroy! - redirect_to @card.board, notice: "Card deleted" + + respond_to do |format| + format.html { redirect_to @card.board, notice: "Card deleted" } + format.json { head :no_content } + end end private diff --git a/test/controllers/cards_controller_test.rb b/test/controllers/cards_controller_test.rb index ba38fb191..6ef509ac4 100644 --- a/test/controllers/cards_controller_test.rb +++ b/test/controllers/cards_controller_test.rb @@ -154,4 +154,20 @@ class CardsControllerTest < ActionDispatch::IntegrationTest assert_equal "Big if true", card.description.to_plain_text assert_equal [ tags(:mobile), tags(:web) ].sort, card.tags.sort end + + test "update as JSON" do + card = cards(:logo) + put card_path(card, format: :json), params: { card: { title: "Update test" } } + + assert_response :success + assert_equal "Update test", card.reload.title + end + + test "delete as JSON" do + card = cards(:logo) + delete card_path(card, format: :json) + + assert_response :no_content + assert_not Card.exists?(card.id) + end end