indexmap 0.6.0 → 0.7.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.
@@ -5,88 +5,117 @@ require "test_helper"
5
5
  class IndexmapTaskRunnerTest < Minitest::Test
6
6
  VALID_KEY = "1234567890abcdef1234567890abcdef"
7
7
 
8
+ class KeywordContentTypeStorage < Indexmap::Storage::Memory
9
+ def write(filename, body, content_type:)
10
+ super
11
+ end
12
+
13
+ def read_file(filename)
14
+ instance_variable_get(:@files).fetch(filename)
15
+ end
16
+ end
17
+
8
18
  def test_create_writes_new_sitemap_and_key_file_without_deleting_unrelated_files
9
- Dir.mktmpdir do |dir|
10
- public_path = Pathname(dir)
11
- public_path.join("sitemap.xml").write("old")
12
- public_path.join("sitemap-pages.xml.gz").write("old")
13
- public_path.join("sitemap-extra.xml").write("existing")
19
+ storage = Indexmap::Storage::Memory.new
20
+ storage.write("sitemap-pages.xml.gz", "old")
21
+ storage.write("sitemap-extra.xml", "existing")
14
22
 
15
- configuration = Indexmap::Configuration.new
16
- configuration.base_url = "https://example.com"
17
- configuration.public_path = public_path
18
- configuration.sections = [
19
- Indexmap::Section.new(
20
- filename: "sitemap-pages.xml",
21
- entries: [Indexmap::Entry.new(loc: "https://example.com/about")]
22
- )
23
- ]
24
- configuration.index_now.key = VALID_KEY
23
+ configuration = configuration_with(storage: storage)
24
+ configuration.index_now.key = VALID_KEY
25
25
 
26
- result = Indexmap::TaskRunner.new(configuration: configuration).create
26
+ result = Indexmap::TaskRunner.new(configuration: configuration).create
27
27
 
28
- assert public_path.join("sitemap-pages.xml.gz").exist?
29
- assert_equal "existing", public_path.join("sitemap-extra.xml").read
30
- assert_includes public_path.join("sitemap.xml").read, "<sitemapindex"
31
- assert_equal VALID_KEY, public_path.join("#{VALID_KEY}.txt").read
32
- assert_equal [public_path.join("sitemap-pages.xml").to_s, public_path.join("sitemap.xml").to_s], result[:files]
33
- assert_equal [public_path.join("sitemap-pages.xml"), public_path.join("sitemap.xml")], result[:written_files]
34
- assert_equal public_path.join("#{VALID_KEY}.txt"), result[:index_now_key_path]
35
- end
28
+ assert storage.exist?("sitemap-pages.xml.gz")
29
+ assert_equal "existing", storage.read("sitemap-extra.xml")
30
+ assert_includes storage.read("sitemap.xml"), "<sitemapindex"
31
+ assert_equal VALID_KEY, storage.read("#{VALID_KEY}.txt")
32
+ assert_equal ["sitemap-pages.xml", "sitemap.xml"], result[:files]
33
+ assert_equal ["sitemap-pages.xml", "sitemap.xml"], result[:written_files]
34
+ assert_equal "#{VALID_KEY}.txt", result[:index_now_key_filename]
36
35
  end
37
36
 
38
37
  def test_create_runs_after_create_callbacks_after_validation
39
- Dir.mktmpdir do |dir|
40
- calls = []
41
- public_path = Pathname(dir)
42
- configuration = Indexmap::Configuration.new
43
- configuration.base_url = "https://example.com"
44
- configuration.public_path = public_path
45
- configuration.sections = [
46
- Indexmap::Section.new(
47
- filename: "sitemap-pages.xml",
48
- entries: [Indexmap::Entry.new(loc: "https://example.com/about")]
49
- )
50
- ]
51
- configuration.after_create do
52
- calls << :called
53
- calls << public_path.join("sitemap.xml").read.include?("<sitemapindex")
54
- end
38
+ calls = []
39
+ storage = Indexmap::Storage::Memory.new
40
+ configuration = configuration_with(storage: storage)
41
+ configuration.after_create do
42
+ calls << :called
43
+ calls << storage.read("sitemap.xml").include?("<sitemapindex")
44
+ end
55
45
 
