From ba9fd1c32e760582041758105b2844debed640a3 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Thu, 5 Sep 2024 05:48:33 -0400 Subject: [PATCH] Add coverage for `Account#prepare_contents` callback (#31748) --- spec/models/account_spec.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rb index 27707fa897e..1e8e4b1e4d3 100644 --- a/spec/models/account_spec.rb +++ b/spec/models/account_spec.rb @@ -723,6 +723,30 @@ RSpec.describe Account do end end + describe '#prepare_contents' do + subject { Fabricate.build :account, domain: domain, note: ' padded note ', display_name: ' padded name ' } + + context 'with local account' do + let(:domain) { nil } + + it 'strips values' do + expect { subject.valid? } + .to change(subject, :note).to('padded note') + .and(change(subject, :display_name).to('padded name')) + end + end + + context 'with remote account' do + let(:domain) { 'host.example' } + + it 'preserves values' do + expect { subject.valid? } + .to not_change(subject, :note) + .and(not_change(subject, :display_name)) + end + end + end + describe 'Normalizations' do describe 'username' do it { is_expected.to normalize(:username).from(" \u3000bob \t \u00a0 \n ").to('bob') }