Add API for closing and opening cards

This commit is contained in:
Stanko K.R.
2025-12-05 14:07:36 +01:00
parent cf52982b8b
commit b4012dfb40
2 changed files with 34 additions and 4 deletions
+10 -2
View File
@@ -3,11 +3,19 @@ class Cards::ClosuresController < ApplicationController
def create
@card.close
render_card_replacement
respond_to do |format|
format.turbo_stream { render_card_replacement }
format.json { head :no_content }
end
end
def destroy
@card.reopen
render_card_replacement
respond_to do |format|
format.turbo_stream { render_card_replacement }
format.json { head :no_content }
end
end
end
@@ -9,7 +9,7 @@ class Cards::ClosuresControllerTest < ActionDispatch::IntegrationTest
card = cards(:logo)
assert_changes -> { card.reload.closed? }, from: false, to: true do
post card_closure_path(card)
post card_closure_path(card), as: :turbo_stream
assert_card_container_rerendered(card)
end
end
@@ -18,8 +18,30 @@ class Cards::ClosuresControllerTest < ActionDispatch::IntegrationTest
card = cards(:shipping)
assert_changes -> { card.reload.closed? }, from: true, to: false do
delete card_closure_path(card)
delete card_closure_path(card), as: :turbo_stream
assert_card_container_rerendered(card)
end
end
test "create as JSON" do
card = cards(:logo)
assert_not card.closed?
post card_closure_path(card), as: :json
assert_response :no_content
assert card.reload.closed?
end
test "destroy as JSON" do
card = cards(:shipping)
assert card.closed?
delete card_closure_path(card), as: :json
assert_response :no_content
assert_not card.reload.closed?
end
end