56
- Indexmap::TaskRunner.new(configuration: configuration).create
46
+ Indexmap::TaskRunner.new(configuration: configuration).create
57
47
 
58
- assert_equal [:called, true], calls
59
- end
48
+ assert_equal [:called, true], calls
49
+ end
50
+
51
+ def test_create_reuses_existing_index_now_key_file
52
+ storage = Indexmap::Storage::Memory.new
53
+ storage.write("#{VALID_KEY}.txt", VALID_KEY, content_type: "text/plain")
54
+ configuration = configuration_with(storage: storage)
55
+ configuration.index_now.key = VALID_KEY
56
+
57
+ result = Indexmap::TaskRunner.new(configuration: configuration).create
58
+
59
+ assert_equal "#{VALID_KEY}.txt", result[:index_now_key_filename]
60
+ assert_equal VALID_KEY, storage.read("#{VALID_KEY}.txt")
61
+ end
62
+
63
+ def test_create_can_skip_index_now_key_file_writing
64
+ storage = Indexmap::Storage::Memory.new
65
+ configuration = configuration_with(storage: storage)
66
+ configuration.index_now.key = VALID_KEY
67
+ configuration.index_now.write_key_file = false
68
+
69
+ result = Indexmap::TaskRunner.new(configuration: configuration).create
70
+
71
+ refute storage.exist?("#{VALID_KEY}.txt")
72
+ assert_nil result[:index_now_key_filename]
73
+ assert_equal ["sitemap-pages.xml", "sitemap.xml"], result[:files]
60
74
  end
61
75
 
62
76
  def test_write_index_now_key_returns_nil_when_key_is_not_configured
63
- Dir.mktmpdir do |dir|
64
- configuration = Indexmap::Configuration.new
77
+ result = Indexmap::TaskRunner.new(configuration: configuration_with).write_index_now_key
78
+
79
+ assert_nil result
80
+ end
81
+
82
+ def test_write_index_now_key_can_generate_a_key_when_requested
83
+ storage = Indexmap::Storage::Memory.new
84
+ configuration = configuration_with(storage: storage)
85
+
86
+ result = Indexmap::TaskRunner.new(configuration: configuration).write_index_now_key(generate_if_missing: true)
87
+
88
+ assert_match(/\A[a-f0-9]{32}\.txt\z/, result)
89
+ assert_equal result.delete_suffix(".txt"), storage.read(result)
90
+ end
91
+
92
+ def test_format_passes_content_type_when_rewriting_sitemaps
93
+ storage = KeywordContentTypeStorage.new
94
+ storage.write("sitemap.xml", <<~XML, content_type: "application/xml")
95
+ <?xml version="1.0" encoding="UTF-8"?>
96
+ <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><url><loc>https://example.com/about</loc></url></urlset>
97
+ XML
98
+ configuration = configuration_with(storage: storage)
99
+
100
+ result = Indexmap::TaskRunner.new(configuration: configuration).format
101
+
102
+ assert_equal ["sitemap.xml"], result
103
+ assert_equal "application/xml", storage.read_file("sitemap.xml").content_type
104
+ assert_includes storage.read("sitemap.xml"), "\n <url>"
105
+ end
106
+
107
+ private
108
+
109
+ def configuration_with(storage: Indexmap::Storage::Memory.new)
110
+ Indexmap::Configuration.new.tap do |configuration|
65
111
  configuration.base_url = "https://example.com"
66
- configuration.public_path = Pathname(dir)
112
+ configuration.storage = storage
67
113
  configuration.sections = [
68
114
  Indexmap::Section.new(
69
115
  filename: "sitemap-pages.xml",
70
116
  entries: [Indexmap::Entry.new(loc: "https://example.com/about")]
71
117
  )
72
118
  ]
73
-
74
- result = Indexmap::TaskRunner.new(configuration: configuration).write_index_now_key
75
-
76
- assert_nil result
77
- end
78
- end
79
-
80
- def test_write_index_now_key_can_generate_a_key_when_requested
81
- Dir.mktmpdir do |dir|
82
- configuration = Indexmap::Configuration.new
83
- configuration.base_url = "https://example.com"
84
- configuration.public_path = Pathname(dir)
85
-
86
- result = Indexmap::TaskRunner.new(configuration: configuration).write_index_now_key(generate_if_missing: true)
87
-
88
- assert_match(/\A[a-f0-9]{32}\.txt\z/, result.basename.to_s)
89
- assert_equal result.basename(".txt").to_s, result.read
90
119
  end
