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

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