File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
13class SchoolEmailDomain < ApplicationRecord
2- belongs_to :school
3- end
4+ belongs_to :school
5+
6+ before_validation :format_domain
7+
8+ private
9+
10+ def format_domain
11+ return if domain . nil?
12+
13+ self . domain = domain . to_s . strip . sub ( /\A @+/ , '' ) . downcase
14+ end
15+ end
Original file line number Diff line number Diff line change 1414 it 'has a domain' do
1515 expect ( school_email_domain . domain ) . to eq ( 'example.edu' )
1616 end
17+
18+ it 'downcases the domain' do
19+ school_email_domain = described_class . new ( school : school , domain : 'EXAMPLE.EDU' )
20+ school_email_domain . valid?
21+
22+ expect ( school_email_domain . domain ) . to eq ( 'example.edu' )
23+ end
24+
25+ it 'removes a leading @' do
26+ school_email_domain = described_class . new ( school : school , domain : '@example.edu' )
27+ school_email_domain . valid?
28+
29+ expect ( school_email_domain . domain ) . to eq ( 'example.edu' )
30+ end
1731end
You can’t perform that action at this time.
0 commit comments