mirror of
https://github.com/glitch-soc/mastodon.git
synced 2025-12-15 16:59:41 +00:00
Merge commit '9cc4040308a758d4b77961f4da79cf63a044fffe' into glitch-soc/merge-upstream
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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) }
|
||||
|
||||
@@ -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
|
||||
|
||||
50
spec/models/scheduled_status_spec.rb
Normal file
50
spec/models/scheduled_status_spec.rb
Normal 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
|
||||
Reference in New Issue
Block a user