91
120
  end
92
121
  end
@@ -4,115 +4,82 @@ require "test_helper"
4
4
 
5
5
  class IndexmapValidatorTest < Minitest::Test
6
6
  def test_validate_raises_for_missing_sitemap
7
- Dir.mktmpdir do |directory|
8
- path = Pathname(directory).join("missing.xml")
9
-
10
- error = assert_raises(Indexmap::ValidationError) do
11
- Indexmap::Validator.new(path: path).validate!
12
- end
13
-
14
- assert_equal "Missing sitemap file: #{path}", error.message
7
+ error = assert_raises(Indexmap::ValidationError) do
8
+ Indexmap::Validator.new(configuration: configuration_with).validate!
15
9
  end
10
+
11
+ assert_equal "Missing sitemap file: sitemap.xml", error.message
16
12
  end
17
13
 
18
14
  def test_validate_raises_for_duplicate_urls
19
- Dir.mktmpdir do |directory|
20
- path = Pathname(directory).join("sitemap.xml")
21
- path.write(<<~XML)
15
+ error = assert_raises(Indexmap::ValidationError) do
16
+ validate_sitemap(<<~XML)
22
17
  <?xml version="1.0" encoding="UTF-8"?>
23
18
  <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
24
19
  <url><loc>https://example.com/about</loc></url>
25
20
  <url><loc>https://example.com/about</loc></url>
26
21
  </urlset>
27
22
  XML
28
-
29
- error = assert_raises(Indexmap::ValidationError) do
30
- Indexmap::Validator.new(path: path).validate!
31
- end
32
-
33
- assert_equal "Duplicate sitemap URLs detected: https://example.com/about", error.message
34
23
  end
24
+
25
+ assert_equal "Duplicate sitemap URLs detected: https://example.com/about", error.message
35
26
  end
36
27
 
37
28
  def test_validate_raises_for_parameterized_urls
38
- Dir.mktmpdir do |directory|
39
- path = Pathname(directory).join("sitemap.xml")
40
- path.write(<<~XML)
29
+ error = assert_raises(Indexmap::ValidationError) do
30
+ validate_sitemap(<<~XML)
41
31
  <?xml version="1.0" encoding="UTF-8"?>
42
32
  <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
43
33
  <url><loc>https://example.com/about?ref=test</loc></url>
44
34
  </urlset>
45
35
  XML
46
-
47
- error = assert_raises(Indexmap::ValidationError) do
48
- Indexmap::Validator.new(path: path).validate!
49
- end
50
-
51
- assert_equal "Parameterized sitemap URLs detected: https://example.com/about?ref=test", error.message
52
36
  end
37
+
38
+ assert_equal "Parameterized sitemap URLs detected: https://example.com/about?ref=test", error.message
53
39
  end
54
40
 
55
41
  def test_validate_raises_for_fragment_urls
56
- Dir.mktmpdir do |directory|
57
- path = Pathname(directory).join("sitemap.xml")
58
- path.write(<<~XML)
42
+ error = assert_raises(Indexmap::ValidationError) do
43
+ validate_sitemap(<<~XML)
59
44
  <?xml version="1.0" encoding="UTF-8"?>
60
45
  <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
61
46
  <url><loc>https://example.com/about#team</loc></url>
62
47
  </urlset>
63
48
  XML
64
-
65
- error = assert_raises(Indexmap::ValidationError) do
66
- Indexmap::Validator.new(path: path).validate!
67
- end
68
-
69
- assert_equal "Fragment sitemap URLs detected: https://example.com/about#team", error.message
70
49
  end
50
+
51
+ assert_equal "Fragment sitemap URLs detected: https://example.com/about#team", error.message
71
52
  end
72
53
 
73
54
  def test_validate_raises_for_relative_urls
74
- Dir.mktmpdir do |directory|
75
- path = Pathname(directory).join("sitemap.xml")
76
- path.write(<<~XML)
55
+ error = assert_raises(Indexmap::ValidationError) do
56
+ validate_sitemap(<<~XML)
77
57
  <?xml version="1.0" encoding="UTF-8"?>
