Skip to content

Commit

Permalink
Merge pull request #1916 from gnclmorais/show-todays-workshop-on-chap…
Browse files Browse the repository at this point in the history
…ter-admin

Show today’s workshop(s) as upcoming
  • Loading branch information
KimberleyCook authored Sep 4, 2023
2 parents 8f0c689 + 6a03c08 commit 4b79b5e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/controllers/admin/chapters_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def create
def show
authorize(@chapter)

@workshops = @chapter.workshops.upcoming
@workshops = @chapter.workshops.today_and_upcoming
@sponsors = @chapter.sponsors.uniq
@groups = @chapter.groups
@subscribers = @chapter.subscriptions.last(20).reverse
Expand Down
1 change: 1 addition & 0 deletions app/models/concerns/listable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module Listable
extend ActiveSupport::Concern

included do
scope :today_and_upcoming, -> { where('date_and_time >= ?', Time.zone.today).order(date_and_time: :asc) }
scope :upcoming, -> { where('date_and_time >= ?', Time.zone.now).order(date_and_time: :asc) }
scope :past, -> { where('date_and_time < ?', Time.zone.now).order(:date_and_time) }
scope :recent, lambda {
Expand Down
13 changes: 13 additions & 0 deletions spec/models/concerns/listable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@
subject(:workshop) { Fabricate(:workshop) }

context 'scopes' do
context '#today_and_upcoming' do
it 'returns a list of all today and upcoming workshops' do
Fabricate.times(5, :past_workshop)
future_workshops = Fabricate.times(3, :workshop)

# Make sure one is not technically upcoming but is happening now
future_workshops.last.date_and_time = 1.hour.ago
future_workshops.last.save

expect(Workshop.today_and_upcoming).to match_array(future_workshops)
end
end

context '#upcoming' do
it 'returns a list of all upcoming workshops' do
Fabricate.times(5, :past_workshop)
Expand Down

0 comments on commit 4b79b5e

Please sign in to comment.