Refactor RSS view renderer
In issue #1815, it was reported that Gollum RSS feeds attempt to put entire commit messages into a feed item's `<title>` element. Given that commit messages can be many paragraphs long, this is not an acceptable way to render a feed item title. If a commit has many lines or paragraphs, we now put those inside the `<description>` element as of this commit. While I was editing this view, I decided it would be a good time to increase test coverage, as this view renderer was not under test at all. I also fixed a typo ("Commited" should say "Committed"). There are implicit dependencies on other gems that provide the `Gollum::Git::Commit`, `Gollum::Git::Actor`, and `Rugged::Commit` classes here, so mocking out simple versions of their interfaces seemed like the path of least resistance to setting up controllable tests. I also removed some now-duplicated assertions from `test/test_app.rb`.
This commit is contained in:
committed by
benjamin wil
parent
738d6f6ec4
commit
10ae969139
@@ -0,0 +1,101 @@
|
||||
require_relative "helper"
|
||||
|
||||
context "Precious::Views::RSS" do
|
||||
# Simplisticially mimics a `Gollum::Git::Actor` object.
|
||||
#
|
||||
MockAuthor = Struct.new(:name, :email)
|
||||
|
||||
# Simplistically mimics a `Gollum::Git::Commit` object.
|
||||
#
|
||||
MockChange = Class.new do
|
||||
def author
|
||||
MockAuthor.new("committer name", "email@example.com")
|
||||
end
|
||||
|
||||
def authored_date
|
||||
Time.new(1999, 01, 01, 0, 0)
|
||||
end
|
||||
|
||||
def files
|
||||
["file 1", "file 2"]
|
||||
end
|
||||
|
||||
def id
|
||||
"f0f0f0f0"
|
||||
end
|
||||
|
||||
def message
|
||||
<<~COMMIT_MESSAGE
|
||||
Multi-line commit message
|
||||
|
||||
This commit is multiple lines long so we can test how this is
|
||||
rendered in the feed.
|
||||
|
||||
Git's documentation says that the first line of a commit should
|
||||
be 50 characters or fewer, and the rest of the commit body's
|
||||
lines should not exceed 72 characters in length.
|
||||
COMMIT_MESSAGE
|
||||
end
|
||||
|
||||
def stats
|
||||
OpenStruct.new(files: [{old_file: "old", new_file: "new"}])
|
||||
end
|
||||
end
|
||||
|
||||
test "renders a valid RSS feed" do
|
||||
feed = RSSView.new(
|
||||
"/",
|
||||
"Wiki Name",
|
||||
"https://example.com",
|
||||
[MockChange.new]
|
||||
).render
|
||||
|
||||
# Assert that we have required RSS feed elements.
|
||||
#
|
||||
assert_match "<?xml version=\"1.0\" encoding=\"UTF-8\"?>", feed
|
||||
assert_match /<rss version=\"2.0\"(.*)<\/rss>/m, feed
|
||||
assert_match /<channel>(.*)<\/channel>/m, feed
|
||||
|
||||
# Assert that we have feed metadata.
|
||||
#
|
||||
assert_match "<title>Wiki Name Latest Changes</title>", feed
|
||||
assert_match "<link>https://example.com/gollum/latest_changes</link>", feed
|
||||
assert_match "<description>Latest Changes in Wiki Name</description>", feed
|
||||
assert_match /<pubDate>(.*)<\/pubDate>/, feed
|
||||
|
||||
# Assert that we have an item in our feed.
|
||||
#
|
||||
assert_match /<item>(.*)<\/item>/m, feed
|
||||
|
||||
# And it has a title.
|
||||
#
|
||||
assert_match "<title>Multi-line commit message</title>", feed
|
||||
|
||||
# Assert that the description contains expected content.
|
||||
#
|
||||
assert_match /<description>(.*)<\/description>/m, feed
|
||||
assert_match /<p> This commit(.*)<\/p>/, feed
|
||||
assert_match /<p>Git's documentation(.*)<\/p>/, feed
|
||||
|
||||
# Assert that the description contains information about the commit.
|
||||
# i.e.:
|
||||
#
|
||||
# <a href="mailto:email@example.com">committer name</a>
|
||||
#
|
||||
# Commit ID: f0f0f0f0
|
||||
#
|
||||
assert_match /Committed by: /, feed
|
||||
assert_match /\<a href=\"mailto:email@example.com\"\>/, feed
|
||||
assert_match /\>\n committer name\n\<\/a>/, feed
|
||||
assert_match "Commit ID: f0f0f0f", feed
|
||||
|
||||
# Assert that affected files include links to commits, i.e.:
|
||||
#
|
||||
# <a href="https://example.com/old/f0f0f0f0">new</a>
|
||||
#
|
||||
assert_match /Affected files: /, feed
|
||||
assert_match /\<a href=\"https:\/\/example.com\/old\/f0f0f0f0\"/,
|
||||
feed
|
||||
assert_match /f0f0f0f0">new<\/a>/, feed
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user