mirror of
https://github.com/mastodon/mastodon.git
synced 2024-12-30 15:05:01 +01:00
46 lines
1.1 KiB
Ruby
46 lines
1.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'rails_helper'
|
|
|
|
RSpec.describe Api::V1::Trends::LinksController do
|
|
render_views
|
|
|
|
describe 'GET #index' do
|
|
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::V1::Trends::LinksController::DEFAULT_LINKS_LIMIT', 2)
|
|
get :index
|
|
|
|
expect(response).to have_http_status(200)
|
|
expect(response.headers).to include('Link')
|
|
end
|
|
|
|
def prepare_trends
|
|
Fabricate.times(3, :preview_card, trendable: true, language: 'en').each do |link|
|
|
2.times { |i| Trends.links.add(link, i) }
|
|
end
|
|
Trends::Links.new(threshold: 1).refresh
|
|
end
|
|
end
|
|
end
|
|
end
|