2023-03-05 03:12:54 +11:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
2023-11-14 01:32:36 +11:00
|
|
|
RSpec.describe Api::V1::Trends::StatusesController do
|
2023-03-05 03:12:54 +11:00
|
|
|
render_views
|
|
|
|
|
|
|
|
describe 'GET #index' do
|
2023-11-14 01:32:36 +11:00
|
|
|
around do |example|
|
|
|
|
previous = Setting.trends
|
|
|
|
example.run
|
|
|
|
Setting.trends = previous
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when trends are disabled' do
|
|
|
|
before { Setting.trends = false }
|
|
|
|
|
|
|
|
it 'returns http success' do
|
|
|
|
get :index
|
|
|
|
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when trends are enabled' do
|
|
|
|
before { Setting.trends = true }
|
|
|
|
|
|
|
|
it 'returns http success' do
|
|
|
|
prepare_trends
|
|
|
|
stub_const('Api::BaseController::DEFAULT_STATUSES_LIMIT', 2)
|
|
|
|
get :index
|
|
|
|
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
expect(response.headers).to include('Link')
|
|
|
|
end
|
2023-03-05 03:12:54 +11:00
|
|
|
|
2023-11-14 01:32:36 +11:00
|
|
|
def prepare_trends
|
|
|
|
Fabricate.times(3, :status, trendable: true, language: 'en').each do |status|
|
|
|
|
2.times { |i| Trends.statuses.add(status, i) }
|
|
|
|
end
|
|
|
|
Trends::Statuses.new(threshold: 1, decay_threshold: -1).refresh
|
|
|
|
end
|
2023-03-05 03:12:54 +11:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|