From 8fcef406259c7e4d04c91d6859a6c6b4ef104915 Mon Sep 17 00:00:00 2001 From: Rachael Wright-Munn Date: Tue, 21 May 2024 19:11:21 +0000 Subject: [PATCH] Minor Refactor - Validation helpers on Event (#225) * Updating to use two validation helpers so I can screenshot it for my talk. * Turn off Rails/Validation which doesn't like validation helpers. They don't include comparison. :( https://docs.rubocop.org/rubocop-rails/cops_rails.html#railsvalidation --- .rubocop.yml | 3 +++ app/models/event.rb | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.rubocop.yml b/.rubocop.yml index 0b3a113..5f376d2 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -50,6 +50,9 @@ Naming/BlockForwarding: Rails/RequestReferer: EnforcedStyle: referrer +Rails/Validation: + Enabled: false + RSpec/ExampleLength: Max: 10 diff --git a/app/models/event.rb b/app/models/event.rb index d47527c..a8eeec6 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -7,7 +7,7 @@ class Event < ApplicationRecord has_many :event_attendees, dependent: :delete_all has_many :attendees, through: :event_attendees, source: :profile - validates :start_at, :end_at, presence: true + validates_presence_of :start_at, :end_at validates_comparison_of :end_at, greater_than: :start_at scope :ongoing_or_upcoming, -> { where("end_at >= ?", Time.zone.now) }