Fix #5293: NoMethodError in sitemap when relation is empty.

This commit is contained in:
evazion
2022-10-14 19:49:21 -05:00
parent 2c3a254359
commit 9c48953e6f
3 changed files with 28 additions and 1 deletions

View File

@@ -74,11 +74,32 @@ Allow: /sitemap.xml
Allow: /favicon.ico
Allow: /favicon.svg
<% if Artist.undeleted.exists? %>
Sitemap: <%= sitemap_url(format: :xml, sitemap: "artists") %>
<% end %>
<% if ForumTopic.undeleted.exists? %>
Sitemap: <%= sitemap_url(format: :xml, sitemap: "forum_topics") %>
<% end %>
<% if Pool.undeleted.exists? %>
Sitemap: <%= sitemap_url(format: :xml, sitemap: "pools") %>
<% end %>
<% if Post.exists? %>
Sitemap: <%= sitemap_url(format: :xml, sitemap: "posts") %>
<% end %>
<% if Tag.nonempty.exists? %>
Sitemap: <%= sitemap_url(format: :xml, sitemap: "tags") %>
<% end %>
<% if User.exists? %>
Sitemap: <%= sitemap_url(format: :xml, sitemap: "users") %>
<% end %>
<% if WikiPage.undeleted.exists? %>
Sitemap: <%= sitemap_url(format: :xml, sitemap: "wiki_pages") %>
<% end %>
<% end %>

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<% 0.upto(@relation.maximum(:id) / @limit) do |page| %>
<% 0.upto(@relation.maximum(:id).to_i / @limit) do |page| %>
<% lo = page * @limit %>
<% hi = (page + 1) * @limit %>
<% lastmod = @relation.where(id: lo..hi).maximum(:updated_at)&.iso8601 %>

View File

@@ -23,6 +23,12 @@ class StaticControllerTest < ActionDispatch::IntegrationTest
assert_equal(1, response.parsed_body.css("sitemap loc").size)
end
end
should "work when the sitemap is empty" do
get sitemap_path(sitemap: "pools"), as: :xml
assert_response :success
end
end
context "dtext_help action" do