File: pages_spec.rb

package info (click to toggle)
ruby-jekyll-github-metadata 2.15.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 712 kB
  • sloc: ruby: 2,355; javascript: 107; sh: 41; makefile: 6
file content (153 lines) | stat: -rw-r--r-- 4,859 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# frozen_string_literal: true

require "spec_helper"

RSpec.describe(Jekyll::GitHubMetadata::Pages) do
  context "enterprise" do
    before(:each) { ENV["PAGES_ENV"] = "enterprise" }
    after(:each)  { ENV["PAGES_ENV"] = "test" }

    let(:ghe_domain) { "ghe.io" }

    it "disables custom domains" do
      expect(described_class.custom_domains_enabled?).to be false
    end

    it "looks for the domain specified" do
      with_env("GITHUB_HOSTNAME", ghe_domain) do
        expect(described_class.github_url).to eql("http://#{ghe_domain}")
        expect(described_class.github_hostname).to eql ghe_domain
      end
    end

    it "handles a separate pages hostname" do
      pages_hostname = "pages.#{ghe_domain}"
      with_env("PAGES_HOSTNAME", pages_hostname) do
        expect(described_class.pages_hostname).to eql pages_hostname
      end
    end
  end

  context ".configuration" do
    it "returns the entire configuration" do
      expect(described_class.configuration).to eql(
        "api_url"                      => "https://api.github.com",
        "custom_domains_enabled?"      => true,
        "development?"                 => false,
        "dotcom?"                      => false,
        "enterprise?"                  => false,
        "env"                          => "test",
        "github_hostname"              => "github.com",
        "github_url"                   => "https://github.com",
        "help_url"                     => "https://help.github.com",
        "page_build?"                  => false,
        "pages_hostname"               => "github.io",
        "repo_pages_html_url_preview?" => nil,
        "scheme"                       => "https",
        "ssl?"                         => true,
        "subdomain_isolation?"         => false,
        "test?"                        => true
      )
    end
  end

  context ".env" do
    it "picks up on PAGES_ENV" do
      with_env("PAGES_ENV", "halp") do
        expect(described_class.env).to eql("halp")
      end
    end

    it "picks up on JEKYLL_ENV" do
      with_env "PAGES_ENV", "" do
        with_env "JEKYLL_ENV", "halp" do
          expect(described_class.env).to eql("halp")
        end
      end
    end

    it "has convenience methods for various envs" do
      with_env("PAGES_ENV", "test") do
        expect(described_class.test?).to be true
        expect(described_class.dotcom?).to be false
        expect(described_class.enterprise?).to be false
        expect(described_class.development?).to be false
      end
      with_env("PAGES_ENV", "dotcom") do
        expect(described_class.test?).to be false
        expect(described_class.dotcom?).to be true
        expect(described_class.enterprise?).to be false
        expect(described_class.development?).to be false
      end
      with_env("PAGES_ENV", "enterprise") do
        expect(described_class.test?).to be false
        expect(described_class.dotcom?).to be false
        expect(described_class.enterprise?).to be true
        expect(described_class.development?).to be false
      end
      with_env("PAGES_ENV", "development") do
        expect(described_class.test?).to be false
        expect(described_class.dotcom?).to be false
        expect(described_class.enterprise?).to be false
        expect(described_class.development?).to be true
      end
    end
  end

  context ".ssl?" do
    before(:each) { ENV["PAGES_ENV"] = "dotcom" }
    after(:each)  { ENV["PAGES_ENV"] = "test" }

    it "only returns true when $SSL is set to 'true'" do
      with_env "SSL", "true" do
        expect(described_class.ssl?).to be true
      end
      with_env "SSL", "trueish" do
        expect(described_class.ssl?).to be false
      end
    end

    it "is true in PAGES_ENV=test" do
      with_env(
        "PAGES_ENV" => "test",
        "SSL"       => "false"
      ) do
        expect(described_class.ssl?).to be true
      end
    end
  end

  context ".subdomain_isolation?" do
    it "returns true when $SUBDOMAIN_ISOLATION is set to 'true'" do
      with_env "SUBDOMAIN_ISOLATION", "true" do
        expect(described_class.subdomain_isolation?).to be true
      end
    end

    it "returns false for any other value" do
      with_env "SUBDOMAIN_ISOLATION", "" do
        expect(described_class.subdomain_isolation?).to be false
      end
    end
  end

  context "development" do
    it "uses the local pages hostname" do
      with_env "PAGES_ENV", "development" do
        expect(described_class.pages_hostname).to eql("localhost:4000")
      end
    end
  end

  context ".page_build?" do
    it "returns true when $PAGE_BUILD_ID is set" do
      with_env "PAGE_BUILD_ID", "123" do
        expect(described_class.page_build?).to be(true)
      end
    end

    it "returns false by default" do
      expect(described_class.page_build?).to be(false)
    end
  end
end