From 04035c3eb7e8f85ce5ebbf6b34fd9a4cb57b527a Mon Sep 17 00:00:00 2001
From: Benjamin Neff <benjamin@coding4coffee.ch>
Date: Sun, 27 Aug 2017 20:48:12 +0200
Subject: [PATCH] Allow to receive reshares without root

closes #7590
---
 app/models/reshare.rb       | 2 +-
 spec/models/reshare_spec.rb | 9 +++++++--
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/app/models/reshare.rb b/app/models/reshare.rb
index 118fca68f9..eda417410a 100644
--- a/app/models/reshare.rb
+++ b/app/models/reshare.rb
@@ -5,7 +5,7 @@
 class Reshare < Post
   belongs_to :root, class_name: "Post", foreign_key: :root_guid, primary_key: :guid, optional: true
   validate :root_must_be_public
-  validates_presence_of :root, :on => :create
+  validates :root, presence: true, on: :create, if: proc {|reshare| reshare.author.local? }
   validates :root_guid, uniqueness: {scope: :author_id}, allow_nil: true
   delegate :author, to: :root, prefix: true
 
diff --git a/spec/models/reshare_spec.rb b/spec/models/reshare_spec.rb
index 26b0ca2678..de2f652ced 100644
--- a/spec/models/reshare_spec.rb
+++ b/spec/models/reshare_spec.rb
@@ -4,11 +4,16 @@ describe Reshare, type: :model do
   end
 
   context "validation" do
-    it "requires root" do
-      reshare = FactoryGirl.build(:reshare, root: nil)
+    it "requires root when the author is local" do
+      reshare = FactoryGirl.build(:reshare, root: nil, author: alice.person)
       expect(reshare).not_to be_valid
     end
 
+    it "doesn't require root when the author is remote" do
+      reshare = FactoryGirl.build(:reshare, root: nil, author: remote_raphael)
+      expect(reshare).to be_valid
+    end
+
     it "require public root" do
       reshare = FactoryGirl.build(:reshare, root: FactoryGirl.create(:status_message, public: false))
       expect(reshare).not_to be_valid
-- 
GitLab