From 0b435e6567e5a895413033dc3e3ee1216c2ba4cf Mon Sep 17 00:00:00 2001 From: Siddhant Bajaj Date: Sat, 11 Mar 2017 01:14:07 +0530 Subject: [PATCH] Added a validation on created at attribute of Registration model --- app/models/registration.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/models/registration.rb b/app/models/registration.rb index 33507ec1..bc5b51b0 100644 --- a/app/models/registration.rb +++ b/app/models/registration.rb @@ -27,6 +27,7 @@ class Registration < ActiveRecord::Base validates_uniqueness_of :user_id, scope: :conference_id, message: 'already Registered!' validate :registration_limit_not_exceed, on: :create validate :registration_to_events_only_if_present + validate :before_end_of_registration_period, on: :create after_create :set_week, :subscribe_to_conference, :send_registration_mail @@ -59,6 +60,12 @@ class Registration < ActiveRecord::Base end end + def before_end_of_registration_period + if conference && conference.registration_period && conference.registration_period.end_date && (Date.today > conference.registration_period.end_date) + errors.add(:created_at, "can't be after the registration period end date!") + end + end + def subscribe_to_conference Subscription.create(conference_id: conference.id, user_id: user.id) end