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:
parent
7fd738bc7d
commit
c3eb178546
8 changed files with 120 additions and 5 deletions
|
|
@ -1,6 +1,10 @@
|
|||
# cannot delete program if there are events submitted
|
||||
|
||||
class Cfp < ActiveRecord::Base
|
||||
TYPES = %w(events).freeze
|
||||
|
||||
scope :for_events, (-> { find_by(cfp_type: 'events') })
|
||||
|
||||
has_paper_trail ignore: [:updated_at], meta: { conference_id: :conference_id }
|
||||
belongs_to :program
|
||||
|
||||
|
|
@ -8,6 +12,15 @@ class Cfp < ActiveRecord::Base
|
|||
validates :start_date, :end_date, presence: true
|
||||
validate :before_end_of_conference
|
||||
validate :start_after_end_date
|
||||
validates :cfp_type,
|
||||
presence: true,
|
||||
inclusion: {
|
||||
in: TYPES
|
||||
},
|
||||
uniqueness: {
|
||||
scope: :program,
|
||||
case_sensitive: false
|
||||
}
|
||||
|
||||
##
|
||||
# Checks whether cfp date is updated
|
||||
|
|
@ -55,6 +68,16 @@ class Cfp < ActiveRecord::Base
|
|||
result > 0 ? result : 0
|
||||
end
|
||||
|
||||
##
|
||||
# Checks if the call for papers is currently open
|
||||
#
|
||||
# ====Returns
|
||||
# * +false+ -> If the CFP is not set or today isn't in the CFP period.
|
||||
# * +true+ -> If today is in the CFP period.
|
||||
def open?
|
||||
(start_date..end_date).cover?(Date.current)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def before_end_of_conference
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
##
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue