Merge remote-tracking branch 'parent/main' into upstream-20241203
This commit is contained in:
commit
2d9124a3ab
214 changed files with 1763 additions and 3380 deletions
|
@ -165,6 +165,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
|
||||
|
@ -175,6 +176,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
|
||||
|
|
|
@ -57,5 +57,25 @@ RSpec.describe Sanitize::Config do
|
|||
it 'keeps a with supported scheme and no host' do
|
||||
expect(Sanitize.fragment('<a href="dweb:/a/foo">Test</a>', subject)).to eq '<a href="dweb:/a/foo" rel="nofollow noopener noreferrer" target="_blank">Test</a>'
|
||||
end
|
||||
|
||||
it 'sanitizes math to LaTeX' do
|
||||
mathml = '<math><semantics><mrow><msup><mi>x</mi><mi>n</mi></msup><mo>+</mo><mi>y</mi></mrow><annotation encoding="application/x-tex">x^n+y</annotation></semantics></math>'
|
||||
expect(Sanitize.fragment(mathml, subject)).to eq '$x^n+y$'
|
||||
end
|
||||
|
||||
it 'sanitizes math blocks to LaTeX' do
|
||||
mathml = '<math display="block"><semantics><mrow><msup><mi>x</mi><mi>n</mi></msup><mo>+</mo><mi>y</mi></mrow><annotation encoding="application/x-tex">x^n+y</annotation></semantics></math>'
|
||||
expect(Sanitize.fragment(mathml, subject)).to eq '$$x^n+y$$'
|
||||
end
|
||||
|
||||
it 'math sanitizer falls back to plaintext' do
|
||||
mathml = '<math><semantics><msqrt><mi>x</mi></msqrt><annotation encoding="text/plain">sqrt(x)</annotation></semantics></math>'
|
||||
expect(Sanitize.fragment(mathml, subject)).to eq 'sqrt(x)'
|
||||
end
|
||||
|
||||
it 'prefers latex' do
|
||||
mathml = '<math><semantics><msqrt><mi>x</mi></msqrt><annotation encoding="text/plain">sqrt(x)</annotation><annotation encoding="application/x-tex">\\sqrt x</annotation></semantics></math>'
|
||||
expect(Sanitize.fragment(mathml, subject)).to eq '$\sqrt x$'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -27,4 +27,28 @@ RSpec.describe CustomFilter do
|
|||
it { is_expected.to normalize(:context).from(['home', 'notifications', 'public ', '']).to(%w(home notifications public)) }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#expires_in' do
|
||||
subject { custom_filter.expires_in }
|
||||
|
||||
let(:custom_filter) { Fabricate.build(:custom_filter, expires_at: expires_at) }
|
||||
|
||||
context 'when expires_at is nil' do
|
||||
let(:expires_at) { nil }
|
||||
|
||||
it { is_expected.to be_nil }
|
||||
end
|
||||
|
||||
context 'when expires is beyond the end of the range' do
|
||||
let(:expires_at) { described_class::EXPIRATION_DURATIONS.last.from_now + 2.days }
|
||||
|
||||
it { is_expected.to be_nil }
|
||||
end
|
||||
|
||||
context 'when expires is before the start of the range' do
|
||||
let(:expires_at) { described_class::EXPIRATION_DURATIONS.first.from_now - 10.minutes }
|
||||
|
||||
it { is_expected.to eq(described_class::EXPIRATION_DURATIONS.first) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -127,6 +127,28 @@ RSpec.describe Report do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#unresolved_siblings?' do
|
||||
subject { Fabricate :report }
|
||||
|
||||
context 'when the target account has other unresolved reports' do
|
||||
before { Fabricate :report, action_taken_at: nil, target_account: subject.target_account }
|
||||
|
||||
it { is_expected.to be_unresolved_siblings }
|
||||
end
|
||||
|
||||
context 'when the target account has a resolved report' do
|
||||
before { Fabricate :report, action_taken_at: 3.days.ago, target_account: subject.target_account }
|
||||
|
||||
it { is_expected.to_not be_unresolved_siblings }
|
||||
end
|
||||
|
||||
context 'when the target account has no other reports' do
|
||||
before { described_class.where(target_account: subject.target_account).destroy_all }
|
||||
|
||||
it { is_expected.to_not be_unresolved_siblings }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'validations' do
|
||||
let(:remote_account) { Fabricate(:account, domain: 'example.com', protocol: :activitypub, inbox_url: 'http://example.com/inbox') }
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -95,7 +95,7 @@ RSpec.describe 'Accounts' do
|
|||
it 'does not add the account to the list', :aggregate_failures do
|
||||
subject
|
||||
|
||||
expect(response).to have_http_status(404)
|
||||
expect(response).to have_http_status(422)
|
||||
expect(response.content_type)
|
||||
.to start_with('application/json')
|
||||
expect(list.accounts).to_not include(bob)
|
||||
|
|
|
@ -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 }
|
||||
|
||||
|
|
55
spec/support/examples/models/concerns/ranked_trend.rb
Normal file
55
spec/support/examples/models/concerns/ranked_trend.rb
Normal 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
|
|
@ -36,7 +36,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)
|
||||
|
||||
|
@ -45,7 +45,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)
|
||||
|
||||
|
@ -54,7 +54,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)
|
||||
|
||||
|
@ -63,7 +63,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)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue