| 1 | # frozen_string_literal: true |
| 2 | |
| 3 | require "rails_helper" |
| 4 | |
| 5 | # The public changelog: an index at /changelog and one page per release at |
| 6 | # /changelog/vX.Y.Z, sourced from config/changelog/*.md via Changelog. |
| 7 | RSpec.describe "Changelog", type: :request do |
| 8 | describe "GET /changelog" do |
| 9 | before { get "/changelog" } |
| 10 | |
| 11 | it "renders the index" do |
| 12 | expect(response).to have_http_status(:ok) |
| 13 | end |
| 14 | |
| 15 | it "lists the shipped releases with links to their pages" do |
| 16 | Changelog.all.each do |entry| |
| 17 | expect(response.body).to include(entry.tag) |
| 18 | expect(response.body).to include("/changelog/#{entry.tag}") |
| 19 | end |
| 20 | end |
| 21 | end |
| 22 | |
| 23 | describe "GET /changelog/:version" do |
| 24 | let(:entry) { Changelog.latest } |
| 25 | |
| 26 | it "renders the release page with its rendered body" do |
| 27 | get "/changelog/#{entry.tag}" |
| 28 | |
| 29 | expect(response).to have_http_status(:ok) |
| 30 | expect(response.body).to include(entry.tag) |
| 31 | expect(response.body).to include(entry.title) if entry.title.present? |
| 32 | end |
| 33 | |
| 34 | it "renders the Markdown body as HTML, not escaped source" do |
| 35 | get "/changelog/#{entry.tag}" |
| 36 | |
| 37 | # The v1.0.0 entry has an H2; it must appear as a real heading tag, and |
| 38 | # never as escaped angle brackets. |
| 39 | expect(response.body).to include("<h2") |
| 40 | expect(response.body).not_to include("<h2") |
| 41 | end |
| 42 | |
| 43 | it "404s an unknown but well-formed version" do |
| 44 | get "/changelog/v9.9.9" |
| 45 | expect(response).to have_http_status(:not_found) |
| 46 | end |
| 47 | |
| 48 | it "does not treat a malformed version as a changelog page" do |
| 49 | # The route constraint rejects non-semver slugs, so "/changelog/latest" |
| 50 | # falls through to the profile matcher rather than the changelog show. |
| 51 | get "/changelog/latest" |
| 52 | expect(response).not_to have_http_status(:ok) |
| 53 | end |
| 54 | end |
| 55 | |
| 56 | describe "the footer" do |
| 57 | it "links the version to its changelog page on every layout render" do |
| 58 | get "/" |
| 59 | expect(response.body).to include("/changelog/v#{Sigitsi::VERSION}") |
| 60 | end |
| 61 | end |
| 62 | |
| 63 | describe "the sitemap" do |
| 64 | it "includes the changelog index and each release" do |
| 65 | get "/sitemap.xml" |
| 66 | expect(response.body).to include("/changelog") |
| 67 | Changelog.all.each do |entry| |
| 68 | expect(response.body).to include("/changelog/#{entry.tag}") |
| 69 | end |
| 70 | end |
| 71 | end |
| 72 | end |