78
58
  <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
79
59
  <url><loc>/about</loc></url>
80
60
  </urlset>
81
61
  XML
82
-
83
- error = assert_raises(Indexmap::ValidationError) do
84
- Indexmap::Validator.new(path: path).validate!
85
- end
86
-
87
- assert_equal "Invalid sitemap URLs detected: /about", error.message
88
62
  end
63
+
64
+ assert_equal "Invalid sitemap URLs detected: /about", error.message
89
65
  end
90
66
 
91
67
  def test_validate_raises_for_urls_outside_configured_base_url
92
- Dir.mktmpdir do |directory|
93
- path = Pathname(directory).join("sitemap.xml")
94
- path.write(<<~XML)
68
+ error = assert_raises(Indexmap::ValidationError) do
69
+ validate_sitemap(<<~XML)
95
70
  <?xml version="1.0" encoding="UTF-8"?>
96
71
  <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
97
72
  <url><loc>https://other.example.com/about</loc></url>
98
73
  </urlset>
99
74
  XML
100
-
101
- configuration = Indexmap::Configuration.new
102
- configuration.base_url = "https://example.com"
103
-
104
- error = assert_raises(Indexmap::ValidationError) do
105
- Indexmap::Validator.new(configuration: configuration, path: path).validate!
106
- end
107
-
108
- assert_equal "Sitemap URLs outside configured base URL detected: https://other.example.com/about", error.message
109
75
  end
76
+
77
+ assert_equal "Sitemap URLs outside configured base URL detected: https://other.example.com/about", error.message
110
78
  end
111
79
 
112
80
  def test_validate_raises_for_invalid_lastmod_values
113
- Dir.mktmpdir do |directory|
114
- path = Pathname(directory).join("sitemap.xml")
115
- path.write(<<~XML)
81
+ error = assert_raises(Indexmap::ValidationError) do
82
+ validate_sitemap(<<~XML)
116
83
  <?xml version="1.0" encoding="UTF-8"?>
117
84
  <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
118
85
  <url>
@@ -121,62 +88,99 @@ class IndexmapValidatorTest < Minitest::Test
121
88
  </url>
122
89
  </urlset>
123
90
  XML
124
-
125
- error = assert_raises(Indexmap::ValidationError) do
126
- Indexmap::Validator.new(path: path).validate!
127
- end
128
-
129
- assert_equal "Invalid sitemap lastmod values detected: https://example.com/about", error.message
130
91
  end
92
+
93
+ assert_equal "Invalid sitemap lastmod values detected: https://example.com/about", error.message
131
94
  end
132
95
 
133
96
  def test_validate_raises_for_empty_sitemaps
134
- Dir.mktmpdir do |directory|
135
- path = Pathname(directory).join("sitemap.xml")
136
- path.write(<<~XML)
97
+ error = assert_raises(Indexmap::ValidationError) do
98
+ validate_sitemap(<<~XML)
137
99
  <?xml version="1.0" encoding="UTF-8"?>
138
100
  <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
139
101
  </urlset>
140
102
  XML
141
-
142
- error = assert_raises(Indexmap::ValidationError) do
143
- Indexmap::Validator.new(path: path).validate!
144
- end
145
-
146
- assert_equal "Sitemap has no URLs: #{path}", error.message
147
103
  end
104
+
105
+ assert_equal "Sitemap has no URLs: sitemap.xml", error.message
148
106
  end
149
107
 
150
108
  def test_validate_raises_for_missing_child_sitemap_files
151
- Dir.mktmpdir do |directory|
152
- path = Pathname(directory).join("sitemap.xml")
153
- child_path = Pathname(directory).join("sitemap-pages.xml")
154
- path.write(<<~XML)
109
+ error = assert_raises(Indexmap::ValidationError) do
110
+ validate_sitemap(<<~XML)
155
111
  <?xml version="1.0" encoding="UTF-8"?>
156
112
  <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
157
113
  <sitemap><loc>https://example.com/sitemap-pages.xml</loc></sitemap>
158
114
  </sitemapindex>
159
115
  XML
116
+ end
160
117
 
161
- error = assert_raises(Indexmap::ValidationError) do
162
- Indexmap::Validator.new(path: path).validate!
163
- end
118
+ assert_equal "Missing child sitemap file: sitemap-pages.xml", error.message
119
+ end
164
120
 
