Skip to content

Commit c66476a

Browse files
committed
Merge branch 'fix-domains_is_in' of github.com:cm-dyoshikawa/valid_email2 into nested_domains
2 parents 63fa0fa + f052d7f commit c66476a

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

spec/address_spec.rb

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,53 @@
105105
end
106106
end
107107

108+
describe "#disposable_domain?" do
109+
let(:domain_hierarchy_max_depth) { 10 }
110+
111+
context "when the disposable domain does not have subdomains" do
112+
let(:disposable_domain) { ValidEmail2.disposable_emails.find { |domain| domain.count(".") == 1 } }
113+
114+
it "is true if the domain is in the disposable_emails list" do
115+
address = described_class.new("foo@#{disposable_domain}", nil, nil, domain_hierarchy_max_depth:)
116+
expect(address.disposable_domain?).to eq true
117+
end
118+
119+
it "is true if the domain is a subdomain of a disposable domain" do
120+
address = described_class.new("foo@sub.#{disposable_domain}", nil, nil, domain_hierarchy_max_depth:)
121+
expect(address.disposable_domain?).to eq true
122+
end
123+
124+
it "is true if the domain is a deeply nested subdomain of a disposable domain" do
125+
address = described_class.new("foo@sub3.sub2.sub1.#{disposable_domain}", nil, nil, domain_hierarchy_max_depth:)
126+
expect(address.disposable_domain?).to eq true
127+
end
128+
129+
it "is false if the domain is not in the disposable_emails list" do
130+
address = described_class.new("foo@example.com", nil, nil, domain_hierarchy_max_depth:)
131+
expect(address.disposable_domain?).to eq false
132+
end
133+
end
134+
135+
context "when the disposable domain has subdomains" do
136+
let(:disposable_domain) { ValidEmail2.disposable_emails.find { |domain| domain.count(".") > 1 } }
137+
138+
it "is true if the domain is in the disposable_emails list" do
139+
address = described_class.new("foo@#{disposable_domain}", nil, nil, domain_hierarchy_max_depth:)
140+
expect(address.disposable_domain?).to eq true
141+
end
142+
143+
it "is true if the domain is a subdomain of a disposable domain" do
144+
address = described_class.new("foo@sub.#{disposable_domain}", nil, nil, domain_hierarchy_max_depth:)
145+
expect(address.disposable_domain?).to eq true
146+
end
147+
148+
it "is true if the domain is a deeply nested subdomain of a disposable domain" do
149+
address = described_class.new("foo@sub3.sub2.sub1.#{disposable_domain}", nil, nil, domain_hierarchy_max_depth:)
150+
expect(address.disposable_domain?).to eq true
151+
end
152+
end
153+
end
154+
108155
describe "caching" do
109156
let(:email_address) { "example@ymail.com" }
110157
let(:dns_instance) { ValidEmail2::Dns.new }

0 commit comments

Comments
 (0)