1
0
Fork 0
mirror of https://github.com/mastodon/mastodon.git synced 2024-08-20 21:08:15 -07:00

Validate uri presence for remote status (#4985)

This commit is contained in:
unarist 2017-09-17 22:21:57 +09:00 committed by Eugen Rochko
parent 3f07f1b2b1
commit dd6f9a1b82
2 changed files with 9 additions and 1 deletions

View file

@ -55,7 +55,7 @@ class Status < ApplicationRecord
has_one :notification, as: :activity, dependent: :destroy
has_one :stream_entry, as: :activity, inverse_of: :status
validates :uri, uniqueness: true, unless: :local?
validates :uri, uniqueness: true, presence: true, unless: :local?
validates :text, presence: true, unless: :reblog?
validates_with StatusLengthValidator
validates :reblog, uniqueness: { scope: :account }, if: :reblog?

View file

@ -516,6 +516,14 @@ RSpec.describe Status, type: :model do
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)
end
end
describe 'after_create' do
it 'saves ActivityPub uri as uri for local status' do
status = Status.create(account: alice, text: 'foo')