Merge commit '9cc4040308a758d4b77961f4da79cf63a044fffe' into glitch-soc/merge-upstream

This commit is contained in:
Claire
2024-06-10 18:20:08 +02:00
50 changed files with 448 additions and 342 deletions

View File

@@ -54,7 +54,7 @@ RSpec.describe ActivityPub::Activity::Flag do
}.with_indifferent_access, sender)
end
let(:long_comment) { Faker::Lorem.characters(number: 6000) }
let(:long_comment) { 'a' * described_class::COMMENT_SIZE_LIMIT * 2 }
before do
subject.perform
@@ -63,10 +63,12 @@ RSpec.describe ActivityPub::Activity::Flag do
it 'creates a report but with a truncated comment' do
report = Report.find_by(account: sender, target_account: flagged)
expect(report).to_not be_nil
expect(report.comment.length).to eq 5000
expect(report.comment).to eq long_comment[0...5000]
expect(report.status_ids).to eq [status.id]
expect(report)
.to be_present
.and have_attributes(status_ids: [status.id])
expect(report.comment)
.to have_attributes(length: described_class::COMMENT_SIZE_LIMIT)
.and eq(long_comment[0...described_class::COMMENT_SIZE_LIMIT])
end
end

View File

@@ -768,20 +768,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
@@ -814,24 +814,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

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

@@ -193,6 +193,32 @@ describe '/api/v1/statuses' do
expect(response).to have_http_status(404)
end
end
context 'when scheduling a status' do
let(:params) { { status: 'Hello world', scheduled_at: 10.minutes.from_now } }
let(:account) { user.account }
it 'returns HTTP 200' do
subject
expect(response).to have_http_status(200)
end
it 'creates a scheduled status' do
expect { subject }.to change { account.scheduled_statuses.count }.from(0).to(1)
end
context 'when the scheduling time is less than 5 minutes' do
let(:params) { { status: 'Hello world', scheduled_at: 4.minutes.from_now } }
it 'does not create a scheduled status', :aggregate_failures do
subject
expect(response).to have_http_status(422)
expect(account.scheduled_statuses).to be_empty
end
end
end
end
describe 'DELETE /api/v1/statuses/:id' do

View File

@@ -61,6 +61,16 @@ RSpec.describe PostStatusService do
status2 = subject.call(account, text: 'test', idempotency: 'meepmeep', scheduled_at: future)
expect(status2.id).to eq status1.id
end
context 'when scheduled_at is less than min offset' do
let(:invalid_scheduled_time) { 4.minutes.from_now }
it 'raises invalid record error' do
expect do
subject.call(account, text: 'Hi future!', scheduled_at: invalid_scheduled_time)
end.to raise_error(ActiveRecord::RecordInvalid)
end
end
end
it 'creates response to the original status of boost' do

View File

@@ -46,7 +46,7 @@ describe 'Filters' do
click_on I18n.t('filters.index.delete')
end.to change(CustomFilter, :count).by(-1)
expect(page).to_not have_content(filter_title)
expect(page).to have_no_content(filter_title)
end
end