Skip to content

Commit fe4b976

Browse files
committed
Update tests to actually read sitemap content
1 parent 8b135c3 commit fe4b976

4 files changed

Lines changed: 129 additions & 8 deletions

File tree

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
class SitemapsController < ApplicationController
22
def index
33
if TeSS::Config.feature['spaces'] && !current_space.default?
4-
render file: Rails.root.join("public/sitemaps/#{current_space.host}/sitemap.xml"), layout: false
4+
render file: sitemap_base.join("#{current_space.host}/sitemap.xml"), layout: false
55
else
6-
render file: Rails.root.join('public/sitemaps/sitemap.xml'), layout: false
6+
render file: sitemap_base.join('sitemap.xml'), layout: false
77
end
88
end
9+
10+
private
11+
12+
def sitemap_base
13+
Rails.env.test? ? Rails.root.join('test/fixtures/files/sitemaps/') : Rails.root.join('public/sitemaps/')
14+
end
915
end

test/controllers/sitemaps_controller_test.rb

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,44 @@
33
class SitemapsControllerTest < ActionController::TestCase
44
include Devise::Test::ControllerHelpers
55

6-
test 'redirects to global sitemap when spaces feature is disabled' do
6+
test 'renders global sitemap when spaces feature is disabled' do
77
with_settings(feature: { spaces: false }) do
88
get :index
99
end
10-
assert_redirected_to '/sitemaps/sitemap.xml'
10+
11+
urls = sitemap_urls
12+
assert_includes urls, 'http://mytess.training/about'
13+
assert_not_includes urls, 'http://plants.mytess.training/about'
1114
end
1215

13-
test 'redirects to global sitemap for default space when spaces feature is enabled' do
16+
test 'renders global sitemap for default space when spaces feature is enabled' do
1417
with_settings(feature: { spaces: true }) do
1518
get :index
1619
end
17-
assert_redirected_to '/sitemaps/sitemap.xml'
20+
21+
urls = sitemap_urls
22+
assert_includes urls, 'http://mytess.training/about'
23+
assert_not_includes urls, 'http://plants.mytess.training/about'
1824
end
1925

20-
test 'redirects to space-specific sitemap when request is for a known space host' do
26+
test 'renders space-specific sitemap when request is for a known space host' do
2127
space = spaces(:plants)
2228
with_settings(feature: { spaces: true }) do
2329
with_host(space.host) do
2430
get :index
2531
end
2632
end
27-
assert_redirected_to "/sitemaps/#{space.host}/sitemap.xml"
33+
34+
urls = sitemap_urls
35+
assert_not_includes urls, 'http://mytess.training/about'
36+
assert_includes urls, 'http://plants.mytess.training/about'
37+
end
38+
39+
private
40+
41+
def sitemap_urls
42+
parser = SitemapParser.new('', recurse: true)
43+
parser.instance_variable_set(:@raw_sitemap, @response.body)
44+
parser.to_a
2845
end
2946
end
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"
4+
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
5+
xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"
6+
xmlns:video="http://www.google.com/schemas/sitemap-video/1.1"
7+
xmlns:news="http://www.google.com/schemas/sitemap-news/0.9"
8+
xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0"
9+
xmlns:pagemap="http://www.google.com/schemas/sitemap-pagemap/1.0" xmlns:xhtml="http://www.w3.org/1999/xhtml">
10+
<url>
11+
<loc>http://plants.mytess.training</loc>
12+
<lastmod>2026-04-21T11:16:34+01:00</lastmod>
13+
<changefreq>daily</changefreq>
14+
<priority>1.0</priority>
15+
</url>
16+
<url>
17+
<loc>http://plants.mytess.training/about</loc>
18+
<lastmod>2026-04-21T11:16:34+01:00</lastmod>
19+
<changefreq>weekly</changefreq>
20+
<priority>0.4</priority>
21+
</url>
22+
<url>
23+
<loc>http://plants.mytess.training/materials</loc>
24+
<lastmod>2025-10-28T07:31:02+00:00</lastmod>
25+
<changefreq>daily</changefreq>
26+
<priority>0.7</priority>
27+
</url>
28+
<url>
29+
<loc>http://plants.mytess.training/events</loc>
30+
<lastmod>2025-11-20T13:57:11+00:00</lastmod>
31+
<changefreq>daily</changefreq>
32+
<priority>0.7</priority>
33+
</url>
34+
<url>
35+
<loc>http://plants.mytess.training/content_providers</loc>
36+
<lastmod>2025-04-22T08:26:43+00:00</lastmod>
37+
<changefreq>weekly</changefreq>
38+
<priority>0.4</priority>
39+
</url>
40+
</urlset>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"
4+
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
5+
xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"
6+
xmlns:video="http://www.google.com/schemas/sitemap-video/1.1"
7+
xmlns:news="http://www.google.com/schemas/sitemap-news/0.9"
8+
xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0"
9+
xmlns:pagemap="http://www.google.com/schemas/sitemap-pagemap/1.0" xmlns:xhtml="http://www.w3.org/1999/xhtml">
10+
<url>
11+
<loc>http://mytess.training</loc>
12+
<lastmod>2026-04-17T17:10:24+01:00</lastmod>
13+
<changefreq>daily</changefreq>
14+
<priority>1.0</priority>
15+
</url>
16+
<url>
17+
<loc>http://mytess.training/about</loc>
18+
<lastmod>2026-04-17T17:10:24+01:00</lastmod>
19+
<changefreq>weekly</changefreq>
20+
<priority>0.4</priority>
21+
</url>
22+
<url>
23+
<loc>http://mytess.training/materials</loc>
24+
<lastmod>2026-03-10T17:00:32+00:00</lastmod>
25+
<changefreq>daily</changefreq>
26+
<priority>0.7</priority>
27+
</url>
28+
<url>
29+
<loc>http://mytess.training/events</loc>
30+
<lastmod>2026-03-18T16:57:25+00:00</lastmod>
31+
<changefreq>daily</changefreq>
32+
<priority>0.7</priority>
33+
</url>
34+
<url>
35+
<loc>http://mytess.training/content_providers</loc>
36+
<lastmod>2025-04-22T08:26:43+00:00</lastmod>
37+
<changefreq>weekly</changefreq>
38+
<priority>0.4</priority>
39+
</url>
40+
<url>
41+
<loc>http://mytess.training/workflows</loc>
42+
<lastmod>2025-12-22T11:44:53+00:00</lastmod>
43+
<changefreq>daily</changefreq>
44+
<priority>0.6</priority>
45+
</url>
46+
<url>
47+
<loc>http://mytess.training/collections</loc>
48+
<lastmod>2025-05-23T14:25:06+00:00</lastmod>
49+
<changefreq>daily</changefreq>
50+
<priority>0.6</priority>
51+
</url>
52+
<url>
53+
<loc>http://mytess.training/learning_paths</loc>
54+
<lastmod>2026-02-11T13:00:15+00:00</lastmod>
55+
<changefreq>daily</changefreq>
56+
<priority>0.6</priority>
57+
</url>
58+
</urlset>

0 commit comments

Comments
 (0)