mirror of
https://github.com/mastodon/mastodon.git
synced 2024-11-08 08:44:27 +00:00
Handle invalid visibility (#31571)
This commit is contained in:
parent
17c57c46e7
commit
8cdc148167
|
@ -52,7 +52,7 @@ class Status < ApplicationRecord
|
|||
update_index('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
|
||||
|
||||
|
|
|
@ -68,7 +68,10 @@ RSpec.describe PostStatusService do
|
|||
it 'raises invalid record error' do
|
||||
expect do
|
||||
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
|
||||
|
@ -123,6 +126,15 @@ RSpec.describe PostStatusService do
|
|||
expect(status.visibility).to eq 'private'
|
||||
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
|
||||
status = subject.call(Fabricate(:account, silenced: true), text: 'test', visibility: :public)
|
||||
|
||||
|
|
Loading…
Reference in a new issue