diff --git a/app/models/status.rb b/app/models/status.rb index 73f00526735..e0630733d89 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -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 diff --git a/spec/services/post_status_service_spec.rb b/spec/services/post_status_service_spec.rb index 7e447896280..26db398d5eb 100644 --- a/spec/services/post_status_service_spec.rb +++ b/spec/services/post_status_service_spec.rb @@ -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)