From c7a2b8311305df94f2c9592ca64b1c38e9204b48 Mon Sep 17 00:00:00 2001 From: Yoann Chaudet Date: Tue, 10 Sep 2024 09:08:55 -0700 Subject: [PATCH] Simplify github_domain? check + add test --- lib/github-pages-health-check/domain.rb | 2 +- spec/github_pages_health_check/domain_spec.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/github-pages-health-check/domain.rb b/lib/github-pages-health-check/domain.rb index 32c4344..83097f2 100644 --- a/lib/github-pages-health-check/domain.rb +++ b/lib/github-pages-health-check/domain.rb @@ -283,7 +283,7 @@ def pages_dot_github_dot_com? # Is this domain owned by GitHub? def github_domain? - !!host.match(/(\A|\.)github\.com\.?\z/i) + host.downcase.eql?("github.com") || host.downcase.end_with?(".github.com") end # Is the host our Fastly CNAME? diff --git a/spec/github_pages_health_check/domain_spec.rb b/spec/github_pages_health_check/domain_spec.rb index 2161a99..cc5a51d 100644 --- a/spec/github_pages_health_check/domain_spec.rb +++ b/spec/github_pages_health_check/domain_spec.rb @@ -535,6 +535,14 @@ end end + context "not github domains" do + let(:domain) { "somethinggithub.com" } + + it "knows if the domain is a github domain" do + expect(subject).to_not be_a_github_domain + end + end + context "fastly domain" do let(:domain) { "github.map.fastly.net" }