From cc70acc11cf488660ebd4a207633380e56cbf417 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Mon, 14 Oct 2024 08:52:47 -0400 Subject: [PATCH] Augment coverage for `Status` model (#32468) --- spec/models/status_spec.rb | 52 ++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 5 deletions(-) diff --git a/spec/models/status_spec.rb b/spec/models/status_spec.rb index df67c365eb..90f5968438 100644 --- a/spec/models/status_spec.rb +++ b/spec/models/status_spec.rb @@ -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