Merge commit '752d49eefef48262d501ba5fc2006d2c8466a000' into glitch-soc/merge-upstream

Conflicts:
- `app/lib/feed_manager.rb`:
  Upstream changed how notifications from follow subscriptions were handled,
  refactoring this file in the process.
  Conflict is due to glitch-soc having an extra timeline type (direct).
  Ported upstream's changes.
- `app/workers/feed_insert_worker.rb`:
  Ditto.
This commit is contained in:
Claire
2024-12-02 21:08:15 +01:00
133 changed files with 595 additions and 580 deletions

View File

@@ -171,6 +171,7 @@ RSpec.describe FeedManager do
allow(List).to receive(:where).and_return(list)
status = Fabricate(:status, text: 'I post a lot', account: bob)
expect(subject.filter?(:home, status, alice)).to be true
expect(subject.filter(:home, status, alice)).to be :skip_home
end
it 'returns true for reblog from followee on exclusive list' do
@@ -181,6 +182,7 @@ RSpec.describe FeedManager do
status = Fabricate(:status, text: 'I post a lot', account: bob)
reblog = Fabricate(:status, reblog: status, account: jeff)
expect(subject.filter?(:home, reblog, alice)).to be true
expect(subject.filter(:home, reblog, alice)).to be :skip_home
end
it 'returns false for post from followee on non-exclusive list' do

View File

@@ -3,20 +3,9 @@
require 'rails_helper'
RSpec.describe PreviewCardTrend do
include_examples 'RankedTrend'
describe 'Associations' do
it { is_expected.to belong_to(:preview_card).required }
end
describe '.locales' do
before do
Fabricate :preview_card_trend, language: 'en'
Fabricate :preview_card_trend, language: 'en'
Fabricate :preview_card_trend, language: 'es'
end
it 'returns unique set of languages' do
expect(described_class.locales)
.to eq(['en', 'es'])
end
end
end

View File

@@ -3,21 +3,10 @@
require 'rails_helper'
RSpec.describe StatusTrend do
include_examples 'RankedTrend'
describe 'Associations' do
it { is_expected.to belong_to(:account).required }
it { is_expected.to belong_to(:status).required }
end
describe '.locales' do
before do
Fabricate :status_trend, language: 'en'
Fabricate :status_trend, language: 'en'
Fabricate :status_trend, language: 'es'
end
it 'returns unique set of languages' do
expect(described_class.locales)
.to eq(['en', 'es'])
end
end
end

View File

@@ -135,6 +135,23 @@ RSpec.describe 'API V1 Push Subscriptions' do
end
end
describe 'GET /api/v1/push/subscription' do
subject { get '/api/v1/push/subscription', headers: headers }
before { create_subscription_with_token }
it 'shows subscription details' do
subject
expect(response)
.to have_http_status(200)
expect(response.content_type)
.to start_with('application/json')
expect(response.parsed_body)
.to include(endpoint: endpoint)
end
end
describe 'DELETE /api/v1/push/subscription' do
subject { delete '/api/v1/push/subscription', headers: headers }

View File

@@ -0,0 +1,55 @@
# frozen_string_literal: true
RSpec.shared_examples 'RankedTrend' do
describe 'Scopes' do
describe '.by_rank' do
let!(:lower_rank) { Fabricate factory_name, rank: 5 }
let!(:higher_rank) { Fabricate factory_name, rank: 50 }
it 'returns records ordered by rank' do
expect(described_class.by_rank)
.to eq([higher_rank, lower_rank])
end
end
describe '.ranked_below' do
let!(:low_rank) { Fabricate factory_name, rank: 5 }
let!(:med_rank) { Fabricate factory_name, rank: 50 }
let!(:high_rank) { Fabricate factory_name, rank: 500 }
it 'returns records ordered by rank' do
expect(described_class.ranked_below(100))
.to include(low_rank)
.and include(med_rank)
.and not_include(high_rank)
end
end
end
describe '.locales' do
before do
Fabricate.times 2, factory_name, language: 'en'
Fabricate factory_name, language: 'es'
end
it 'returns unique set of languages' do
expect(described_class.locales)
.to eq(['en', 'es'])
end
end
describe '.recalculate_ordered_rank' do
let!(:low_score) { Fabricate factory_name, score: 5, rank: 123 }
let!(:high_score) { Fabricate factory_name, score: 10, rank: 456 }
it 'ranks records based on their score' do
expect { described_class.recalculate_ordered_rank }
.to change { low_score.reload.rank }.to(2)
.and change { high_score.reload.rank }.to(1)
end
end
def factory_name
described_class.name.underscore.to_sym
end
end

View File

@@ -32,7 +32,7 @@ RSpec.describe FeedInsertWorker do
context 'when there are real records' do
it 'skips the push when there is a filter' do
instance = instance_double(FeedManager, push_to_home: nil, filter?: true)
instance = instance_double(FeedManager, push_to_home: nil, filter?: true, filter: :filter)
allow(FeedManager).to receive(:instance).and_return(instance)
result = subject.perform(status.id, follower.id)
@@ -41,7 +41,7 @@ RSpec.describe FeedInsertWorker do
end
it 'pushes the status onto the home timeline without filter' do
instance = instance_double(FeedManager, push_to_home: nil, filter?: false)
instance = instance_double(FeedManager, push_to_home: nil, filter?: false, filter: nil)
allow(FeedManager).to receive(:instance).and_return(instance)
result = subject.perform(status.id, follower.id, :home)
@@ -50,7 +50,7 @@ RSpec.describe FeedInsertWorker do
end
it 'pushes the status onto the tags timeline without filter' do
instance = instance_double(FeedManager, push_to_home: nil, filter?: false)
instance = instance_double(FeedManager, push_to_home: nil, filter?: false, filter: nil)
allow(FeedManager).to receive(:instance).and_return(instance)
result = subject.perform(status.id, follower.id, :tags)
@@ -59,7 +59,7 @@ RSpec.describe FeedInsertWorker do
end
it 'pushes the status onto the list timeline without filter' do
instance = instance_double(FeedManager, push_to_list: nil, filter?: false)
instance = instance_double(FeedManager, push_to_list: nil, filter?: false, filter: nil)
allow(FeedManager).to receive(:instance).and_return(instance)
result = subject.perform(status.id, list.id, :list)