Merge remote-tracking branch 'parent/main' into upstream-20240913

This commit is contained in:
KMY 2024-09-13 10:31:48 +09:00
commit fc9d27ff91
392 changed files with 3757 additions and 3233 deletions

View file

@ -95,16 +95,11 @@ RSpec.describe ActivityPub::LinkedDataSignature do
describe '#sign!' do
subject { described_class.new(raw_json).sign!(sender) }
it 'returns a hash' do
it 'returns a hash with a signature, the expected context, and the signature can be verified', :aggregate_failures do
expect(subject).to be_a Hash
end
it 'contains signature' do
expect(subject['signature']).to be_a Hash
expect(subject['signature']['signatureValue']).to be_present
end
it 'can be verified again' do
expect(Array(subject['@context'])).to include('https://w3id.org/security/v1')
expect(described_class.new(subject).verify_actor!).to eq sender
end
end

View file

@ -0,0 +1,41 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe AnnualReport::CommonlyInteractedWithAccounts do
describe '#generate' do
subject { described_class.new(account, Time.zone.now.year) }
context 'with an inactive account' do
let(:account) { Fabricate :account }
it 'builds a report for an account' do
expect(subject.generate)
.to include(
commonly_interacted_with_accounts: be_an(Array).and(be_empty)
)
end
end
context 'with an active account' do
let(:account) { Fabricate :account }
let(:other_account) { Fabricate :account }
before do
_other = Fabricate :status
Fabricate :status, account: account, reply: true, in_reply_to_id: Fabricate(:status, account: other_account).id
Fabricate :status, account: account, reply: true, in_reply_to_id: Fabricate(:status, account: other_account).id
end
it 'builds a report for an account' do
expect(subject.generate)
.to include(
commonly_interacted_with_accounts: contain_exactly(
include(account_id: other_account.id, count: 2)
)
)
end
end
end
end

View file

@ -0,0 +1,41 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe AnnualReport::MostRebloggedAccounts do
describe '#generate' do
subject { described_class.new(account, Time.zone.now.year) }
context 'with an inactive account' do
let(:account) { Fabricate :account }
it 'builds a report for an account' do
expect(subject.generate)
.to include(
most_reblogged_accounts: be_an(Array).and(be_empty)
)
end
end
context 'with an active account' do
let(:account) { Fabricate :account }
let(:other_account) { Fabricate :account }
before do
_other = Fabricate :status
Fabricate :status, account: account, reblog: Fabricate(:status, account: other_account)
Fabricate :status, account: account, reblog: Fabricate(:status, account: other_account)
end
it 'builds a report for an account' do
expect(subject.generate)
.to include(
most_reblogged_accounts: contain_exactly(
include(account_id: other_account.id, count: 2)
)
)
end
end
end
end

View file

@ -0,0 +1,40 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe AnnualReport::MostUsedApps do
describe '#generate' do
subject { described_class.new(account, Time.zone.now.year) }
context 'with an inactive account' do
let(:account) { Fabricate :account }
it 'builds a report for an account' do
expect(subject.generate)
.to include(
most_used_apps: be_an(Array).and(be_empty)
)
end
end
context 'with an active account' do
let(:account) { Fabricate :account }
let(:application) { Fabricate :application }
before do
_other = Fabricate :status
Fabricate.times 2, :status, account: account, application: application
end
it 'builds a report for an account' do
expect(subject.generate)
.to include(
most_used_apps: contain_exactly(
include(name: application.name, count: 2)
)
)
end
end
end
end

View file

@ -0,0 +1,44 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe AnnualReport::Percentiles do
describe '#generate' do
subject { described_class.new(account, Time.zone.now.year) }
context 'with an inactive account' do
let(:account) { Fabricate :account }
it 'builds a report for an account' do
expect(subject.generate)
.to include(
percentiles: include(
followers: 0,
statuses: 0
)
)
end
end
context 'with an active account' do
let(:account) { Fabricate :account }
before do
Fabricate.times 2, :status # Others as `account`
Fabricate.times 2, :follow # Others as `target_account`
Fabricate.times 2, :status, account: account
Fabricate.times 2, :follow, target_account: account
end
it 'builds a report for an account' do
expect(subject.generate)
.to include(
percentiles: include(
followers: 50,
statuses: 50
)
)
end
end
end
end

View file

@ -0,0 +1,46 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe AnnualReport::TimeSeries do
describe '#generate' do
subject { described_class.new(account, Time.zone.now.year) }
context 'with an inactive account' do
let(:account) { Fabricate :account }
it 'builds a report for an account' do
expect(subject.generate)
.to include(
time_series: match(
include(followers: 0, following: 0, month: 1, statuses: 0)
)
)
end
end
context 'with an active account' do
let(:account) { Fabricate :account }
let(:month_one_date) { DateTime.new(Time.zone.now.year, 1, 1, 12, 12, 12) }
let(:tag) { Fabricate :tag }
before do
_other = Fabricate :status
Fabricate :status, account: account, created_at: month_one_date
Fabricate :follow, account: account, created_at: month_one_date
Fabricate :follow, target_account: account, created_at: month_one_date
end
it 'builds a report for an account' do
expect(subject.generate)
.to include(
time_series: match(
include(followers: 1, following: 1, month: 1, statuses: 1)
)
)
end
end
end
end

View file

