Add rel alternate rss/json links to tags show html page (#33179)

This commit is contained in:
Matt Jankowski 2024-12-05 06:34:49 -05:00 committed by GitHub
parent 21f6780498
commit 86b45a4a48
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 0 deletions

View File

@ -1,4 +1,6 @@
- content_for :header_tags do - 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' }/ %meta{ name: 'robots', content: 'noindex' }/
= render partial: 'shared/og' = render partial: 'shared/og'

View File

@ -7,6 +7,29 @@ RSpec.describe 'Tags' do
context 'when tag exists' do context 'when tag exists' do
let(:tag) { Fabricate :tag } 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 context 'with JSON format' do
before { get tag_path(tag, format: :json) } before { get tag_path(tag, format: :json) }