Merge commit '37ccffa95a30772b55e3f18d486d699ee6c5f9e8' into glitch-soc/merge-upstream
This commit is contained in:
commit
99ff59b7b2
34 files changed
+381
-328
No files matched your search
@@ -1,50 +0,0 @@
|
||||
# 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 }
|
||||
let(:most_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
|
||||
|
||||
Fabricate :status, account: account, reply: true, in_reply_to_id: Fabricate(:status, account: most_other_account).id
|
||||
Fabricate :status, account: account, reply: true, in_reply_to_id: Fabricate(:status, account: most_other_account).id
|
||||
Fabricate :status, account: account, reply: true, in_reply_to_id: Fabricate(:status, account: most_other_account).id
|
||||
end
|
||||
|
||||
it 'builds a report for an account' do
|
||||
expect(subject.generate)
|
||||
.to include(
|
||||
commonly_interacted_with_accounts: eq(
|
||||
[
|
||||
{ account_id: most_other_account.id.to_s, count: 3 },
|
||||
{ account_id: other_account.id.to_s, count: 2 },
|
||||
]
|
||||
)
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,49 +0,0 @@
|
||||
# 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 }
|
||||
let(:most_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)
|
||||
|
||||
Fabricate :status, account: account, reblog: Fabricate(:status, account: most_other_account)
|
||||
Fabricate :status, account: account, reblog: Fabricate(:status, account: most_other_account)
|
||||
Fabricate :status, account: account, reblog: Fabricate(:status, account: most_other_account)
|
||||
end
|
||||
|
||||
it 'builds a report for an account' do
|
||||
expect(subject.generate)
|
||||
.to include(
|
||||
most_reblogged_accounts: eq(
|
||||
[
|
||||
{ account_id: most_other_account.id.to_s, count: 3 },
|
||||
{ account_id: other_account.id.to_s, count: 2 },
|
||||
]
|
||||
)
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,46 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe AnnualReport::Percentiles do
|
||||
describe '#generate' do
|
||||
subject { described_class.new(account, year) }
|
||||
|
||||
let(:year) { Time.zone.now.year }
|
||||
|
||||
context 'with an inactive account' do
|
||||
let(:account) { Fabricate :account }
|
||||
|
||||
it 'builds a report for an account' do
|
||||
described_class.prepare(year)
|
||||
|
||||
expect(subject.generate)
|
||||
.to include(
|
||||
percentiles: include(
|
||||
statuses: 100
|
||||
)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with an active account' do
|
||||
let(:account) { Fabricate :account }
|
||||
|
||||
before do
|
||||
Fabricate.times 2, :status # Others as `account`
|
||||
Fabricate.times 2, :status, account: account
|
||||
end
|
||||
|
||||
it 'builds a report for an account' do
|
||||
described_class.prepare(year)
|
||||
|
||||
expect(subject.generate)
|
||||
.to include(
|
||||
percentiles: include(
|
||||
statuses: 50
|
||||
)
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -13,13 +13,4 @@ RSpec.describe AnnualReport do
|
||||
.to change(GeneratedAnnualReport, :count).by(1)
|
||||
end
|
||||
end
|
||||
|
||||
describe '.prepare' do
|
||||
before { Fabricate :status }
|
||||
|
||||
it 'generates records from source class which prepare data' do
|
||||
expect { described_class.prepare(Time.current.year) }
|
||||
.to change(AnnualReport::StatusesPerAccountCount, :count).by(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -15,17 +15,62 @@ RSpec.describe Mastodon::CLI::EmailDomainBlocks do
|
||||
describe '#list' do
|
||||
let(:action) { :list }
|
||||
|
||||
context 'with both --only-blocked and --only-with-approval' do
|
||||
let(:options) { { only_blocked: true, only_with_approval: true } }
|
||||
|
||||
it 'warns about usage and exits' do
|
||||
expect { subject }
|
||||
.to raise_error(Thor::Error, 'Cannot specify both --only-blocked and --only-with-approval')
|
||||
end
|
||||
end
|
||||
|
||||
context 'with email domain block records' do
|
||||
let!(:parent_block) { Fabricate(:email_domain_block) }
|
||||
let!(:child_block) { Fabricate(:email_domain_block, parent: parent_block) }
|
||||
let!(:parent_allow_block) { Fabricate(:email_domain_block, allow_with_approval: true) }
|
||||
let!(:child_allow_block) { Fabricate(:email_domain_block, parent: parent_allow_block, allow_with_approval: true) }
|
||||
|
||||
it 'lists the blocks' do
|
||||
it 'lists all the blocks by default' do
|
||||
expect { subject }
|
||||
.to output_results(
|
||||
parent_block.domain,
|
||||
child_block.domain
|
||||
child_block.domain,
|
||||
parent_allow_block.domain,
|
||||
child_allow_block.domain
|
||||
)
|
||||
end
|
||||
|
||||
context 'with the --only-blocked flag set' do
|
||||
let(:options) { { only_blocked: true } }
|
||||
|
||||
it 'lists only blocked domains' do
|
||||
expect { subject }
|
||||
.to output_results(
|
||||
parent_block.domain,
|
||||
child_block.domain
|
||||
)
|
||||
.and not_output_results(
|
||||
parent_allow_block.domain,
|
||||
child_allow_block.domain
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with the --only-with-approval flag set' do
|
||||
let(:options) { { only_with_approval: true } }
|
||||
|
||||
it 'lists only manually approvable domains' do
|
||||
expect { subject }
|
||||
.to output_results(
|
||||
parent_allow_block.domain,
|
||||
child_allow_block.domain
|
||||
)
|
||||
.and not_output_results(
|
||||
parent_block.domain,
|
||||
child_block.domain
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -56,6 +101,7 @@ RSpec.describe Mastodon::CLI::EmailDomainBlocks do
|
||||
context 'when no blocks exist' do
|
||||
let(:domain) { 'host.example' }
|
||||
let(:arguments) { [domain] }
|
||||
let(:options) { { allow_with_approval: false } }
|
||||
|
||||
it 'adds a new block' do
|
||||
expect { subject }
|
||||
@@ -67,7 +113,7 @@ RSpec.describe Mastodon::CLI::EmailDomainBlocks do
|
||||
context 'with --with-dns-records true' do
|
||||
let(:domain) { 'host.example' }
|
||||
let(:arguments) { [domain] }
|
||||
let(:options) { { with_dns_records: true } }
|
||||
let(:options) { { allow_with_approval: false, with_dns_records: true } }
|
||||
|
||||
before do
|
||||
configure_mx(domain: domain, exchange: 'other.host')
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Api::V1Alpha::Collections', feature: :collections do
|
||||
include_context 'with API authentication', oauth_scopes: 'read:collections write:collections'
|
||||
|
||||
describe 'POST /api/v1_alpha/collections' do
|
||||
subject do
|
||||
post '/api/v1_alpha/collections', headers: headers, params: params
|
||||
end
|
||||
|
||||
let(:params) { {} }
|
||||
|
||||
it_behaves_like 'forbidden for wrong scope', 'read'
|
||||
|
||||
context 'with valid params' do
|
||||
let(:params) do
|
||||
{
|
||||
name: 'Low-traffic bots',
|
||||
description: 'Really nice bots, please follow',
|
||||
sensitive: '0',
|
||||
discoverable: '1',
|
||||
}
|
||||
end
|
||||
|
||||
it 'creates a collection and returns http success' do
|
||||
expect do
|
||||
subject
|
||||
end.to change(Collection, :count).by(1)
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with invalid params' do
|
||||
it 'returns http unprocessable content and detailed errors' do
|
||||
expect do
|
||||
subject
|
||||
end.to_not change(Collection, :count)
|
||||
|
||||
expect(response).to have_http_status(422)
|
||||
expect(response.parsed_body).to include({
|
||||
'error' => a_hash_including({
|
||||
'details' => a_hash_including({
|
||||
'name' => [{ 'error' => 'ERR_BLANK', 'description' => "can't be blank" }],
|
||||
'description' => [{ 'error' => 'ERR_BLANK', 'description' => "can't be blank" }],
|
||||
}),
|
||||
}),
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,30 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe REST::CollectionSerializer do
|
||||
subject { serialized_record_json(collection, described_class) }
|
||||
|
||||
let(:collection) do
|
||||
Fabricate(:collection,
|
||||
name: 'Exquisite follows',
|
||||
description: 'Always worth a follow',
|
||||
local: true,
|
||||
sensitive: true,
|
||||
discoverable: false)
|
||||
end
|
||||
|
||||
it 'includes the relevant attributes' do
|
||||
expect(subject)
|
||||
.to include(
|
||||
'account' => an_instance_of(Hash),
|
||||
'name' => 'Exquisite follows',
|
||||
'description' => 'Always worth a follow',
|
||||
'local' => true,
|
||||
'sensitive' => true,
|
||||
'discoverable' => false,
|
||||
'created_at' => match_api_datetime_format,
|
||||
'updated_at' => match_api_datetime_format
|
||||
)
|
||||
end
|
||||
end
|
||||
@@ -7,3 +7,5 @@ module CommandLineHelpers
|
||||
).to_stdout
|
||||
end
|
||||
end
|
||||
|
||||
RSpec::Matchers.define_negated_matcher :not_output_results, :output_results
|
||||
Reference in new issue
Block a user