165
- assert_equal "Missing child sitemap file: #{child_path}", error.message
166
- end
121
+ def test_validate_preserves_directory_keys_for_child_sitemap_files
122
+ storage = Indexmap::Storage::Memory.new
123
+ storage.write("sitemaps/sitemap.xml", <<~XML)
124
+ <?xml version="1.0" encoding="UTF-8"?>
125
+ <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
126
+ <sitemap><loc>https://example.com/sitemaps/sitemap-pages.xml</loc></sitemap>
127
+ </sitemapindex>
128
+ XML
129
+ storage.write("sitemaps/sitemap-pages.xml", <<~XML)
130
+ <?xml version="1.0" encoding="UTF-8"?>
131
+ <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
132
+ <url><loc>https://example.com/about</loc></url>
133
+ </urlset>
134
+ XML
135
+
136
+ assert Indexmap::Validator.new(
137
+ configuration: configuration_with(storage: storage, index_filename: "sitemaps/sitemap.xml")
138
+ ).validate!
139
+ end
140
+
141
+ def test_validate_resolves_relative_child_sitemaps_from_parent_directory
142
+ storage = Indexmap::Storage::Memory.new
143
+ storage.write("sitemaps/sitemap.xml", <<~XML)
144
+ <?xml version="1.0" encoding="UTF-8"?>
145
+ <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
146
+ <sitemap><loc>sitemap-pages.xml</loc></sitemap>
147
+ </sitemapindex>
148
+ XML
149
+ storage.write("sitemaps/sitemap-pages.xml", <<~XML)
150
+ <?xml version="1.0" encoding="UTF-8"?>
151
+ <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
152
+ <url><loc>https://example.com/about</loc></url>
153
+ </urlset>
154
+ XML
155
+
156
+ assert Indexmap::Validator.new(
157
+ configuration: configuration_with(storage: storage, index_filename: "sitemaps/sitemap.xml")
158
+ ).validate!
167
159
  end
168
160
 
169
161
  def test_validate_passes_for_valid_sitemap
170
- Dir.mktmpdir do |directory|
171
- path = Pathname(directory).join("sitemap.xml")
172
- path.write(<<~XML)
173
- <?xml version="1.0" encoding="UTF-8"?>
174
- <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
175
- <url><loc>https://example.com/about</loc></url>
176
- </urlset>
177
- XML
162
+ assert validate_sitemap(<<~XML)
163
+ <?xml version="1.0" encoding="UTF-8"?>
164
+ <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
165
+ <url><loc>https://example.com/about</loc></url>
166
+ </urlset>
167
+ XML
168
+ end
178
169
 
179
- assert Indexmap::Validator.new(path: path).validate!
170
+ private
171
+
172
+ def validate_sitemap(body)
173
+ storage = Indexmap::Storage::Memory.new
174
+ storage.write("sitemap.xml", body)
175
+
176
+ Indexmap::Validator.new(configuration: configuration_with(storage: storage)).validate!
177
+ end
178
+
179
+ def configuration_with(storage: Indexmap::Storage::Memory.new, index_filename: "sitemap.xml")
180
+ Indexmap::Configuration.new.tap do |configuration|
181
+ configuration.base_url = "https://example.com"
182
+ configuration.index_filename = index_filename
183
+ configuration.storage = storage
180
184
  end
181
185
  end
182
186
  end
@@ -3,97 +3,86 @@
3
3
  require "test_helper"
4
4
 
5
5
  class IndexmapWriterTest < Minitest::Test
6
- def test_writes_sitemap_index_and_child_sitemap
7
- Dir.mktmpdir do |directory|
8
- sections = [
9
- Indexmap::Section.new(
10
- filename: "sitemap-pages.xml",
11
- entries: [
12
- Indexmap::Entry.new(loc: "https://example.com/", lastmod: Date.new(2026, 4, 21)),
13
- Indexmap::Entry.new(loc: "https://example.com/pricing", lastmod: Time.utc(2026, 4, 22, 10, 30, 0))
14
- ]
15
- )
16
- ]
6
+ def test_writes_sitemap_index_and_child_sitemap_documents
7
+ sections = [
8
+ Indexmap::Section.new(
9
+ filename: "sitemap-pages.xml",
10
+ entries: [
11
+ Indexmap::Entry.new(loc: "https://example.com/", lastmod: Date.new(2026, 4, 21)),
12
+ Indexmap::Entry.new(loc: "https://example.com/pricing", lastmod: Time.utc(2026, 4, 22, 10, 30, 0))
13
+ ]
14
+ )
15
+ ]
17
16
 
