Skip to content

Commit

Permalink
Merge pull request #1087 from richardboehme/rb/update-current-event
Browse files Browse the repository at this point in the history
Use next event as the "current" event
  • Loading branch information
salzig authored Jan 26, 2025
2 parents 64d19ee + 403ffe3 commit a6f1bd2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
6 changes: 3 additions & 3 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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..(Time.now + 9.weeks)).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
Expand Down
2 changes: 1 addition & 1 deletion app/models/highlight.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions spec/models/event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit a6f1bd2

Please sign in to comment.