Skip to content
Extraits de code Groupes Projets
Non vérifiée Valider 04035c3e rédigé par Benjamin Neff's avatar Benjamin Neff
Parcourir les fichiers

Allow to receive reshares without root

closes #7590
parent 163ffdb1
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
class Reshare < Post class Reshare < Post
belongs_to :root, class_name: "Post", foreign_key: :root_guid, primary_key: :guid, optional: true belongs_to :root, class_name: "Post", foreign_key: :root_guid, primary_key: :guid, optional: true
validate :root_must_be_public 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 validates :root_guid, uniqueness: {scope: :author_id}, allow_nil: true
delegate :author, to: :root, prefix: true delegate :author, to: :root, prefix: true
......
...@@ -4,11 +4,16 @@ describe Reshare, type: :model do ...@@ -4,11 +4,16 @@ describe Reshare, type: :model do
end end
context "validation" do context "validation" do
it "requires root" do it "requires root when the author is local" do
reshare = FactoryGirl.build(:reshare, root: nil) reshare = FactoryGirl.build(:reshare, root: nil, author: alice.person)
expect(reshare).not_to be_valid expect(reshare).not_to be_valid
end 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 it "require public root" do
reshare = FactoryGirl.build(:reshare, root: FactoryGirl.create(:status_message, public: false)) reshare = FactoryGirl.build(:reshare, root: FactoryGirl.create(:status_message, public: false))
expect(reshare).not_to be_valid expect(reshare).not_to be_valid
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter