From eb23d838b53ce0dc61e333206a2fa24b1eb80440 Mon Sep 17 00:00:00 2001 From: shlok007 Date: Tue, 11 Jul 2017 04:59:03 +0530 Subject: [PATCH] correct past and upcoming conferences in admin/organizations#index --- app/models/conference.rb | 2 ++ app/views/admin/organizations/index.html.haml | 4 ++-- spec/models/conference_spec.rb | 17 +++++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/app/models/conference.rb b/app/models/conference.rb index 69571dc9..68cdc186 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -7,6 +7,8 @@ class Conference < ActiveRecord::Base resourcify :roles, dependent: :delete_all default_scope { order('start_date DESC') } + scope :upcoming, (-> { where('end_date >= ?', Date.current) }) + scope :past, (-> { where('end_date < ?', Date.current) }) belongs_to :organization diff --git a/app/views/admin/organizations/index.html.haml b/app/views/admin/organizations/index.html.haml index 52e2877a..aa682c57 100644 --- a/app/views/admin/organizations/index.html.haml +++ b/app/views/admin/organizations/index.html.haml @@ -20,9 +20,9 @@ %td = organization.name %td - = organization.conferences.count + = organization.conferences.upcoming.count %td - = organization.conferences.count + = organization.conferences.past.count %td .btn-group = link_to 'Edit', edit_admin_organization_path(organization), diff --git a/spec/models/conference_spec.rb b/spec/models/conference_spec.rb index 89863412..91c06140 100755 --- a/spec/models/conference_spec.rb +++ b/spec/models/conference_spec.rb @@ -1687,4 +1687,21 @@ describe Conference do expect{ room.save }.to change { subject.revision }.by(1) end end + + describe '.upcoming' do + let!(:upcoming_conference) { create(:conference) } + let!(:past_conference) { create(:conference, start_date: Date.current - 1.days, end_date: Date.current - 1.days) } + subject { Conference.upcoming } + + it { is_expected.to eq [upcoming_conference] } + end + + describe '.past' do + let!(:upcoming_conference) { create(:conference) } + let!(:past_conference1) { create(:conference, start_date: Date.current - 1.days, end_date: Date.current - 1.days) } + let!(:past_conference2) { create(:conference, start_date: Date.current - 2.days, end_date: Date.current - 1.days) } + subject { Conference.past } + + it { is_expected.to eq [past_conference1, past_conference2] } + end end