Skip to content

Commit 4740867

Browse files
Add has_many association on School
1 parent 3ed981f commit 4740867

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

app/models/school.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class School < ApplicationRecord
66
has_many :projects, dependent: :nullify
77
has_many :roles, dependent: :nullify
88
has_many :school_projects, dependent: :nullify
9+
has_many :school_email_domains, dependent: :destroy
910

1011
VALID_URL_REGEX = %r{\A(?:https?://)?(?:www.)?[a-z0-9]+([-.]{1}[a-z0-9]+)*\.[a-z]{2,63}(\.[a-z]{2,63})*(/.*)?\z}ix
1112

spec/models/school_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@
3535
expect(school.roles.size).to eq(2)
3636
end
3737

38+
it 'has many school email domains' do
39+
SchoolEmailDomain.create!(school:, domain: 'example.edu')
40+
SchoolEmailDomain.create!(school:, domain: 'other.edu')
41+
expect(school.school_email_domains.size).to eq(2)
42+
end
43+
3844
context 'when a school is destroyed' do
3945
let!(:school_class) { create(:school_class, school:, teacher_ids: [teacher.id]) }
4046
let!(:lesson_1) { create(:lesson, user_id: teacher.id, school_class:) }
@@ -88,6 +94,11 @@
8894
school.destroy!
8995
expect(role.reload.school_id).to be_nil
9096
end
97+
98+
it 'also destroys school email domains' do
99+
SchoolEmailDomain.create!(school:, domain: 'example.edu')
100+
expect { school.destroy! }.to change(SchoolEmailDomain, :count).by(-1)
101+
end
91102
end
92103
end
93104

0 commit comments

Comments
 (0)