Add and apply Style/CollectionQuerying rubocop rule
This rule was added in rubocop 1.77. We were following it most of the time. It makes the code more readable in my humble opinion.
This commit is contained in:
@@ -747,6 +747,9 @@ Style/ClassVars:
|
|||||||
Style/CollectionMethods:
|
Style/CollectionMethods:
|
||||||
Enabled: true
|
Enabled: true
|
||||||
|
|
||||||
|
Style/CollectionQuerying:
|
||||||
|
Enabled: true
|
||||||
|
|
||||||
Style/ComparableBetween:
|
Style/ComparableBetween:
|
||||||
Enabled: true
|
Enabled: true
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ class Layout::NotificationItemComponent < ApplicationComponent
|
|||||||
end
|
end
|
||||||
|
|
||||||
def notifications_class
|
def notifications_class
|
||||||
if unread_notifications.count > 0
|
if unread_notifications.any?
|
||||||
"unread-notifications"
|
"unread-notifications"
|
||||||
else
|
else
|
||||||
"no-notifications"
|
"no-notifications"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
module DebatesHelper
|
module DebatesHelper
|
||||||
def has_featured?
|
def has_featured?
|
||||||
Debate.all.featured.count > 0
|
Debate.all.featured.any?
|
||||||
end
|
end
|
||||||
|
|
||||||
def empty_recommended_debates_message_text(user)
|
def empty_recommended_debates_message_text(user)
|
||||||
|
|||||||
@@ -6,11 +6,11 @@ class PollOptionFinder
|
|||||||
end
|
end
|
||||||
|
|
||||||
def manageable_choices
|
def manageable_choices
|
||||||
choices_map.select { |choice, ids| ids.count == 1 }
|
choices_map.select { |choice, ids| ids.one? }
|
||||||
end
|
end
|
||||||
|
|
||||||
def unmanageable_choices
|
def unmanageable_choices
|
||||||
choices_map.reject { |choice, ids| ids.count == 1 }
|
choices_map.reject { |choice, ids| ids.one? }
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ class Budget
|
|||||||
end
|
end
|
||||||
|
|
||||||
def has_lines_with_no_heading?
|
def has_lines_with_no_heading?
|
||||||
investments.no_heading.count > 0
|
investments.no_heading.any?
|
||||||
end
|
end
|
||||||
|
|
||||||
def has_lines_with_heading?
|
def has_lines_with_heading?
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ module Globalizable
|
|||||||
length: options[:length],
|
length: options[:length],
|
||||||
if: lambda { |translation| translation.locale == Setting.default_locale }
|
if: lambda { |translation| translation.locale == Setting.default_locale }
|
||||||
end
|
end
|
||||||
if options.count > 1
|
if options.many?
|
||||||
translation_class.instance_eval do
|
translation_class.instance_eval do
|
||||||
validates method, options.reject { |key| key == :length }
|
validates method, options.reject { |key| key == :length }
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ class Verification::Management::Email
|
|||||||
private
|
private
|
||||||
|
|
||||||
def validate_user
|
def validate_user
|
||||||
return if errors.count > 0
|
return if errors.any?
|
||||||
|
|
||||||
if !user?
|
if !user?
|
||||||
errors.add(:email, I18n.t("errors.messages.user_not_found"))
|
errors.add(:email, I18n.t("errors.messages.user_not_found"))
|
||||||
@@ -52,7 +52,7 @@ class Verification::Management::Email
|
|||||||
end
|
end
|
||||||
|
|
||||||
def validate_document_number
|
def validate_document_number
|
||||||
return if errors.count > 0
|
return if errors.any?
|
||||||
|
|
||||||
if document_number_mismatch?
|
if document_number_mismatch?
|
||||||
errors.add(
|
errors.add(
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Default admin user (change password after first deploy to a server!)
|
# Default admin user (change password after first deploy to a server!)
|
||||||
if Administrator.count == 0 && (!Rails.env.test? || !Tenant.default?)
|
if Administrator.none? && (!Rails.env.test? || !Tenant.default?)
|
||||||
admin = User.create!(username: "admin", email: "admin@consul.dev", password: "12345678",
|
admin = User.create!(username: "admin", email: "admin@consul.dev", password: "12345678",
|
||||||
password_confirmation: "12345678", confirmed_at: Time.current,
|
password_confirmation: "12345678", confirmed_at: Time.current,
|
||||||
terms_of_service: "1")
|
terms_of_service: "1")
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ namespace :polls do
|
|||||||
option_finder.unmanageable_choices.each do |choice, ids|
|
option_finder.unmanageable_choices.each do |choice, ids|
|
||||||
tenant_info = " on tenant #{Tenant.current_schema}" unless Tenant.default?
|
tenant_info = " on tenant #{Tenant.current_schema}" unless Tenant.default?
|
||||||
|
|
||||||
if ids.count == 0
|
if ids.none?
|
||||||
logger.warn "Skipping poll_answers with the text \"#{choice}\" for the poll_question " \
|
logger.warn "Skipping poll_answers with the text \"#{choice}\" for the poll_question " \
|
||||||
"with ID #{question.id}. This question has no poll_question_answers " \
|
"with ID #{question.id}. This question has no poll_question_answers " \
|
||||||
"containing the text \"#{choice}\"" + tenant_info.to_s
|
"containing the text \"#{choice}\"" + tenant_info.to_s
|
||||||
@@ -185,7 +185,7 @@ namespace :polls do
|
|||||||
option_finder.unmanageable_choices.each do |choice, ids|
|
option_finder.unmanageable_choices.each do |choice, ids|
|
||||||
tenant_info = " on tenant #{Tenant.current_schema}" unless Tenant.default?
|
tenant_info = " on tenant #{Tenant.current_schema}" unless Tenant.default?
|
||||||
|
|
||||||
if ids.count == 0
|
if ids.none?
|
||||||
logger.warn "Skipping poll_partial_results with the text \"#{choice}\" for the poll_question " \
|
logger.warn "Skipping poll_partial_results with the text \"#{choice}\" for the poll_question " \
|
||||||
"with ID #{question.id}. This question has no poll_question_answers " \
|
"with ID #{question.id}. This question has no poll_question_answers " \
|
||||||
"containing the text \"#{choice}\"" + tenant_info.to_s
|
"containing the text \"#{choice}\"" + tenant_info.to_s
|
||||||
|
|||||||
Reference in New Issue
Block a user