Modify CFP to accept proposals for other things

Add field cfp_type and relevant validations
Add Program#cfp to preserve backwards compatibility
Add 'for_events' scope to the cfp, in order for it to be used like
program.cfps.events
Add useful methods
Add rspec test for the new code
The supported cfp types can be viewed via Cfp::TYPES
This commit is contained in:
AEtherC0r3 2017-05-30 20:54:48 +03:00 committed by Stella Rouzi
parent 7fd738bc7d
commit c3eb178546
8 changed files with 120 additions and 5 deletions

View file

@ -5,7 +5,7 @@ class Program < ActiveRecord::Base
belongs_to :conference
has_one :cfp, dependent: :destroy
has_many :cfps, dependent: :destroy
has_many :event_types, dependent: :destroy
has_many :tracks, dependent: :destroy
has_many :difficulty_levels, dependent: :destroy
@ -135,7 +135,7 @@ class Program < ActiveRecord::Base
# * +false+ -> If the CFP is not set or today isn't in the CFP period.
# * +true+ -> If today is in the CFP period.
def cfp_open?
cfp = self.cfp
cfp = cfps.events
cfp.present? && (cfp.start_date..cfp.end_date).cover?(Date.current)
end
@ -163,6 +163,23 @@ class Program < ActiveRecord::Base
EventSchedule.where(schedule: selected_schedule).where(start_time: parsed_date..(parsed_date + 1)).any?
end
##
# Provides backwards compatibility for when the program had one cfp
#
# ====Returns
# * +ActiveRecord+ -> The program's cfp with cfp_type == 'events'
def cfp
return nil if cfps.for_events.blank?
cfps.for_events
end
##
# ====Returns
# * +Array+ -> The types of cfps for which a cfp doesn't exist yet
def remaining_cfp_types
Cfp::TYPES - cfps.pluck(:cfp_type)
end
private
##