bunto-redirect-from 5.0.0 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,116 +1,149 @@
1
- require "spec_helper"
2
-
3
- describe BuntoRedirectFrom::Redirector do
4
- let(:redirector) { described_class.new }
5
- let(:post_to_redirect) { setup_post("2014-01-03-redirect-me-plz.md") }
6
- let(:doc_to_redirect_from) { setup_doc("redirect-me-plz.md") }
7
- let(:doc_to_redirect_to) { setup_doc("redirect-somewhere-else-plz.html") }
8
- let(:page_with_one) { setup_page("one_redirect_url.md") }
9
- let(:page_with_many) { setup_page("multiple_redirect_urls.md") }
10
- let(:page_with_one_redirect_to) { setup_page("one_redirect_to.md") }
11
- let(:page_with_many_redirect_to) { setup_page("multiple_redirect_tos.md") }
12
-
13
- it "knows if a page or post is requesting a redirect page" do
14
- if Bunto::VERSION < '3.0.0'
15
- expect(redirector.has_alt_urls?(post_to_redirect)).to be_truthy
16
- else
17
- skip "Don't need to test posts in Bunto 3"
18
- end
19
- end
20
-
21
- it "knows if a document is requesting a redirect page" do
22
- expect(redirector.has_alt_urls?(doc_to_redirect_from)).to be_truthy
23
- end
24
-
25
- it "knows if a document is requesting a redirect away" do
26
- expect(redirector.redirect_to_url(doc_to_redirect_to)).to eql(["http://www.zombo.com"])
27
- end
28
-
29
- it "handles one redirect path" do
30
- expect(redirector.alt_urls(page_with_one)).to eql(["mencius/was/my/father"])
31
- end
32
-
33
- it "handles many redirect paths" do
34
- expect(redirector.alt_urls(page_with_many)).to eql(["help", "contact", "let-there/be/light-he-said", "/geepers/mccreepin"])
35
- end
36
-
37
- it "handles a single redirect_to url" do
38
- expect(redirector.redirect_to_url(page_with_one_redirect_to)).to eql(["https://www.github.com"])
39
- end
40
-
41
- it "handles a many redirect_to urls" do
42
- expect(redirector.redirect_to_url(page_with_many_redirect_to)).to eql(["https://www.bunto.isc"])
43
- end
44
-
45
- it "does not include pages with a redirect in sitemap" do
46
- expect(destination_sitemap).not_to include(%|one_redirect_to.html|)
47
- end
48
-
49
- context "refresh page generation" do
50
- before(:each) do
51
- described_class.new.generate(@site)
52
- end
53
-
54
- it "generates the refresh page for the post properly" do
55
- expect(destination_file_exists?("posts/23128432159832/mary-had-a-little-lamb")).to be_truthy
56
- end
57
-
58
- it "generates the refresh pages for the page with multiple redirect_from urls" do
59
- expect(destination_file_exists?("help")).to be_truthy
60
- expect(destination_file_exists?("contact")).to be_truthy
61
- expect(destination_file_exists?("let-there/be/light-he-said")).to be_truthy
62
- expect(destination_file_exists?("/geepers/mccreepin")).to be_truthy
63
- end
64
-
65
- it "generates the refresh page for the page with one redirect_from url" do
66
- expect(destination_file_exists?("mencius/was/my/father")).to be_truthy
67
- end
68
-
69
- it "generates the refresh page for the collection with one redirect_to url" do
70
- expect(@dest.join("articles", "redirect-somewhere-else-plz.html")).to exist
71
- expect(destination_doc_contents("articles", "redirect-somewhere-else-plz.html")).to include(%|<meta http-equiv="refresh" content="0; url=http://www.zombo.com">|)
72
- end
73
-
74
- it "generates the refresh page for the page with one redirect_to url" do
75
- expect(destination_file_exists?("one_redirect_to.html")).to be_truthy
76
- expect(destination_file_contents("one_redirect_to.html")).to include(%|<meta http-equiv="refresh" content="0; url=https://www.github.com">|)
77
- end
78
-
79
- it "generates the refresh page for the page with multiple redirect_to urls" do
80
- expect(destination_file_exists?("multiple_redirect_tos.html")).to be_truthy
81
- expect(destination_file_contents("multiple_redirect_tos.html")).to include(%|<meta http-equiv="refresh" content="0; url=https://www.bunto.isc">|)
82
- end
83
- end
84
-
85
- context "prefix" do
86
- it "uses site.github.url as the redirect prefix" do
87
- @site.config['github'] = { "url" => "http://example.github.io/test" }
88
- expect(redirector.redirect_url(@site, page_with_one)).to start_with("http://example.github.io/test")
89
- end
90
-
91
- it "converts non-string values in site.github.url to strings" do
92
- @site.config['github'] = { "url" => TestStringContainer.new("http://example.github.io/test") }
93
- expect(redirector.redirect_url(@site, page_with_one)).to start_with("http://example.github.io/test")
94
- end
95
-
96
- it "uses site.baseurl as the redirect prefix when site.github.url is not set" do
97
- @site.config['baseurl'] = "/fancy/prefix"
98
- expect(redirector.redirect_url(@site, page_with_one)).to start_with("/fancy/prefix")
99
- end
100
-
101
- it "prefers site.github.url over site.baseurl" do
102
- @site.config['github'] = { "url" => "http://example.github.io/test" }
103
- @site.config['baseurl'] = "/fancy/baseurl"
104
- expect(redirector.redirect_url(@site, page_with_one)).to start_with("http://example.github.io/test")
105
- end
106
-
107
- it "no-ops when site.github.url and site.baseurl are not set" do
108
- expect(redirector.redirect_url(@site, page_with_one)).to eql("/one_redirect_url.html")
109
- end
110
-
111
- it "no-ops when site.github is set but site.github.url is not" do
112
- @site.config['github'] = "username"
113
- expect(redirector.redirect_url(@site, page_with_one)).to eql("/one_redirect_url.html")
114
- end
115
- end
116
- end
1
+ require "spec_helper"
2
+
3
+ describe BuntoRedirectFrom::Redirector do
4
+ let(:redirector) { described_class.new }
5
+ let(:post_to_redirect) { setup_post("2014-01-03-redirect-me-plz.md") }
6
+ let(:doc_to_redirect_from) { setup_doc("redirect-me-plz.md") }
7
+ let(:doc_to_redirect_to) { setup_doc("redirect-somewhere-else-plz.html") }
8
+ let(:doc_to_redirect_to_permalnk) { setup_doc("redirect-somewhere-else-im-a-permalink.html") }
9
+ let(:page_with_one) { setup_page("one_redirect_url.md") }
10
+ let(:page_with_many) { setup_page("multiple_redirect_urls.md") }
11
+ let(:page_with_one_redirect_to) { setup_page("one_redirect_to.md") }
12
+ let(:page_with_many_redirect_to) { setup_page("multiple_redirect_tos.md") }
13
+ let(:page_to_redirect_to_permlnk) { setup_page("tags/how we work.md") }
14
+
15
+ it "knows if a page or post is requesting a redirect page" do
16
+ if BuntoRedirectFrom.bunto_3?
17
+ skip "Don't need to test posts in Bunto 3"
18
+ else
19
+ expect(redirector.has_alt_urls?(post_to_redirect)).to be_truthy
20
+ end
21
+ end
22
+
23
+ it "knows if a document is requesting a redirect page" do
24
+ expect(redirector.has_alt_urls?(doc_to_redirect_from)).to be_truthy
25
+ end
26
+
27
+ it "knows if a document is requesting a redirect away" do
28
+ expect(redirector.redirect_to_url(doc_to_redirect_to)).to eql(["http://www.zombo.com"])
29
+ end
30
+
31
+ it "knows if a document is requesting a redirect away" do
32
+ expect(redirector.redirect_to_url(doc_to_redirect_to_permalnk)).to eql(["/tags/our-projects/"])
33
+ end
34
+
35
+ it "handles one redirect path" do
36
+ expect(redirector.alt_urls(page_with_one)).to eql(["mencius/was/my/father"])
37
+ end
38
+
39
+ it "handles many redirect paths" do
40
+ expect(redirector.alt_urls(page_with_many)).to eql(["help", "contact", "let-there/be/light-he-said", "/geepers/mccreepin"])
41
+ end
42
+
43
+ it "handles a single redirect_to url" do
44
+ expect(redirector.redirect_to_url(page_with_one_redirect_to)).to eql(["https://www.github.com"])
45
+ end
46
+
47
+ it "handles a many redirect_to urls" do
48
+ expect(redirector.redirect_to_url(page_with_many_redirect_to)).to eql(["https://www.buntorb.com"])
49
+ end
50
+
51
+ it "does not include pages with a redirect in sitemap" do
52
+ expect(destination_sitemap).not_to include(%|one_redirect_to.html|)
53
+ end
54
+
55
+ context "refresh page generation" do
56
+ before(:each) do
57
+ described_class.new.generate(@site)
58
+ end
59
+
60
+ it "generates the refresh page for the post properly" do
61
+ expect(dest_dir("posts/23128432159832/mary-had-a-little-lamb#{forced_output_ext}")).to exist
62
+ end
63
+
64
+ it "generates the refresh pages for the page with multiple redirect_from urls" do
65
+ expect(dest_dir("help")).to be_truthy
66
+ expect(dest_dir("contact")).to be_truthy
67
+ expect(dest_dir("let-there/be/light-he-said")).to be_truthy
68
+ expect(dest_dir("/geepers/mccreepin")).to be_truthy
69
+ end
70
+
71
+ it "generates the refresh page for the page with one redirect_from url" do
72
+ expect(dest_dir("mencius/was/my/father#{forced_output_ext}")).to exist
73
+ end
74
+
75
+ it "generates the refresh page for the collection with one redirect_to url" do
76
+ expect(dest_dir("articles", "redirect-somewhere-else-plz.html")).to exist
77
+ expect(dest_dir("articles", "redirect-somewhere-else-plz.html").read).to include(%|<meta http-equiv="refresh" content="0; url=http://www.zombo.com">|)
78
+ end
79
+
80
+ it "generates the refresh page for the collection with one redirect_to url and a permalink" do
81
+ expect(dest_dir("tags", "our projects", "index")).not_to exist
82
+ expect(dest_dir("tags", "our projects", "index.html")).to exist
83
+ expect(dest_dir("tags", "our projects", "index.html").read).to include(%|<meta http-equiv="refresh" content="0; url=/tags/our-projects/">|)
84
+ end
85
+
86
+ it "generates the refresh page for the page with one redirect_to url" do
87
+ expect(dest_dir("one_redirect_to.html")).to exist
88
+ expect(dest_dir("one_redirect_to.html").read).to include(%|<meta http-equiv="refresh" content="0; url=https://www.github.com">|)
89
+ end
90
+
91
+ it "generates the refresh page for the page with multiple redirect_to urls" do
92
+ expect(dest_dir("multiple_redirect_tos.html")).to exist
93
+ expect(dest_dir("multiple_redirect_tos.html").read).to include(%|<meta http-equiv="refresh" content="0; url=https://www.buntorb.com">|)
94
+ end
95
+
96
+ it "does not include any default layout" do
97
+ expect(dest_dir("multiple_redirect_tos.html")).to exist
98
+ expect(dest_dir("multiple_redirect_tos.html").read).not_to include('LAYOUT INCLUDED')
99
+ end
100
+
101
+ it "generates the refresh page for the page with one redirect_to url and a permalink" do
102
+ expect(dest_dir("tags", "how we work", "index")).not_to exist
103
+ expect(dest_dir("tags", "how we work", "index.html")).to exist
104
+ expect(dest_dir("tags", "how we work", "index.html").read).to include(%|<meta http-equiv="refresh" content="0; url=/tags/how-we-work/">|)
105
+ end
106
+ end
107
+
108
+ context "prefix" do
109
+ it "uses site.url as the redirect prefix when site.github.url is not set" do
110
+ @site.config['url'] = "http://notgithub.io"
111
+ @site.config['baseurl'] = nil
112
+ expect(redirector.redirect_url(@site, page_with_one)).to eql("http://notgithub.io/one_redirect_url.html")
113
+ end
114
+
115
+ it "uses site.baseurl as the redirect prefix when site.github.url is not set" do
116
+ @site.config['url'] = nil
117
+ @site.config['baseurl'] = "/fancy/prefix"
118
+ expect(redirector.redirect_url(@site, page_with_one)).to eql("/fancy/prefix/one_redirect_url.html")
119
+ end
120
+
121
+ it "uses site.url + site.baseurl as the redirect prefix when site.github.url is not set" do
122
+ @site.config['url'] = "http://notgithub.io"
123
+ @site.config['baseurl'] = "/fancy/prefix"
124
+ expect(redirector.redirect_url(@site, page_with_one)).to eql("http://notgithub.io/fancy/prefix/one_redirect_url.html")
125
+ end
126
+
127
+ it "prefers site.github.url over site.url or site.baseurl" do
128
+ @site.config['url'] = "http://notgithub.io"
129
+ @site.config['baseurl'] = "/fancy/prefix"
130
+ @site.config['github'] = { "url" => "http://example.github.io/test" }
131
+ expect(redirector.redirect_url(@site, page_with_one)).to eql("http://example.github.io/test/one_redirect_url.html")
132
+ end
133
+
134
+ it "converts non-string values in site.github.url to strings" do
135
+ @site.config['github'] = { "url" => TestStringContainer.new("http://example.github.io/test") }
136
+ expect(redirector.redirect_url(@site, page_with_one)).to eql("http://example.github.io/test/one_redirect_url.html")
137
+ end
138
+
139
+ it "uses site.url when site.github is set but site.github.url is not" do
140
+ @site.config['github'] = "username"
141
+ expect(redirector.redirect_url(@site, page_with_one)).to eql("http://bunto.github.io/one_redirect_url.html")
142
+ end
143
+
144
+ it "no-ops when site.github.url and site.baseurl and site.url are not set" do
145
+ @site.config['url'] = nil
146
+ expect(redirector.redirect_url(@site, page_with_one)).to eql("/one_redirect_url.html")
147
+ end
148
+ end
149
+ end
@@ -1,6 +1,6 @@
1
- ---
2
- title: Please redirect me, sir.
3
- redirect_from: /articles/23128432159832/mary-had-a-little-lamb
4
- ---
5
-
6
- Yay.
1
+ ---
2
+ title: Please redirect me, sir.
3
+ redirect_from: /articles/23128432159832/mary-had-a-little-lamb
4
+ ---
5
+
6
+ Yay.
@@ -0,0 +1,7 @@
1
+ ---
2
+ title: Please redirect away from me and my permalink.
3
+ permalink: /tags/our projects/
4
+ redirect_to: /tags/our-projects/
5
+ ---
6
+
7
+ Bye.
@@ -1,6 +1,6 @@
1
- ---
2
- title: Please redirect away from me, sir.
3
- redirect_to: "http://www.zombo.com"
4
- ---
5
-
6
- Boo.
1
+ ---
2
+ title: Please redirect away from me, sir.
3
+ redirect_to: "http://www.zombo.com"
4
+ ---
5
+
6
+ Boo.
@@ -1,5 +1,5 @@
1
- ---
2
- redirect_from: /kansaichris/
3
- ---
4
-
5
- Hi.
1
+ ---
2
+ redirect_from: /kansaichris/
3
+ ---
4
+
5
+ Hi.
@@ -1,7 +1,7 @@
1
- url: http://bunto.isc
2
- gems:
3
- - bunto-redirect-from
4
- - bunto-sitemap
5
- collections:
6
- articles:
7
- output: true
1
+ url: https://bunto.github.io
2
+ gems:
3
+ - bunto-redirect-from
4
+ - bunto-sitemap
5
+ collections:
6
+ articles:
7
+ output: true
@@ -0,0 +1,6 @@
1
+ ---
2
+ ---
3
+
4
+ LAYOUT INCLUDED
5
+
6
+ {{ content }}
@@ -1,6 +1,6 @@
1
- ---
2
- title: Please redirect me, sir.
3
- redirect_from: /posts/23128432159832/mary-had-a-little-lamb
4
- ---
5
-
6
- Yay.
1
+ ---
2
+ title: Please redirect me, sir.
3
+ redirect_from: /posts/23128432159832/mary-had-a-little-lamb
4
+ ---
5
+
6
+ Yay.
@@ -1,9 +1,9 @@
1
- ---
2
- title: I have lots of redirect to urls
3
- redirect_to:
4
- - https://www.bunto.isc
5
- - https://www.github.com
6
- - https://www.twitter.com
7
- ---
8
-
9
- Lots of redirect to urls.
1
+ ---
2
+ title: I have lots of redirect to urls
3
+ redirect_to:
4
+ - https://bunto.github.io
5
+ - https://www.github.com
6
+ - https://www.twitter.com
7
+ ---
8
+
9
+ Lots of redirect to urls.
@@ -1,10 +1,10 @@
1
- ---
2
- title: I have lots of redirect urls
3
- redirect_from:
4
- - help
5
- - contact
6
- - let-there/be/light-he-said
7
- - /geepers/mccreepin
8
- ---
9
-
10
- Lots of redirect urls
1
+ ---
2
+ title: I have lots of redirect urls
3
+ redirect_from:
4
+ - help
5
+ - contact
6
+ - let-there/be/light-he-said
7
+ - /geepers/mccreepin
8
+ ---
9
+
10
+ Lots of redirect urls
@@ -1,6 +1,6 @@
1
- ---
2
- title: I am going somewhere else.
3
- redirect_to: https://www.github.com
4
- ---
5
-
6
- Redirecting elsewhere.
1
+ ---
2
+ title: I am going somewhere else.
3
+ redirect_to: https://www.github.com
4
+ ---
5
+
6
+ Redirecting elsewhere.
@@ -1,6 +1,6 @@
1
- ---
2
- title: I only have one redirect url.
3
- redirect_from: mencius/was/my/father
4
- ---
5
-
6
- One redirect url
1
+ ---
2
+ title: I only have one redirect url.
3
+ redirect_from: mencius/was/my/father
4
+ ---
5
+
6
+ One redirect url
@@ -0,0 +1,4 @@
1
+ ---
2
+ redirect_to: "/tags/how-we-work/"
3
+ permalink: "/tags/how we work/"
4
+ ---
@@ -1,13 +1,13 @@
1
- require 'spec_helper'
2
-
3
- describe("Integration Tests") do
4
- it "writes the redirect pages for collection items which are outputted" do
5
- expect(@dest.join("articles", "redirect-me-plz.html")).to exist
6
- expect(@dest.join("articles", "23128432159832", "mary-had-a-little-lamb")).to exist
7
- end
8
-
9
- it "doesn't write redirect pages for collection items which are not outputted" do
10
- expect(@dest.join("authors")).not_to exist
11
- expect(@dest.join("kansaichris")).not_to exist
12
- end
13
- end
1
+ require 'spec_helper'
2
+
3
+ describe("Integration Tests") do
4
+ it "writes the redirect pages for collection items which are outputted" do
5
+ expect(dest_dir("articles", "redirect-me-plz.html")).to exist
6
+ expect(dest_dir("articles", "23128432159832", "mary-had-a-little-lamb#{forced_output_ext}")).to exist
7
+ end
8
+
9
+ it "doesn't write redirect pages for collection items which are not outputted" do
10
+ expect(dest_dir("authors")).not_to exist
11
+ expect(dest_dir("kansaichris")).not_to exist
12
+ end
13
+ end