Handle invalid visibility (#31571)

This commit is contained in:
Christian Schmidt 2024-09-12 15:29:55 +02:00 committed by GitHub
parent 17c57c46e7
commit 8cdc148167
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 2 deletions

View file

@ -52,7 +52,7 @@ class Status < ApplicationRecord
update_index('statuses', :proper) update_index('statuses', :proper)
update_index('public_statuses', :proper) update_index('public_statuses', :proper)
enum :visibility, { public: 0, unlisted: 1, private: 2, direct: 3, limited: 4 }, suffix: :visibility enum :visibility, { public: 0, unlisted: 1, private: 2, direct: 3, limited: 4 }, suffix: :visibility, validate: true
belongs_to :application, class_name: 'Doorkeeper::Application', optional: true belongs_to :application, class_name: 'Doorkeeper::Application', optional: true

View file

@ -68,7 +68,10 @@ RSpec.describe PostStatusService do
it 'raises invalid record error' do it 'raises invalid record error' do
expect do expect do
subject.call(account, text: 'Hi future!', scheduled_at: invalid_scheduled_time) subject.call(account, text: 'Hi future!', scheduled_at: invalid_scheduled_time)
end.to raise_error(ActiveRecord::RecordInvalid) end.to raise_error(
ActiveRecord::RecordInvalid,
'Validation failed: Scheduled at The scheduled date must be in the future'
)
end end
end end
end end
@ -123,6 +126,15 @@ RSpec.describe PostStatusService do
expect(status.visibility).to eq 'private' expect(status.visibility).to eq 'private'
end end
it 'raises on an invalid visibility' do
expect do
create_status_with_options(visibility: :xxx)
end.to raise_error(
ActiveRecord::RecordInvalid,
'Validation failed: Visibility is not included in the list'
)
end
it 'creates a status with limited visibility for silenced users' do it 'creates a status with limited visibility for silenced users' do
status = subject.call(Fabricate(:account, silenced: true), text: 'test', visibility: :public) status = subject.call(Fabricate(:account, silenced: true), text: 'test', visibility: :public)