From da31792ac7768299d32419764bdc118adf7e1ea5 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Thu, 18 Jan 2024 07:22:12 -0500 Subject: [PATCH] Fix `Rails/WhereExists` cop in FeaturedTag model (#28791) --- .rubocop_todo.yml | 1 - app/models/featured_tag.rb | 6 +++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 73ad0cac0..eaa86ad15 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -82,7 +82,6 @@ Rails/WhereExists: - 'app/lib/feed_manager.rb' - 'app/lib/status_cache_hydrator.rb' - 'app/lib/suspicious_sign_in_detector.rb' - - 'app/models/featured_tag.rb' - 'app/models/poll.rb' - 'app/models/session_activation.rb' - 'app/models/status.rb' diff --git a/app/models/featured_tag.rb b/app/models/featured_tag.rb index 7c36aa8b0..63cd67476 100644 --- a/app/models/featured_tag.rb +++ b/app/models/featured_tag.rb @@ -66,6 +66,10 @@ class FeaturedTag < ApplicationRecord end def validate_tag_uniqueness - errors.add(:name, :taken) if FeaturedTag.by_name(name).where(account_id: account_id).exists? + errors.add(:name, :taken) if tag_already_featured_for_account? + end + + def tag_already_featured_for_account? + FeaturedTag.by_name(name).exists?(account_id: account_id) end end