@ -0,0 +1,43 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe AnnualReport::TopHashtags do
describe '#generate' do
subject { described_class.new(account, Time.zone.now.year) }
context 'with an inactive account' do
let(:account) { Fabricate :account }
it 'builds a report for an account' do
expect(subject.generate)
.to include(
top_hashtags: be_an(Array).and(be_empty)
)
end
end
context 'with an active account' do
let(:account) { Fabricate :account }
let(:tag) { Fabricate :tag }
before do
_other = Fabricate :status
first = Fabricate :status, account: account
first.tags << tag
last = Fabricate :status, account: account
last.tags << tag
end
it 'builds a report for an account' do
expect(subject.generate)
.to include(
top_hashtags: contain_exactly(
include(name: tag.name, count: 2)
)
)
end
end
end
end

View file

@ -0,0 +1,50 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe AnnualReport::TopStatuses do
describe '#generate' do
subject { described_class.new(account, Time.zone.now.year) }
context 'with an inactive account' do
let(:account) { Fabricate :account }
it 'builds a report for an account' do
expect(subject.generate)
.to include(
top_statuses: include(
by_reblogs: be_nil,
by_favourites: be_nil,
by_replies: be_nil
)
)
end
end
context 'with an active account' do
let(:account) { Fabricate :account }
let(:reblogged_status) { Fabricate :status, account: account }
let(:favourited_status) { Fabricate :status, account: account }
let(:replied_status) { Fabricate :status, account: account }
before do
_other = Fabricate :status
reblogged_status.status_stat.update(reblogs_count: 123)
favourited_status.status_stat.update(favourites_count: 123)
replied_status.status_stat.update(replies_count: 123)
end
it 'builds a report for an account' do
expect(subject.generate)
.to include(
top_statuses: include(
by_reblogs: reblogged_status.id,
by_favourites: favourited_status.id,
by_replies: replied_status.id
)
)
end
end
end
end

View file

@ -0,0 +1,48 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe AnnualReport::TypeDistribution do
describe '#generate' do
subject { described_class.new(account, Time.zone.now.year) }
context 'with an inactive account' do
let(:account) { Fabricate :account }
it 'builds a report for an account' do
expect(subject.generate)
.to include(
type_distribution: include(
total: 0,
reblogs: 0,
replies: 0,
standalone: 0
)
)
end
end
context 'with an active account' do
let(:account) { Fabricate :account }
before do
_other = Fabricate :status
Fabricate :status, reblog: Fabricate(:status), account: account
Fabricate :status, in_reply_to_id: Fabricate(:status).id, account: account, reply: true
Fabricate :status, account: account
end
it 'builds a report for an account' do
expect(subject.generate)
.to include(
type_distribution: include(
total: 3,
reblogs: 1,
replies: 1,
standalone: 1
)
)
end
end
end
end

View file

@ -33,6 +33,14 @@ RSpec.describe LinkDetailsExtractor do
expect(subject.canonical_url).to eq original_url
end
end
context 'when canonical URL is set to "undefined"' do
let(:url) { 'undefined' }
it 'ignores the canonical URLs' do
expect(subject.canonical_url).to eq original_url
end
end
end
context 'when only basic metadata is present' do

View file

@ -8,6 +8,37 @@ RSpec.describe SearchQueryTransformer do
let(:account) { Fabricate(:account) }
let(:parser) { SearchQueryParser.new.parse(query) }
shared_examples 'date operator' do |operator|
let(:statement_operations) { [] }
[
['2022-01-01', '2022-01-01'],
['"2022-01-01"', '2022-01-01'],
['12345678', '12345678'],
['"12345678"', '12345678'],
].each do |value, parsed|
context "with #{operator}:#{value}" do
let(:query) { "#{operator}:#{value}" }
it 'transforms clauses' do
ops = statement_operations.index_with { |_op| parsed }
expect(subject.send(:must_clauses)).to be_empty
expect(subject.send(:must_not_clauses)).to be_empty
expect(subject.send(:filter_clauses).map(&:term)).to contain_exactly(**ops, time_zone: 'UTC')
end
end
end
context "with #{operator}:\"abc\"" do
let(:query) { "#{operator}:\"abc\"" }
it 'raises an exception' do
expect { subject }.to raise_error(Mastodon::FilterValidationError, 'Invalid date abc')
end
end
end
context 'with "hello world"' do
let(:query) { 'hello world' }
@ -68,13 +99,33 @@ RSpec.describe SearchQueryTransformer do
end
end
context 'with \'before:"2022-01-01 23:00"\'' do
let(:query) { 'before:"2022-01-01 23:00"' }
context 'with \'is:"foo bar"\'' do
let(:query) { 'is:"foo bar"' }
it 'transforms clauses' do
expect(subject.send(:must_clauses)).to be_empty
expect(subject.send(:must_not_clauses)).to be_empty
expect(subject.send(:filter_clauses).map(&:term)).to contain_exactly(lt: '2022-01-01 23:00', time_zone: 'UTC')
expect(subject.send(:filter_clauses).map(&:term)).to contain_exactly('foo bar')
end
end
context 'with date operators' do
context 'with "before"' do
it_behaves_like 'date operator', 'before' do
let(:statement_operations) { [:lt] }
end
end
context 'with "after"' do
it_behaves_like 'date operator', 'after' do
let(:statement_operations) { [:gt] }
end
end
context 'with "during"' do
it_behaves_like 'date operator', 'during' do
let(:statement_operations) { [:gte, :lte] }
end
end
end
end