From 0788925c1bb756802ad225b2c1ea386329db7afb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Sun, 23 Jun 2019 00:46:28 +0200 Subject: [PATCH] Apply `Rails/Validation` rubocop rule --- .rubocop.yml | 3 --- .rubocop_basic.yml | 3 +++ app/models/budget/content_block.rb | 3 +-- app/models/newsletter.rb | 4 +--- app/models/votation_type.rb | 9 +++------ 5 files changed, 8 insertions(+), 14 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 5e563232c..a64b6f7d0 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -165,9 +165,6 @@ Rails/SkipsModelValidations: Rails/UniqBeforePluck: Enabled: true -Rails/Validation: - Enabled: true - RSpec/AlignLeftLetBrace: Enabled: false diff --git a/.rubocop_basic.yml b/.rubocop_basic.yml index 865a6c76f..127a6dca8 100644 --- a/.rubocop_basic.yml +++ b/.rubocop_basic.yml @@ -157,6 +157,9 @@ Rails/UnknownEnv: - preproduction - staging +Rails/Validation: + Enabled: true + RSpec/NotToNot: Enabled: true diff --git a/app/models/budget/content_block.rb b/app/models/budget/content_block.rb index ae3bf44e9..06de2bd19 100644 --- a/app/models/budget/content_block.rb +++ b/app/models/budget/content_block.rb @@ -1,8 +1,7 @@ class Budget class ContentBlock < ApplicationRecord validates :locale, presence: true, inclusion: { in: I18n.available_locales.map(&:to_s) } - validates :heading, presence: true - validates_uniqueness_of :heading, scope: :locale + validates :heading, presence: true, uniqueness: { scope: :locale } belongs_to :heading end diff --git a/app/models/newsletter.rb b/app/models/newsletter.rb index df088ce8e..e6fcf7720 100644 --- a/app/models/newsletter.rb +++ b/app/models/newsletter.rb @@ -3,12 +3,10 @@ class Newsletter < ApplicationRecord validates :subject, presence: true validates :segment_recipient, presence: true - validates :from, presence: true + validates :from, presence: true, format: { with: /@/ } validates :body, presence: true validate :validate_segment_recipient - validates_format_of :from, :with => /@/ - acts_as_paranoid column: :hidden_at include ActsAsParanoidAliases diff --git a/app/models/votation_type.rb b/app/models/votation_type.rb index c518408f7..891ba250e 100644 --- a/app/models/votation_type.rb +++ b/app/models/votation_type.rb @@ -30,12 +30,9 @@ class VotationType < ApplicationRecord validates :questionable, presence: true validates :questionable_type, inclusion: { in: QUESTIONABLE_TYPES } - validates_presence_of :max_votes, allow_blank: false, - if: :max_votes_required? - validates_presence_of :max_groups_answers, allow_blank: false, - if: :max_groups_answers_required? - validates_presence_of :prioritization_type, allow_blank: false, - if: :prioritization_type_required? + validates :max_votes, presence: { allow_blank: false, if: :max_votes_required? } + validates :max_groups_answers, presence: { allow_blank: false, if: :max_groups_answers_required? } + validates :prioritization_type, presence: { allow_blank: false, if: :prioritization_type_required? } after_create :add_skip_question_answer, if: :display_skip_question?