Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use next event as the "current" event #1087

Merged
merged 2 commits into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading