From 67f54c4e75aeaa78ba72e10603b43a713929fcbd Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 23 Jan 2024 04:06:53 -0500 Subject: [PATCH] Fix `Rails/WhereExists` cop in app/validators (#28854) --- .rubocop_todo.yml | 2 -- app/validators/reaction_validator.rb | 2 +- app/validators/vote_validator.rb | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index a2ee32d284..4d2f11ff7b 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -88,8 +88,6 @@ Rails/WhereExists: - 'app/serializers/rest/announcement_serializer.rb' - 'app/services/activitypub/fetch_remote_status_service.rb' - 'app/services/vote_service.rb' - - 'app/validators/reaction_validator.rb' - - 'app/validators/vote_validator.rb' - 'app/workers/move_worker.rb' - 'lib/tasks/tests.rake' - 'spec/models/account_spec.rb' diff --git a/app/validators/reaction_validator.rb b/app/validators/reaction_validator.rb index 4ed3376e8b..89d83de5a2 100644 --- a/app/validators/reaction_validator.rb +++ b/app/validators/reaction_validator.rb @@ -19,7 +19,7 @@ class ReactionValidator < ActiveModel::Validator end def new_reaction?(reaction) - !reaction.announcement.announcement_reactions.where(name: reaction.name).exists? + !reaction.announcement.announcement_reactions.exists?(name: reaction.name) end def limit_reached?(reaction) diff --git a/app/validators/vote_validator.rb b/app/validators/vote_validator.rb index fa2bd223dc..e725b4c0b8 100644 --- a/app/validators/vote_validator.rb +++ b/app/validators/vote_validator.rb @@ -35,7 +35,7 @@ class VoteValidator < ActiveModel::Validator if vote.persisted? account_votes_on_same_poll(vote).where(choice: vote.choice).where.not(poll_votes: { id: vote }).exists? else - account_votes_on_same_poll(vote).where(choice: vote.choice).exists? + account_votes_on_same_poll(vote).exists?(choice: vote.choice) end end