18
- Indexmap::Writer.new(
19
- sections: sections,
20
- public_path: directory,
21
- base_url: "https://example.com"
22
- ).write
17
+ files = Indexmap::Writer.new(
18
+ sections: sections,
19
+ base_url: "https://example.com"
20
+ ).write
23
21
 
24
- index_xml = File.read(File.join(directory, "sitemap.xml"))
25
- child_xml = File.read(File.join(directory, "sitemap-pages.xml"))
22
+ index_xml = files.find { |file| file.filename == "sitemap.xml" }.body
23
+ child_xml = files.find { |file| file.filename == "sitemap-pages.xml" }.body
26
24
 
27
- assert_includes index_xml, "<loc>https://example.com/sitemap-pages.xml</loc>"
28
- assert_includes child_xml, "<loc>https://example.com/</loc>"
29
- assert_includes child_xml, "<loc>https://example.com/pricing</loc>"
30
- assert_includes child_xml, "<lastmod>2026-04-21</lastmod>"
31
- assert_includes child_xml, "<lastmod>2026-04-22T10:30:00Z</lastmod>"
32
- end
25
+ assert_includes index_xml, "<loc>https://example.com/sitemap-pages.xml</loc>"
26
+ assert_includes child_xml, "<loc>https://example.com/</loc>"
27
+ assert_includes child_xml, "<loc>https://example.com/pricing</loc>"
28
+ assert_includes child_xml, "<lastmod>2026-04-21</lastmod>"
29
+ assert_includes child_xml, "<lastmod>2026-04-22T10:30:00Z</lastmod>"
33
30
  end
34
31
 
35
32
  def test_accepts_hash_based_sections_and_entries
36
- Dir.mktmpdir do |directory|
37
- Indexmap::Writer.new(
38
- sections: [
39
- {
40
- filename: "sitemap-pages.xml",
41
- entries: [
42
- {loc: "https://example.com/about", lastmod: "2026-04-20T09:15:00Z"}
43
- ]
44
- }
45
- ],
46
- public_path: directory,
47
- base_url: "https://example.com"
48
- ).write
33
+ files = Indexmap::Writer.new(
34
+ sections: [
35
+ {
36
+ filename: "sitemap-pages.xml",
37
+ entries: [
38
+ {loc: "https://example.com/about", lastmod: "2026-04-20T09:15:00Z"}
39
+ ]
40
+ }
41
+ ],
42
+ base_url: "https://example.com"
43
+ ).write
49
44
 
50
- child_xml = File.read(File.join(directory, "sitemap-pages.xml"))
45
+ child_xml = files.find { |file| file.filename == "sitemap-pages.xml" }.body
51
46
 
52
- assert_includes child_xml, "<loc>https://example.com/about</loc>"
53
- assert_includes child_xml, "<lastmod>2026-04-20T09:15:00Z</lastmod>"
54
- end
47
+ assert_includes child_xml, "<loc>https://example.com/about</loc>"
48
+ assert_includes child_xml, "<lastmod>2026-04-20T09:15:00Z</lastmod>"
55
49
  end
56
50
 
57
51
  def test_writes_single_file_urlset
58
- Dir.mktmpdir do |directory|
59
- Indexmap::Writer.new(
60
- format: :single_file,
61
- entries: [
62
- Indexmap::Entry.new(loc: "https://example.com/", lastmod: Date.new(2026, 4, 21)),
63
- {loc: "https://example.com/about", lastmod: "2026-04-22T09:15:00Z"}
64
- ],
65
- public_path: directory,
66
- base_url: "https://example.com"
67
- ).write
52
+ files = Indexmap::Writer.new(
53
+ format: :single_file,
54
+ entries: [
55
+ Indexmap::Entry.new(loc: "https://example.com/", lastmod: Date.new(2026, 4, 21)),
56
+ {loc: "https://example.com/about", lastmod: "2026-04-22T09:15:00Z"}
57
+ ],
58
+ base_url: "https://example.com"
59
+ ).write
68
60
 
