Add command to tag cards

This commit is contained in:
Jorge Manrubia
2025-05-07 16:48:33 +02:00
parent 31d0271952
commit b7f086d361
6 changed files with 111 additions and 17 deletions
+1 -1
View File
@@ -7,7 +7,7 @@ class Command::FilterByCardTest < ActionDispatch::IntegrationTest
@tag = tags(:web)
end
test "redirects to the cards index filtering by cards" do
test "redirect to the cards index filtering by cards" do
result = execute_command "##{@tag.title}"
assert_equal cards_path(indexed_by: "newest", tag_ids: [ @tag.id ]), result.url
+47
View File
@@ -0,0 +1,47 @@
require "test_helper"
class Command::TagTest < ActionDispatch::IntegrationTest
include CommandTestHelper
setup do
Current.session = sessions(:david)
@card = cards(:text)
@tag = tags(:web)
end
test "tag card on perma with existing tag" do
assert_changes -> { @card.tagged_with?(@tag) }, from: false, to: true do
execute_command "/tag #{@tag.title}", context_url: collection_card_url(@card.collection, @card)
end
end
test "tag card on perma with new card" do
assert_difference -> { @card.tags.count }, +1 do
execute_command "/tag some-new-tag", context_url: collection_card_url(@card.collection, @card)
end
assert_equal "some-new-tag", @card.tags.last.title
end
test "tag several cards on cards' index page" do
cards = cards(:logo, :text, :layout)
cards.each { it.taggings.destroy_all }
execute_command "/tag #{@tag.title}", context_url: collection_cards_url(@card.collection)
cards.each { assert it.reload.tagged_with?(@tag) }
end
test "undo tagged cards" do
cards = cards(:logo, :text, :layout)
cards.each { it.taggings.destroy_all }
command = parse_command "/tag #{@tag.title}", context_url: collection_cards_url(@card.collection)
command.execute
cards.each { assert it.reload.tagged_with?(@tag) }
command.undo
cards.each { assert_not it.reload.tagged_with?(@tag) }
end
end