Skip to content

Commit

Permalink
Augment coverage for Status model (mastodon#32468)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjankowski authored Oct 14, 2024
1 parent d8eab3d commit cc70acc
Showing 1 changed file with 47 additions and 5 deletions.
52 changes: 47 additions & 5 deletions spec/models/status_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -472,11 +472,53 @@
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

Expand Down

0 comments on commit cc70acc

Please sign in to comment.