EventSchedule validations

event, schedule, room and start_time are mandatory in EventSchedule.
This commit is contained in:
Ana 2016-07-26 16:20:31 +02:00
parent 354e15a76d
commit 0b26ed5c35
10 changed files with 26 additions and 15 deletions

View file

@ -75,7 +75,7 @@ class Event < ActiveRecord::Base
# ====Returns
# * +true+ or +false+
def scheduled?
selected_event_schedule.try(:start_time).present? && selected_event_schedule.try(:room).present?
selected_event_schedule.present?
end
##
@ -84,7 +84,7 @@ class Event < ActiveRecord::Base
# ====Returns
# * +true+ or +false+
def unscheduled?(schedule_id)
state == 'confirmed' && (!event_schedule(schedule_id).try(:start_time).present? || !event_schedule(schedule_id).try(:room).present?)
state == 'confirmed' && !event_schedule(schedule_id).present?
end
def registration_possible?

View file

@ -3,13 +3,16 @@ class EventSchedule < ActiveRecord::Base
belongs_to :event
belongs_to :room
validates :schedule, presence: true
validates :event, presence: true
validates :room, presence: true
validates :start_time, presence: true
scope :confirmed, -> { joins(:event).where('state = ?', 'confirmed') }
scope :canceled, -> { joins(:event).where('state = ?', 'canceled') }
scope :withdrawn, -> { joins(:event).where('state = ?', 'withdrawn') }
def room_guid
room.try(:guid)
end
delegate :guid, to: :room, prefix: true
##
# Returns end of the event

View file

@ -28,7 +28,7 @@ class Program < ActiveRecord::Base
end
def scheduled(schedule_id)
joins(:event_schedules).where('event_schedules.schedule_id = ? AND event_schedules.start_time IS NOT NULL AND event_schedules.room_id IS NOT NULL', schedule_id)
joins(:event_schedules).where('event_schedules.schedule_id = ?', schedule_id)
end
def unscheduled(schedule_id)