From b8a42e9adabafdf2a723614362e11452ce528000 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20B=C3=B6hme?= Date: Tue, 3 Dec 2024 15:30:44 +0100 Subject: [PATCH 1/2] Use next event as the "current" event This change removes the restriction of the current event to be at most 9 weeks in the future. Some user groups might decide to hold meetups less frequently so this limitation prevents them from advertising their next event until 9 weeks before the meetup. With this change the current event that is displayed on the homepage will always be the next event, even if it's set far in the future. Closes #1084 --- app/models/event.rb | 2 +- spec/models/event_spec.rb | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/models/event.rb b/app/models/event.rb index aee5cf754..19ffa8280 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -22,7 +22,7 @@ class Event < ApplicationRecord default_scope -> { where(label: Whitelabel[:label_id]) } scope :with_topics, -> { joins(:topics).distinct } - scope :current, -> { where(date: Date.today.to_time..(Time.now + 9.weeks)).limit(1).order('date ASC') } + scope :current, -> { where(date: Date.today.to_time..).limit(1).order('date ASC') } scope :latest, -> { where('date < ?', Date.today.to_time).order('date DESC') } scope :unpublished, -> { where('published IS NULL') } scope :ordered, -> { order('date DESC') } diff --git a/spec/models/event_spec.rb b/spec/models/event_spec.rb index 74dff5bc8..11d3aa7f1 100644 --- a/spec/models/event_spec.rb +++ b/spec/models/event_spec.rb @@ -24,6 +24,8 @@ it 'finds a current event' do event_next = create(:event, date: 2.days.from_now) expect(Event.current.first).to eql(event_next) + event_next.update(date: 5.months.from_now) + expect(Event.current.first).to eql(event_next) end end From 403ffe31104b12dec8d091610bbe7564ac12820a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20B=C3=B6hme?= Date: Tue, 3 Dec 2024 17:14:54 +0100 Subject: [PATCH 2/2] Use AR's symbol syntax for ordering relations --- app/models/event.rb | 6 +++--- app/models/highlight.rb | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/event.rb b/app/models/event.rb index 19ffa8280..20e200db9 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -22,10 +22,10 @@ class Event < ApplicationRecord default_scope -> { where(label: Whitelabel[:label_id]) } scope :with_topics, -> { joins(:topics).distinct } - scope :current, -> { where(date: Date.today.to_time..).limit(1).order('date ASC') } - scope :latest, -> { where('date < ?', Date.today.to_time).order('date DESC') } + scope :current, -> { where(date: Date.today.to_time..).limit(1).order(date: :asc) } + scope :latest, -> { where('date < ?', Date.today.to_time).order(date: :desc) } scope :unpublished, -> { where('published IS NULL') } - scope :ordered, -> { order('date DESC') } + scope :ordered, -> { order(date: :desc) } def end_date date + 2.hours diff --git a/app/models/highlight.rb b/app/models/highlight.rb index 814f90bb9..7471ca6f9 100644 --- a/app/models/highlight.rb +++ b/app/models/highlight.rb @@ -5,7 +5,7 @@ class Highlight < ApplicationRecord default_scope -> { where(label: Whitelabel[:label_id]) } - scope :active, -> { where('end_at > ?', Time.now).order('start_at').limit(1) } + scope :active, -> { where('end_at > ?', Time.now).order(start_at: :asc).limit(1) } def disabled? end_at <= Time.now