From 37bf992d67131a0accd3a87ffd31fdb9922e25be Mon Sep 17 00:00:00 2001 From: Jorge Manrubia Date: Tue, 6 May 2025 15:17:57 +0200 Subject: [PATCH] Add controller tests for undo --- .../commands/undos_controller_test.rb | 19 +++++++++++++++++++ test/fixtures/commands.yml | 10 ++++++++++ 2 files changed, 29 insertions(+) create mode 100644 test/controllers/commands/undos_controller_test.rb create mode 100644 test/fixtures/commands.yml diff --git a/test/controllers/commands/undos_controller_test.rb b/test/controllers/commands/undos_controller_test.rb new file mode 100644 index 000000000..c3caee1be --- /dev/null +++ b/test/controllers/commands/undos_controller_test.rb @@ -0,0 +1,19 @@ +require "test_helper" + +class UndosControllerTest < ActionDispatch::IntegrationTest + setup do + sign_in_as :jz + end + + test "undo and destroy a command" do + assert_includes cards(:logo).reload.assignees, users(:jz) + + assert_difference -> { users(:jz).commands.reload.count }, -1 do + post command_undo_path(commands(:logo_assign_to_jz_command)), headers: { "HTTP_REFERER" => cards_path } + end + + assert_not_includes cards(:logo).reload.assignees, users(:jz) + + assert_redirected_to cards_path + end +end diff --git a/test/fixtures/commands.yml b/test/fixtures/commands.yml new file mode 100644 index 000000000..ff85c644a --- /dev/null +++ b/test/fixtures/commands.yml @@ -0,0 +1,10 @@ +logo_assign_to_jz_command: + user: jz + type: Command::Assign + data: <%= { + card_ids: [ ActiveRecord::FixtureSet.identify(:logo) ], + assignee_ids: [ ActiveRecord::FixtureSet.identify(:jz) ], + toggled_assignees_by_card: { + ActiveRecord::FixtureSet.identify(:logo) => [ ActiveRecord::FixtureSet.identify(:jz) ] + } + }.to_json %>