Augment coverage for `Status` model (#32468)

pull/2884/head
Matt Jankowski 2024-10-14 08:52:47 -04:00 committed by GitHub
parent d8eab3d81f
commit cc70acc11c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 47 additions and 5 deletions

View File

@ -472,11 +472,53 @@ RSpec.describe Status do
end
end
describe 'validation' do
it 'disallow empty uri for remote status' do
alice.update(domain: 'example.com')
status = Fabricate.build(:status, uri: '', account: alice)
expect(status).to model_have_error_on_field(:uri)
describe 'Validations' do
context 'with a remote account' do
subject { Fabricate.build :status, account: remote_account }
let(:remote_account) { Fabricate :account, domain: 'example.com' }
it { is_expected.to_not allow_value('').for(:uri) }
end
end
describe 'Callbacks' do
describe 'Stripping content when required' do
context 'with a remote account' do
subject { Fabricate.build :status, local: false, account:, text: ' text ', spoiler_text: ' spoiler ' }
let(:account) { Fabricate.build :account, domain: 'host.example' }
it 'preserves content' do
expect { subject.valid? }
.to not_change(subject, :text)
.and not_change(subject, :spoiler_text)
end
end
context 'with a local account' do
let(:account) { Fabricate.build :account, domain: nil }
context 'with populated fields' do
subject { Fabricate.build :status, local: true, account:, text: ' text ', spoiler_text: ' spoiler ' }
it 'strips content' do
expect { subject.valid? }
.to change(subject, :text).to('text')
.and change(subject, :spoiler_text).to('spoiler')
end
end
context 'with empty fields' do
subject { Fabricate.build :status, local: true, account:, text: nil, spoiler_text: nil }
it 'preserves content' do
expect { subject.valid? }
.to not_change(subject, :text)
.and not_change(subject, :spoiler_text)
end
end
end
end
end