diff --git a/.rubocop.yml b/.rubocop.yml index 74d2640d8..eef2a9d38 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -325,6 +325,9 @@ Rails/UnknownEnv: Rails/Validation: Enabled: true +Rails/WhereNot: + Enabled: true + RSpec/AroundBlock: Enabled: true diff --git a/app/models/debate.rb b/app/models/debate.rb index 47a78f360..7366249c6 100644 --- a/app/models/debate.rb +++ b/app/models/debate.rb @@ -45,7 +45,7 @@ class Debate < ApplicationRecord scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) } scope :sort_by_recommendations, -> { order(cached_votes_total: :desc) } scope :last_week, -> { where("created_at >= ?", 7.days.ago) } - scope :featured, -> { where("featured_at is not null") } + scope :featured, -> { where.not(featured_at: nil) } scope :public_for_api, -> { all } # Ahoy setup @@ -58,8 +58,7 @@ class Debate < ApplicationRecord end def self.recommendations(user) - tagged_with(user.interests, any: true) - .where("author_id != ?", user.id) + tagged_with(user.interests, any: true).where.not(author_id: user.id) end def searchable_translations_definitions diff --git a/app/models/milestone.rb b/app/models/milestone.rb index 8401a3a86..0498d24c4 100644 --- a/app/models/milestone.rb +++ b/app/models/milestone.rb @@ -15,7 +15,7 @@ class Milestone < ApplicationRecord scope :order_by_publication_date, -> { order(publication_date: :asc, created_at: :asc) } scope :published, -> { where("publication_date <= ?", Date.current.end_of_day) } - scope :with_status, -> { where("status_id IS NOT NULL") } + scope :with_status, -> { where.not(status_id: nil) } def self.title_max_length 80 diff --git a/app/models/poll.rb b/app/models/poll.rb index 08e11f854..de8b56187 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -122,7 +122,7 @@ class Poll < ApplicationRecord end def self.not_voted_by(user) - where("polls.id not in (?)", poll_ids_voted_by(user)) + where.not(id: poll_ids_voted_by(user)) end def self.poll_ids_voted_by(user) diff --git a/app/models/proposal.rb b/app/models/proposal.rb index 18109bbaa..643c51de5 100644 --- a/app/models/proposal.rb +++ b/app/models/proposal.rb @@ -106,7 +106,7 @@ class Proposal < ApplicationRecord def self.recommendations(user) tagged_with(user.interests, any: true) - .where("author_id != ?", user.id) + .where.not(author_id: user.id) .unsuccessful .not_followed_by_user(user) .not_archived diff --git a/app/models/verification/management/managed_user.rb b/app/models/verification/management/managed_user.rb index 45ed1bbab..babf18f58 100644 --- a/app/models/verification/management/managed_user.rb +++ b/app/models/verification/management/managed_user.rb @@ -2,7 +2,7 @@ class Verification::Management::ManagedUser include ActiveModel::Model def self.find(document_type, document_number) - User.where("document_number is not null"). + User.where.not(document_number: nil). find_or_initialize_by(document_type: document_type, document_number: document_number) end diff --git a/db/dev_seeds/flags.rb b/db/dev_seeds/flags.rb index ebddb901a..a31c0e550 100644 --- a/db/dev_seeds/flags.rb +++ b/db/dev_seeds/flags.rb @@ -1,19 +1,19 @@ section "Flagging Debates & Comments" do 40.times do debate = Debate.all.sample - flagger = User.where(["users.id <> ?", debate.author_id]).all.sample + flagger = User.where.not(id: debate.author_id).all.sample Flag.flag(flagger, debate) end 40.times do comment = Comment.all.sample - flagger = User.where(["users.id <> ?", comment.user_id]).all.sample + flagger = User.where.not(id: comment.user_id).all.sample Flag.flag(flagger, comment) end 40.times do proposal = Proposal.all.sample - flagger = User.where(["users.id <> ?", proposal.author_id]).all.sample + flagger = User.where.not(id: proposal.author_id).all.sample Flag.flag(flagger, proposal) end end