Skip to content

Commit 3ed981f

Browse files
Format domains
Removing leading @ symbols and lower case domains
1 parent d227cae commit 3ed981f

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

app/models/school_email_domain.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
# frozen_string_literal: true
2+
13
class 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

spec/models/school_email_domain_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,18 @@
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
1731
end

0 commit comments

Comments
 (0)