require_relative "helper" context "Precious::Views::RSS" do # Simplistically 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 "", feed assert_match //m, feed assert_match /(.*)<\/channel>/m, feed # Assert that we have feed metadata. # assert_match "Wiki Name Latest Changes", feed assert_match "https://example.com/gollum/latest_changes", feed assert_match "Latest Changes in Wiki Name", feed assert_match /(.*)<\/pubDate>/, feed # Assert that we have an item in our feed. # assert_match /(.*)<\/item>/m, feed # And it has a title. # assert_match "Multi-line commit message", feed # Assert that the description contains expected content. # assert_match /(.*)<\/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.: # # committer name # # 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.: # # new # assert_match /Affected files: /, feed assert_match /\<a href=\"https:\/\/example.com\/old\/f0f0f0f0\"/, feed assert_match /f0f0f0f0">new<\/a>/, feed end end