From 86b45a4a4832ef5e6fe54b5c7441ea8afc9b5c2d Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Thu, 5 Dec 2024 06:34:49 -0500 Subject: [PATCH] Add rel alternate rss/json links to tags show html page (#33179) --- app/views/tags/show.html.haml | 2 ++ spec/requests/tags_spec.rb | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/app/views/tags/show.html.haml b/app/views/tags/show.html.haml index 4b4967a8f5..bce1b4aa4d 100644 --- a/app/views/tags/show.html.haml +++ b/app/views/tags/show.html.haml @@ -1,4 +1,6 @@ - content_for :header_tags do + %link{ rel: :alternate, type: 'application/rss+xml', href: tag_url(@tag) }/ + %link{ rel: :alternate, type: 'application/activity+json', href: tag_url(@tag) }/ %meta{ name: 'robots', content: 'noindex' }/ = render partial: 'shared/og' diff --git a/spec/requests/tags_spec.rb b/spec/requests/tags_spec.rb index fbd1f7d56e..f04d1bc2d3 100644 --- a/spec/requests/tags_spec.rb +++ b/spec/requests/tags_spec.rb @@ -7,6 +7,29 @@ RSpec.describe 'Tags' do context 'when tag exists' do let(:tag) { Fabricate :tag } + context 'with HTML format' do + before { get tag_path(tag) } + + it 'returns page with links to alternate resources' do + expect(rss_links.first[:href]) + .to eq(tag_url(tag)) + expect(activity_json_links.first[:href]) + .to eq(tag_url(tag)) + end + + def rss_links + alternate_links.css('[type="application/rss+xml"]') + end + + def activity_json_links + alternate_links.css('[type="application/activity+json"]') + end + + def alternate_links + response.parsed_body.css('link[rel=alternate]') + end + end + context 'with JSON format' do before { get tag_path(tag, format: :json) }