This commit is contained in:
Eugene 2017-03-10 16:41:42 +00:00 committed by GitHub
commit 92abf4b2ff
8 changed files with 283 additions and 5 deletions

View file

@ -1,4 +1,8 @@
class Event < ActiveRecord::Base
attr_accessor :submitter_id
attr_accessor :speaker_id
attr_accessor :validate_owners
include ActiveRecord::Transitions
has_paper_trail on: [:create, :update], ignore: [:updated_at, :guid, :week], meta: { conference_id: :conference_id }
@ -37,6 +41,8 @@ class Event < ActiveRecord::Base
validate :max_attendees_no_more_than_room_size
validate :submitter_and_speaker_present
scope :confirmed, -> { where(state: 'confirmed') }
scope :canceled, -> { where(state: 'canceled') }
scope :withdrawn, -> { where(state: 'withdrawn') }
@ -294,4 +300,18 @@ class Event < ActiveRecord::Base
def conference_id
program.conference_id
end
def submitter_and_speaker_present
if validate_owners
errors.add(:speaker_id, "can't be blank!") unless self.speaker_id.present?
if self.speaker_id.present?
errors.add(:speaker_id, 'user should exist!') unless User.where(id: self.speaker_id).take
end
errors.add(:submitter_id, "can't be blank!") unless self.submitter_id.present?
if self.submitter_id.present?
errors.add(:submitter_id, 'user should exist!') unless User.where(id: self.submitter_id).take
end
end
end
end