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

Show today’s workshop(s) as upcoming #1916

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
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