From 4a30663df10e33940766349482fb30ea09c89c75 Mon Sep 17 00:00:00 2001 From: Jorge Manrubia Date: Wed, 3 Dec 2025 23:37:52 +0100 Subject: [PATCH] Scope tags by account We missed this one when we went to MySQL. This can results in cards tagged with cards from other accounts. No data leaked though: the symptom is that you see the card tagged as expected but you don't see the tag in the menu. --- app/models/card/taggable.rb | 2 +- test/models/card/taggable_test.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/models/card/taggable.rb b/app/models/card/taggable.rb index 5ad75a593..73c89d0b6 100644 --- a/app/models/card/taggable.rb +++ b/app/models/card/taggable.rb @@ -9,7 +9,7 @@ module Card::Taggable end def toggle_tag_with(title) - tag = Tag.find_or_create_by!(title: title) + tag = account.tags.find_or_create_by!(title: title) transaction do if tagged_with?(tag) diff --git a/test/models/card/taggable_test.rb b/test/models/card/taggable_test.rb index 5d054af14..4aadde46f 100644 --- a/test/models/card/taggable_test.rb +++ b/test/models/card/taggable_test.rb @@ -16,4 +16,13 @@ class Card::TaggableTest < ActiveSupport::TestCase @card.toggle_tag_with "ruby" end end + + test "scope tags by account" do + assert_difference -> { Tag.count }, 2 do + cards(:logo).toggle_tag_with "ruby" + cards(:paycheck).toggle_tag_with "ruby" + end + + assert_not_equal cards(:logo).tags.last, cards(:paycheck).tags.last + end end