69
- sitemap_xml = File.read(File.join(directory, "sitemap.xml"))
61
+ sitemap_xml = files.fetch(0).body
70
62
 
71
- assert_includes sitemap_xml, "<urlset"
72
- assert_includes sitemap_xml, "<loc>https://example.com/</loc>"
73
- assert_includes sitemap_xml, "<loc>https://example.com/about</loc>"
74
- assert_includes sitemap_xml, "<lastmod>2026-04-21</lastmod>"
75
- assert_includes sitemap_xml, "<lastmod>2026-04-22T09:15:00Z</lastmod>"
76
- refute_includes sitemap_xml, "<sitemapindex"
77
- refute File.exist?(File.join(directory, "sitemap-pages.xml"))
78
- end
63
+ assert_equal 1, files.size
64
+ assert_equal "sitemap.xml", files.fetch(0).filename
65
+ assert_includes sitemap_xml, "<urlset"
66
+ assert_includes sitemap_xml, "<loc>https://example.com/</loc>"
67
+ assert_includes sitemap_xml, "<loc>https://example.com/about</loc>"
68
+ assert_includes sitemap_xml, "<lastmod>2026-04-21</lastmod>"
69
+ assert_includes sitemap_xml, "<lastmod>2026-04-22T09:15:00Z</lastmod>"
70
+ refute_includes sitemap_xml, "<sitemapindex"
79
71
  end
80
72
 
81
73
  def test_omits_sitemap_index_lastmod_when_sections_have_no_lastmod
82
- Dir.mktmpdir do |directory|
83
- Indexmap::Writer.new(
84
- sections: [
85
- Indexmap::Section.new(
86
- filename: "sitemap-pages.xml",
87
- entries: [Indexmap::Entry.new(loc: "https://example.com/about")]
88
- )
89
- ],
90
- public_path: directory,
91
- base_url: "https://example.com"
92
- ).write
74
+ files = Indexmap::Writer.new(
75
+ sections: [
76
+ Indexmap::Section.new(
77
+ filename: "sitemap-pages.xml",
78
+ entries: [Indexmap::Entry.new(loc: "https://example.com/about")]
79
+ )
80
+ ],
81
+ base_url: "https://example.com"
82
+ ).write
93
83
 
94
- index_xml = File.read(File.join(directory, "sitemap.xml"))
84
+ index_xml = files.find { |file| file.filename == "sitemap.xml" }.body
95
85
 
96
- refute_includes index_xml, "<lastmod>"
97
- end
86
+ refute_includes index_xml, "<lastmod>"
98
87
  end
99
88
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: indexmap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paulo Fidalgo
@@ -183,12 +183,15 @@ files:
183
183
  - lib/indexmap/index_now_configuration.rb
184
184
  - lib/indexmap/output.rb
185
185
  - lib/indexmap/parser.rb
186
- - lib/indexmap/path.rb
187
186
  - lib/indexmap/pinger/base.rb
188
187
  - lib/indexmap/pinger/google.rb
189
188
  - lib/indexmap/pinger/index_now.rb
190
189
  - lib/indexmap/railtie.rb
191
190
  - lib/indexmap/section.rb
191
+ - lib/indexmap/storage/active_storage.rb
192
+ - lib/indexmap/storage/file.rb
193
+ - lib/indexmap/storage/filesystem.rb
194
+ - lib/indexmap/storage/memory.rb
192
195
  - lib/indexmap/task_runner.rb
193
196
  - lib/indexmap/validator.rb
194
197
  - lib/indexmap/version.rb
@@ -196,9 +199,9 @@ files:
196
199
  - lib/tasks/indexmap_tasks.rake
197
200
  - test/indexmap/configuration_test.rb
198
201
  - test/indexmap/parser_test.rb
199
- - test/indexmap/path_test.rb
200
202
  - test/indexmap/pinger/google_test.rb
201
203
  - test/indexmap/pinger/index_now_test.rb
204
+ - test/indexmap/storage_test.rb
202
205
  - test/indexmap/task_runner_test.rb
203
206
  - test/indexmap/validator_test.rb
204
207
  - test/indexmap/writer_test.rb