File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 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 :) }
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
You can’t perform that action at this time.
0 commit comments