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

This commit is contained in:
KMY 2024-06-18 07:43:33 +09:00
commit aa2cdc898a
271 changed files with 1839 additions and 1397 deletions

View file

@ -3,22 +3,30 @@
require 'rails_helper'
RSpec.describe AccountDomainBlock do
let(:account) { Fabricate(:account) }
it 'removes blocking cache after creation' do
account = Fabricate(:account)
Rails.cache.write("exclude_domains_for:#{account.id}", 'a.domain.already.blocked')
described_class.create!(account: account, domain: 'a.domain.blocked.later')
expect(Rails.cache.exist?("exclude_domains_for:#{account.id}")).to be false
expect { block_domain_for_account('a.domain.blocked.later') }
.to change { account_has_exclude_domains_cache? }.to(false)
end
it 'removes blocking cache after destruction' do
account = Fabricate(:account)
block = described_class.create!(account: account, domain: 'domain')
block = block_domain_for_account('domain')
Rails.cache.write("exclude_domains_for:#{account.id}", 'domain')
block.destroy!
expect { block.destroy! }
.to change { account_has_exclude_domains_cache? }.to(false)
end
expect(Rails.cache.exist?("exclude_domains_for:#{account.id}")).to be false
private
def block_domain_for_account(domain)
Fabricate(:account_domain_block, account: account, domain: domain)
end
def account_has_exclude_domains_cache?
Rails.cache.exist?("exclude_domains_for:#{account.id}")
end
end

View file

@ -991,20 +991,20 @@ RSpec.describe Account do
expect(account).to model_have_error_on_field(:username)
end
it 'is invalid if the username is longer than 30 characters' do
account = Fabricate.build(:account, username: Faker::Lorem.characters(number: 31))
it 'is invalid if the username is longer than the character limit' do
account = Fabricate.build(:account, username: username_over_limit)
account.valid?
expect(account).to model_have_error_on_field(:username)
end
it 'is invalid if the display name is longer than 30 characters' do
account = Fabricate.build(:account, display_name: Faker::Lorem.characters(number: 31))
it 'is invalid if the display name is longer than the character limit' do
account = Fabricate.build(:account, display_name: username_over_limit)
account.valid?
expect(account).to model_have_error_on_field(:display_name)
end
it 'is invalid if the note is longer than 500 characters' do
account = Fabricate.build(:account, note: Faker::Lorem.characters(number: 501))
it 'is invalid if the note is longer than the character limit' do
account = Fabricate.build(:account, note: account_note_over_limit)
account.valid?
expect(account).to model_have_error_on_field(:note)
end
@ -1037,24 +1037,32 @@ RSpec.describe Account do
expect(account).to model_have_error_on_field(:username)
end
it 'is valid even if the username is longer than 30 characters' do
account = Fabricate.build(:account, domain: 'domain', username: Faker::Lorem.characters(number: 31))
it 'is valid even if the username is longer than the character limit' do
account = Fabricate.build(:account, domain: 'domain', username: username_over_limit)
account.valid?
expect(account).to_not model_have_error_on_field(:username)
end
it 'is valid even if the display name is longer than 30 characters' do
account = Fabricate.build(:account, domain: 'domain', display_name: Faker::Lorem.characters(number: 31))
it 'is valid even if the display name is longer than the character limit' do
account = Fabricate.build(:account, domain: 'domain', display_name: username_over_limit)
account.valid?
expect(account).to_not model_have_error_on_field(:display_name)
end
it 'is valid even if the note is longer than 500 characters' do
account = Fabricate.build(:account, domain: 'domain', note: Faker::Lorem.characters(number: 501))
it 'is valid even if the note is longer than the character limit' do
account = Fabricate.build(:account, domain: 'domain', note: account_note_over_limit)
account.valid?
expect(account).to_not model_have_error_on_field(:note)
end
end
def username_over_limit
'a' * described_class::USERNAME_LENGTH_LIMIT * 2
end
def account_note_over_limit
'a' * described_class::NOTE_LENGTH_LIMIT * 2
end
end
describe 'scopes' do

View file

@ -3,6 +3,19 @@
require 'rails_helper'
describe Appeal do
describe 'Validations' do
it 'validates text length is under limit' do
appeal = Fabricate.build(
:appeal,
strike: Fabricate(:account_warning),
text: 'a' * described_class::TEXT_LENGTH_LIMIT * 2
)
expect(appeal).to_not be_valid
expect(appeal).to model_have_error_on_field(:text)
end
end
describe 'scopes' do
describe 'approved' do
let(:approved_appeal) { Fabricate(:appeal, approved_at: 10.days.ago) }

View file

