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

This commit is contained in:
KMY 2024-02-09 12:53:59 +09:00
commit 05e52a09a8
188 changed files with 2810 additions and 1295 deletions

View file

@ -1246,19 +1246,10 @@ RSpec.describe Account do
it 'increments the count in multi-threaded an environment when account_stat is not yet initialized' do
subject
increment_by = 15
wait_for_start = true
threads = Array.new(increment_by) do
Thread.new do
true while wait_for_start
described_class.find(subject.id).increment_count!(:followers_count)
end
multi_threaded_execution(15) do
described_class.find(subject.id).increment_count!(:followers_count)
end
wait_for_start = false
threads.each(&:join)
expect(subject.reload.followers_count).to eq 15
end
end

View file

@ -6,6 +6,8 @@ describe Account::Counters do
let!(:account) { Fabricate(:account) }
describe '#increment_count!' do
let(:increment_by) { 15 }
it 'increments the count' do
expect(account.followers_count).to eq 0
account.increment_count!(:followers_count)
@ -13,24 +15,17 @@ describe Account::Counters do
end
it 'increments the count in multi-threaded an environment' do
increment_by = 15
wait_for_start = true
threads = Array.new(increment_by) do
Thread.new do
true while wait_for_start
account.increment_count!(:statuses_count)
end
multi_threaded_execution(increment_by) do
account.increment_count!(:statuses_count)
end
wait_for_start = false
threads.each(&:join)
expect(account.statuses_count).to eq increment_by
end
end
describe '#decrement_count!' do
let(:decrement_by) { 10 }
it 'decrements the count' do
account.followers_count = 15
account.save!
@ -40,22 +35,13 @@ describe Account::Counters do
end
it 'decrements the count in multi-threaded an environment' do
decrement_by = 10
wait_for_start = true
account.statuses_count = 15
account.save!
threads = Array.new(decrement_by) do
Thread.new do
true while wait_for_start
account.decrement_count!(:statuses_count)
end
multi_threaded_execution(decrement_by) do
account.decrement_count!(:statuses_count)
end
wait_for_start = false
threads.each(&:join)
expect(account.statuses_count).to eq 5
end
end

View file

@ -133,5 +133,18 @@ describe Report do
report = Fabricate.build(:report, account: remote_account, comment: Faker::Lorem.characters(number: 1001))
expect(report.valid?).to be true
end
it 'is invalid if it references invalid rules' do
report = Fabricate.build(:report, category: :violation, rule_ids: [-1])
expect(report.valid?).to be false
expect(report).to model_have_error_on_field(:rule_ids)
end
it 'is invalid if it references rules but category is not "violation"' do
rule = Fabricate(:rule)
report = Fabricate.build(:report, category: :spam, rule_ids: rule.id)
expect(report.valid?).to be false
expect(report).to model_have_error_on_field(:rule_ids)
end
end
end