Add Deprecation headers on deprecated endpoints (#34262)

Co-authored-by: Damien Mathieu <42@dmathieu.com>
This commit is contained in:
Claire 2025-03-25 13:30:10 +01:00 committed by GitHub
parent 40bb8ec325
commit 38f5e74122
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 121 additions and 12 deletions

View file

@ -15,6 +15,8 @@ RSpec.describe 'API V1 Trends Tags' do
.and not_have_http_link_header
expect(response.content_type)
.to start_with('application/json')
expect(response.headers['Deprecation'])
.to be_nil
end
end
@ -31,6 +33,8 @@ RSpec.describe 'API V1 Trends Tags' do
.and have_http_link_header(api_v1_trends_tags_url(offset: 2)).for(rel: 'next')
expect(response.content_type)
.to start_with('application/json')
expect(response.headers['Deprecation'])
.to be_nil
end
def prepare_trends

View file

@ -0,0 +1,48 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe 'deprecated API V1 Trends Tags' do
describe 'GET /api/v1/trends' do
context 'when trends are disabled' do
before { Setting.trends = false }
it 'returns http success' do
get '/api/v1/trends'
expect(response)
.to have_http_status(200)
.and not_have_http_link_header
expect(response.content_type)
.to start_with('application/json')
expect(response.headers['Deprecation'])
.to start_with '@'
end
end
context 'when trends are enabled' do
before { Setting.trends = true }
it 'returns http success' do
prepare_trends
stub_const('Api::V1::Trends::TagsController::DEFAULT_TAGS_LIMIT', 2)
get '/api/v1/trends'
expect(response)
.to have_http_status(200)
.and have_http_link_header(api_v1_trends_tags_url(offset: 2)).for(rel: 'next')
expect(response.content_type)
.to start_with('application/json')
expect(response.headers['Deprecation'])
.to start_with '@'
end
def prepare_trends
Fabricate.times(3, :tag, trendable: true).each do |tag|
2.times { |i| Trends.tags.add(tag, i) }
end
Trends::Tags.new(threshold: 1).refresh
end
end
end
end