logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe
commit: dd6f9a1b827226346d0fff22a79538351fb33028
parent: 3f07f1b2b18affd0c48f3673d124cfbea6b9e380
Author: unarist <m.unarist@gmail.com>
Date:   Sun, 17 Sep 2017 22:21:57 +0900

Validate uri presence for remote status (#4985)


Diffstat:

Mapp/models/status.rb2+-
Mspec/models/status_spec.rb8++++++++
2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/app/models/status.rb b/app/models/status.rb @@ -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? diff --git a/spec/models/status_spec.rb b/spec/models/status_spec.rb @@ -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')