diff --git a/app/models/ect_at_school_period.rb b/app/models/ect_at_school_period.rb index bd840d94..7ba35a49 100644 --- a/app/models/ect_at_school_period.rb +++ b/app/models/ect_at_school_period.rb @@ -11,6 +11,10 @@ class ECTAtSchoolPeriod < ApplicationRecord has_many :events # Validations + validates :email, + notify_email: true, + allow_nil: true + validates :started_on, presence: true diff --git a/app/models/mentor_at_school_period.rb b/app/models/mentor_at_school_period.rb index b751493b..22a9b446 100644 --- a/app/models/mentor_at_school_period.rb +++ b/app/models/mentor_at_school_period.rb @@ -9,6 +9,10 @@ class MentorAtSchoolPeriod < ApplicationRecord has_many :events # Validations + validates :email, + notify_email: true, + allow_nil: true + validates :started_on, presence: true diff --git a/spec/models/ect_at_school_period_spec.rb b/spec/models/ect_at_school_period_spec.rb index 19ba0c1a..e3ac715c 100644 --- a/spec/models/ect_at_school_period_spec.rb +++ b/spec/models/ect_at_school_period_spec.rb @@ -15,6 +15,12 @@ it { is_expected.to validate_presence_of(:school_id) } it { is_expected.to validate_presence_of(:teacher_id) } + context "email" do + it { is_expected.to allow_value(nil).for(:email) } + it { is_expected.to allow_value("test@example.com").for(:email) } + it { is_expected.not_to allow_value("invalid_email").for(:email) } + end + context "teacher distinct period" do context "when the period has not finished yet" do context "when the teacher has a sibling ect_at_school_period starting later" do diff --git a/spec/models/mentor_at_school_period_spec.rb b/spec/models/mentor_at_school_period_spec.rb index 1d6a64b1..65f7a661 100644 --- a/spec/models/mentor_at_school_period_spec.rb +++ b/spec/models/mentor_at_school_period_spec.rb @@ -14,6 +14,12 @@ it { is_expected.to validate_presence_of(:school_id) } it { is_expected.to validate_presence_of(:teacher_id) } + context "email" do + it { is_expected.to allow_value(nil).for(:email) } + it { is_expected.to allow_value("test@example.com").for(:email) } + it { is_expected.not_to allow_value("invalid_email").for(:email) } + end + context "teacher school distinct period" do context "when the period has not finished yet" do context "when the teacher has a school sibling mentor_at_school_period starting later" do