Merge pull request #930 from kmycode/upstream-20241203

Upstream 20241203
This commit is contained in:
KMY(雪あすか) 2024-12-04 12:21:04 +09:00 committed by GitHub
commit 58ce8274e5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
261 changed files with 2375 additions and 3844 deletions

View file

@ -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
@ -200,7 +202,7 @@ RSpec.describe FeedManager do
antenna.accounts << bob
allow(Antenna).to receive(:where).and_return(antenna)
status = Fabricate(:status, text: 'I post a lot', account: bob)
expect(described_class.instance.filter?(:home, status, alice)).to be true
expect(subject.filter?(:home, status, alice)).to be true
end
it 'returns true for reblog from followee on exclusive antenna' do
@ -210,7 +212,7 @@ RSpec.describe FeedManager do
allow(Antenna).to receive(:where).and_return(antenna)
status = Fabricate(:status, text: 'I post a lot', account: bob)
reblog = Fabricate(:status, reblog: status, account: jeff)
expect(described_class.instance.filter?(:home, reblog, alice)).to be true
expect(subject.filter?(:home, reblog, alice)).to be true
end
it 'returns false for post from followee on non-exclusive antenna' do
@ -218,7 +220,7 @@ RSpec.describe FeedManager do
alice.follow!(bob)
antenna.accounts << bob
status = Fabricate(:status, text: 'I post a lot', account: bob)
expect(described_class.instance.filter?(:home, status, alice)).to be false
expect(subject.filter?(:home, status, alice)).to be false
end
it 'returns false for reblog from followee on non-exclusive antenna' do
@ -227,7 +229,7 @@ RSpec.describe FeedManager do
antenna.accounts << jeff
status = Fabricate(:status, text: 'I post a lot', account: bob)
reblog = Fabricate(:status, reblog: status, account: jeff)
expect(described_class.instance.filter?(:home, reblog, alice)).to be false
expect(subject.filter?(:home, reblog, alice)).to be false
end
end

View file

@ -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

View file

@ -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

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

@ -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') }

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

@ -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)

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

@ -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)