Add JSON support for pin/unpin on the card endpoints and add tests.
This commit is contained in:
@@ -9,14 +9,22 @@ class Cards::PinsController < ApplicationController
|
||||
@pin = @card.pin_by Current.user
|
||||
|
||||
broadcast_add_pin_to_tray
|
||||
render_pin_button_replacement
|
||||
|
||||
respond_to do |format|
|
||||
format.turbo_stream { render_pin_button_replacement }
|
||||
format.json { head :no_content }
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@pin = @card.unpin_by Current.user
|
||||
|
||||
broadcast_remove_pin_from_tray
|
||||
render_pin_button_replacement
|
||||
|
||||
respond_to do |format|
|
||||
format.turbo_stream { render_pin_button_replacement }
|
||||
format.json { head :no_content }
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -17,6 +17,17 @@ class Cards::PinsControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "create as JSON" do
|
||||
card = cards(:layout)
|
||||
|
||||
assert_not card.pinned_by?(users(:kevin))
|
||||
|
||||
post card_pin_path(card), as: :json
|
||||
|
||||
assert_response :no_content
|
||||
assert card.reload.pinned_by?(users(:kevin))
|
||||
end
|
||||
|
||||
test "destroy" do
|
||||
assert_changes -> { cards(:shipping).pinned_by?(users(:kevin)) }, from: true, to: false do
|
||||
perform_enqueued_jobs do
|
||||
@@ -28,4 +39,15 @@ class Cards::PinsControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "destroy as JSON" do
|
||||
card = cards(:shipping)
|
||||
|
||||
assert card.pinned_by?(users(:kevin))
|
||||
|
||||
delete card_pin_path(card), as: :json
|
||||
|
||||
assert_response :no_content
|
||||
assert_not card.reload.pinned_by?(users(:kevin))
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user