Skip to content

Commit

Permalink
feat: update ECTAtSchoolPeriod and MentorAtSchoolPeriod models to han…
Browse files Browse the repository at this point in the history
…dle 'email'. Add email formatting validation
  • Loading branch information
TobyRet committed Jan 24, 2025
1 parent 8c04344 commit d2968ec
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/models/ect_at_school_period.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ class ECTAtSchoolPeriod < ApplicationRecord
has_many :events

# Validations
validates :email,
notify_email: true,
allow_nil: true

validates :started_on,
presence: true

Expand Down
4 changes: 4 additions & 0 deletions app/models/mentor_at_school_period.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ class MentorAtSchoolPeriod < ApplicationRecord
has_many :events

# Validations
validates :email,
notify_email: true,
allow_nil: true

validates :started_on,
presence: true

Expand Down
6 changes: 6 additions & 0 deletions spec/models/ect_at_school_period_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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("[email protected]").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
Expand Down
6 changes: 6 additions & 0 deletions spec/models/mentor_at_school_period_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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("[email protected]").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
Expand Down

0 comments on commit d2968ec

Please sign in to comment.