fix root_diaspora_id when root was deleted

This commit is contained in:
Benjamin Neff 2015-05-18 00:27:54 +02:00 committed by Dennis Schubert
parent ceec5084af
commit 267a1df3c4
2 changed files with 14 additions and 1 deletions

View file

@ -26,7 +26,7 @@ class Reshare < Post
end
def root_diaspora_id
self.root.author.diaspora_handle
root.try(:author).try(:diaspora_handle)
end
delegate :o_embed_cache, :open_graph_cache,

View file

@ -20,6 +20,19 @@ describe Reshare, :type => :model do
expect(FactoryGirl.create(:reshare, :public => false).public).to be true
end
describe "#root_diaspora_id" do
it "should return the root diaspora id" do
reshare = FactoryGirl.create(:reshare, root: FactoryGirl.build(:status_message, author: bob.person, public: true))
expect(reshare.root_diaspora_id).to eq(bob.person.diaspora_handle)
end
it "should be nil if no root found" do
reshare = FactoryGirl.create(:reshare, root: FactoryGirl.build(:status_message, author: bob.person, public: true))
reshare.root = nil
expect(reshare.root_diaspora_id).to be_nil
end
end
describe "#receive" do
let(:receive_reshare) { @reshare.receive(@root.author.owner, @reshare.author) }