8000 Add test for preventing load data on reset · jekyll/github-metadata@eced31d · GitHub
[go: up one dir, main page]

Skip to content

Commit eced31d

Browse files
committed
Add test for preventing load data on reset
This commit adds a new fixture site that doesn't load all of `site.github`. It just loads a few items. We then check that those items are loaded once after the first and second times the site is processed. We also use a new spec helper function `not_expect_api_call` to make sure other API calls are not made. This test checks a few enpoints that get loaded when the entire `site.github` is loaded. Before adding the uninject code, these API endpoints would have gotten called, despite not being used by the fixture site. With the uninject changes, they are no longer called.
1 parent 2c265a5 commit eced31d

File tree

5 files changed

+57
-0
lines changed

5 files changed

+57
-0
lines changed

spec/site_github_munger_spec.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,4 +231,27 @@
231231
end.to raise_error(Jekyll::GitHubMetadata::Client::BadCredentialsError)
232232
end
233233
end
234+
235+
context "render the 'uninject' fixture test site" do
236+
let(:source) { File.expand_path("test-site-uninject", __dir__) }
237+
let(:dest) { File.expand_path("../tmp/test-site-uninject-build", __dir__) }
238+
239+
it "process site twice (simulate reset), check API calls" do
240+
config = Jekyll::Configuration.from({"source" => source, "destination" => dest})
241+
site = Jekyll::Site.new(config)
242+
site.process
243+
expect_api_call "/repos/jekyll/github-metadata"
244+
expect_api_call "/repos/jekyll/github-metadata/releases/latest"
245+
expect_api_call "/orgs/jekyll"
246+
site.process
247+
expect_api_call "/repos/jekyll/github-metadata"
248+
expect_api_call "/repos/jekyll/github-metadata/releases/latest"
249+
expect_api_call "/orgs/jekyll"
250+
251+
not_expect_api_call "/repos/jekyll/github-metadata/pages"
252+
not_expect_api_call "/repos/jekyll/github-metadata/contributors?per_page=100"
253+
not_expect_api_call "/orgs/jekyll/public_members?per_page=100"
254+
not_expect_api_call "/users/jekyll/repos?per_page=100&type=public"
255+
end
256+
end
234257
end

spec/spec_helpers/web_mock_helper.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ def expect_api_call(path)
4141
.with(:headers => request_headers).once
4242
end
4343

44+
def not_expect_api_call(path)
45+
expect(WebMock).to have_requested(:get, url(path))
46+
.with(:headers => request_headers).times(0)
47+
end
48+
4449
def request_headers
4550
REQUEST_HEADERS.merge(
4651
"Authorization" => "token #{ENV.fetch("JEKYLL_GITHUB_TOKEN", "1234abc")}"

spec/test-site-uninject/_config.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
repository: jekyll/github-metadata
2+
github:
3+
in_your_config:
4+
setting_your: keyz
5+
plugins:
6+
- jekyll-github-metadata
7+
# remove this once we drop support for Jekyll v3.4 and below
8+
gems:
9+
- jekyll-github-metadata

spec/test-site-uninject/index.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
---
3+
4+
<!DOCTYPE html>
5+
<html>
6+
<head>
7+
<meta charset="utf-8">
8+
<title>Page Title</title>
9+
</head>
10+
<body>
11+
<h1>{{ site.github.project_title }}</h1>
12+
<h2>{{ site.github.project_tagline }}</h2>
13+
<h2>Owner: {{ site.github.owner_name }}</h2>
14+
<h3>Latest Release: {{ site.github.latest_release }}</h3>
15+
</body>
16+
</html>

spec/test-site-uninject/subvalues.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
---
3+
4+
owner: {{ site.github.owner }}

0 commit comments

Comments
 (0)
0