Skip to content

Commit a6f1bd2

Browse files
authored
Merge pull request #1087 from richardboehme/rb/update-current-event
Use next event as the "current" event
2 parents 64d19ee + 403ffe3 commit a6f1bd2

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

app/models/event.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ class Event < ApplicationRecord
2222
default_scope -> { where(label: Whitelabel[:label_id]) }
2323

2424
scope :with_topics, -> { joins(:topics).distinct }
25-
scope :current, -> { where(date: Date.today.to_time..(Time.now + 9.weeks)).limit(1).order('date ASC') }
26-
scope :latest, -> { where('date < ?', Date.today.to_time).order('date DESC') }
25+
scope :current, -> { where(date: Date.today.to_time..).limit(1).order(date: :asc) }
26+
scope :latest, -> { where('date < ?', Date.today.to_time).order(date: :desc) }
2727
scope :unpublished, -> { where('published IS NULL') }
28-
scope :ordered, -> { order('date DESC') }
28+
scope :ordered, -> { order(date: :desc) }
2929

3030
def end_date
3131
date + 2.hours

app/models/highlight.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class Highlight < ApplicationRecord
55

66
default_scope -> { where(label: Whitelabel[:label_id]) }
77

8-
scope :active, -> { where('end_at > ?', Time.now).order('start_at').limit(1) }
8+
scope :active, -> { where('end_at > ?', Time.now).order(start_at: :asc).limit(1) }
99

1010
def disabled?
1111
end_at <= Time.now

spec/models/event_spec.rb

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
it 'finds a current event' do
2525
event_next = create(:event, date: 2.days.from_now)
2626
expect(Event.current.first).to eql(event_next)
27+
event_next.update(date: 5.months.from_now)
28+
expect(Event.current.first).to eql(event_next)
2729
end
2830
end
2931

0 commit comments

Comments
 (0)