Change Cfp scopes to class methods

When no record matches the requested criteria a scope will return all
the records
In this case, if no record can be found we want the result to be nil

Also, make some readability fixes in specs
This commit is contained in:
AEtherC0r3 2017-07-16 20:29:03 +03:00 committed by Stella Rouzi
parent d9faffc96a
commit f9903eba16
5 changed files with 59 additions and 30 deletions

View file

@ -3,9 +3,6 @@
class Cfp < ActiveRecord::Base
TYPES = %w(events booths tracks).freeze
scope :for_events, (-> { find_by(cfp_type: 'events') })
scope :for_tracks, (-> { find_by(cfp_type: 'tracks') })
has_paper_trail ignore: [:updated_at], meta: { conference_id: :conference_id }
belongs_to :program
@ -79,6 +76,24 @@ class Cfp < ActiveRecord::Base
(start_date..end_date).cover?(Date.current)
end
##
# Finds the cfp for events if it exists
#
# ====Returns
# * +Cfp+ -> The cfp with type 'events'
def self.for_events
find_by(cfp_type: 'events')
end
##
# Finds the cfp for tracks if it exists
#
# ====Returns
# * +Cfp+ -> The cfp with type 'tracks'
def self.for_tracks
find_by(cfp_type: 'tracks')
end
private
def before_end_of_conference