Skip to content
Extraits de code Groupes Projets
Valider 9144a4aa rédigé par Benjamin Neff's avatar Benjamin Neff
Parcourir les fichiers

write specs for retractions

parent c8c489ea
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -2,60 +2,100 @@ ...@@ -2,60 +2,100 @@
# licensed under the Affero General Public License version 3 or later. See # licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file. # the COPYRIGHT file.
require 'spec_helper' require "spec_helper"
describe Retraction do describe Retraction do
before do let(:post) { alice.post(:status_message, text: "destroy!", public: true) }
skip # TODO let(:retraction) { Retraction.for(post, alice) }
@aspect = alice.aspects.first
alice.contacts.create(:person => eve.person, :aspects => [@aspect]) describe "#subscribers" do
@post = alice.post(:status_message, :public => true, :text => "Destroy!", :to => @aspect.id) it "contains all remote-subscribers of target object" do
post = local_luke.post(:status_message, text: "destroy!", public: true)
retraction = Retraction.for(post, local_luke)
expect(retraction.subscribers).to eq([remote_raphael])
end
end
describe "#data" do
it "contains the hash with all data from the federation-retraction" do
federation_retraction = Diaspora::Federation::Entities.signed_retraction(post, alice)
expect(retraction.data).to eq(federation_retraction.to_h)
end
end
describe ".for" do
it "creates a retraction for a post" do
expect(Diaspora::Federation::Entities).to receive(:signed_retraction).with(post, alice)
Retraction.for(post, alice)
end
it "creates a retraction for a relayable" do
comment = FactoryGirl.create(:comment, author: alice.person, post: post)
expect(Diaspora::Federation::Entities).to receive(:relayable_retraction).with(comment, alice)
Retraction.for(comment, alice)
end
it "creates a retraction for a contact" do
contact = FactoryGirl.create(:contact)
expect(Diaspora::Federation::Entities).to receive(:retraction).with(contact)
Retraction.for(contact, contact.user)
end
end
describe ".defer_dispatch" do
it "queues a job to send the retraction later" do
post = local_luke.post(:status_message, text: "destroy!", public: true)
federation_retraction = Diaspora::Federation::Entities.signed_retraction(post, alice)
expect(Workers::DeferredRetraction)
.to receive(:perform_async).with(alice.id, federation_retraction.to_h, [remote_raphael.id])
Retraction.for(post, alice).defer_dispatch(alice)
end
it "does not queue a job if subscribers is empty" do
federation_retraction = Diaspora::Federation::Entities.signed_retraction(post, alice)
expect(Workers::DeferredRetraction).not_to receive(:perform_async).with(alice.id, federation_retraction.to_h, [])
Retraction.for(post, alice).defer_dispatch(alice)
end
end end
describe 'serialization' do describe "#perform" do
it 'should have a post id after serialization' do it "destroys the target object" do
retraction = described_class.for(@post) expect(post).to receive(:destroy!)
xml = retraction.to_xml.to_s Retraction.for(post, alice).perform
expect(xml.include?(@post.guid.to_s)).to eq(true)
end end
end end
describe '#subscribers' do describe "#public?" do
context 'posts' do it "returns true for a public target" do
before do expect(Retraction.for(post, alice).public?).to be_truthy
@retraction = described_class.for(@post) end
@obj = @retraction.instance_variable_get(:@object)
@wanted_subscribers = @obj.subscribers it "returns false for a private target" do
end private_post = alice.post(:status_message, text: "destroy!", to: alice.aspects.first.id)
expect(Retraction.for(private_post, alice).public?).to be_falsey
it 'returns the subscribers to the post for all objects other than person' do end
expect(@retraction.subscribers.map(&:id)).to match_array(@wanted_subscribers.map(&:id)) end
end
describe "#target_type" do
it 'does not return the authors of reshares' do it "returns the type of the target as String" do
@post.reshares << FactoryGirl.build(:reshare, :root => @post, :author => bob.person) expect(Retraction.for(post, alice).target_type).to eq("Post")
@post.save! end
@wanted_subscribers -= [bob.person] it "is Person for a Contact-retraction" do
expect(@retraction.subscribers.map(&:id)).to match_array(@wanted_subscribers.map(&:id)) contact = FactoryGirl.create(:contact)
end expect(Retraction.for(contact, contact.user).target_type).to eq("Person")
end
context 'setting subscribers' do
it 'barfs if the type is a person, and subscribers instance varabile is not set' do
retraction = described_class.for(alice)
obj = retraction.instance_variable_get(:@object)
expect {
retraction.subscribers
}.to raise_error RuntimeError, "HAX: you must set the subscribers manaully before unfriending" # TODO
end
it "returns manually set subscribers" do
retraction = described_class.for(alice)
retraction.subscribers = "fooey"
expect(retraction.subscribers).to eq("fooey")
end
end end
end end
end end
...@@ -420,6 +420,49 @@ describe Diaspora::Federation::Receive do ...@@ -420,6 +420,49 @@ describe Diaspora::Federation::Receive do
expect(contact).not_to be_nil expect(contact).not_to be_nil
expect(contact.sharing).to be_falsey expect(contact.sharing).to be_falsey
end end
context "Relayable" do
it "relays the retraction and destroys the relayable when the parent-author is local" do
local_post = FactoryGirl.create(:status_message, author: alice.person, public: true)
remote_comment = FactoryGirl.create(:comment, author: sender, post: local_post)
retraction = FactoryGirl.build(
:retraction_entity,
author: sender.diaspora_handle,
target_guid: remote_comment.guid,
target_type: "Comment"
)
comment_retraction = Retraction.for(remote_comment, alice)
expect(Retraction).to receive(:for).with(instance_of(Comment), alice).and_return(comment_retraction)
expect(comment_retraction).to receive(:defer_dispatch).with(alice)
expect(comment_retraction).to receive(:perform).and_call_original
expect_any_instance_of(Comment).to receive(:destroy!).and_call_original
Diaspora::Federation::Receive.retraction(retraction, nil)
expect(StatusMessage.exists?(guid: remote_comment.guid)).to be_falsey
end
it "destroys the relayable when the parent-author is not local" do
remote_post = FactoryGirl.create(:status_message, author: sender, public: true)
remote_comment = FactoryGirl.create(:comment, author: sender, post: remote_post)
retraction = FactoryGirl.build(
:retraction_entity,
author: sender.diaspora_handle,
target_guid: remote_comment.guid,
target_type: "Comment"
)
expect_any_instance_of(Comment).to receive(:destroy!).and_call_original
Diaspora::Federation::Receive.retraction(retraction, nil)
expect(StatusMessage.exists?(guid: remote_comment.guid)).to be_falsey
end
end
end end
describe ".status_message" do describe ".status_message" do
......
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