@ -36,16 +36,15 @@ RSpec.describe Follow do
end
end
describe 'recent' do
it 'sorts so that more recent follows comes earlier' do
follow0 = described_class.create!(account: alice, target_account: bob)
follow1 = described_class.create!(account: bob, target_account: alice)
describe '.recent' do
let!(:follow_earlier) { Fabricate(:follow) }
let!(:follow_later) { Fabricate(:follow) }
a = described_class.recent.to_a
it 'sorts with most recent follows first' do
results = described_class.recent
expect(a.size).to eq 2
expect(a[0]).to eq follow1
expect(a[1]).to eq follow0
expect(results.size).to eq 2
expect(results).to eq [follow_later, follow_earlier]
end
end

View file

@ -8,11 +8,6 @@ RSpec.describe Import do
let(:data) { attachment_fixture('imports.txt') }
describe 'validations' do
it 'has a valid parameters' do
import = described_class.create(account: account, type: type, data: data)
expect(import).to be_valid
end
it 'is invalid without an type' do
import = described_class.create(account: account, data: data)
expect(import).to model_have_error_on_field(:type)

View file

@ -31,14 +31,6 @@ describe Poll do
end
describe 'validations' do
context 'when valid' do
let(:poll) { Fabricate.build(:poll) }
it 'is valid with valid attributes' do
expect(poll).to be_valid
end
end
context 'when not valid' do
let(:poll) { Fabricate.build(:poll, expires_at: nil) }

View file

@ -123,14 +123,14 @@ describe Report do
describe 'validations' do
let(:remote_account) { Fabricate(:account, domain: 'example.com', protocol: :activitypub, inbox_url: 'http://example.com/inbox') }
it 'is invalid if comment is longer than 1000 characters only if reporter is local' do
report = Fabricate.build(:report, comment: Faker::Lorem.characters(number: 1001))
it 'is invalid if comment is longer than character limit and reporter is local' do
report = Fabricate.build(:report, comment: comment_over_limit)
expect(report.valid?).to be false
expect(report).to model_have_error_on_field(:comment)
end
it 'is valid if comment is longer than 1000 characters and reporter is not local' do
report = Fabricate.build(:report, account: remote_account, comment: Faker::Lorem.characters(number: 1001))
it 'is valid if comment is longer than character limit and reporter is not local' do
report = Fabricate.build(:report, account: remote_account, comment: comment_over_limit)
expect(report.valid?).to be true
end
@ -146,5 +146,9 @@ describe Report do
expect(report.valid?).to be false
expect(report).to model_have_error_on_field(:rule_ids)
end
def comment_over_limit
'a' * described_class::COMMENT_SIZE_LIMIT * 2
end
end
end

View file

@ -0,0 +1,50 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe ScheduledStatus do
let(:account) { Fabricate(:account) }
describe 'validations' do
context 'when scheduled_at is less than minimum offset' do
subject { Fabricate.build(:scheduled_status, scheduled_at: 4.minutes.from_now, account: account) }
it 'is not valid', :aggregate_failures do
expect(subject).to_not be_valid
expect(subject.errors[:scheduled_at]).to include(I18n.t('scheduled_statuses.too_soon'))
end
end
context 'when account has reached total limit' do
subject { Fabricate.build(:scheduled_status, account: account) }
before do
allow(account.scheduled_statuses).to receive(:count).and_return(described_class::TOTAL_LIMIT)
end
it 'is not valid', :aggregate_failures do
expect(subject).to_not be_valid
expect(subject.errors[:base]).to include(I18n.t('scheduled_statuses.over_total_limit', limit: ScheduledStatus::TOTAL_LIMIT))
end
end
context 'when account has reached daily limit' do
subject { Fabricate.build(:scheduled_status, account: account, scheduled_at: base_time + 10.minutes) }
let(:base_time) { Time.current.change(hour: 12) }
before do
stub_const('ScheduledStatus::DAILY_LIMIT', 3)
travel_to base_time do
Fabricate.times(ScheduledStatus::DAILY_LIMIT, :scheduled_status, account: account, scheduled_at: base_time + 1.hour)
end
end
it 'is not valid', :aggregate_failures do
expect(subject).to_not be_valid
expect(subject.errors[:base]).to include(I18n.t('scheduled_statuses.over_daily_limit', limit: ScheduledStatus::DAILY_LIMIT))
end
end
end
end

View file

@ -71,8 +71,8 @@ RSpec.describe WebauthnCredential do
expect(webauthn_credential).to model_have_error_on_field(:sign_count)
end
it 'is invalid if sign_count is greater 2**63 - 1' do
webauthn_credential = Fabricate.build(:webauthn_credential, sign_count: 2**63)
it 'is invalid if sign_count is greater than the limit' do
webauthn_credential = Fabricate.build(:webauthn_credential, sign_count: (described_class::SIGN_COUNT_LIMIT * 2))
webauthn_credential.valid?