diaspora/spec/lib/postzord/receiver/private_spec.rb
Benjamin Neff 58a5a881cf receive local
* Contact: auto-follow-back
* Shareable: create share visibilities
2016-06-26 06:20:59 +02:00

63 lines
2.3 KiB
Ruby

# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require 'spec_helper'
describe Postzord::Receiver::Private do
before do
@alices_post = alice.build_post(:status_message, :text => "hey", :aspect_ids => [alice.aspects.first.id])
@salmon_xml = alice.salmon(@alices_post).xml_for(bob.person)
end
describe '.initialize' do
it 'valid for local' do
expect(Person).not_to receive(:find_or_fetch_by_identifier)
expect(Salmon::EncryptedSlap).not_to receive(:from_xml)
zord = Postzord::Receiver::Private.new(bob, :person => alice.person, :object => @alices_post)
expect(zord.instance_variable_get(:@user)).not_to be_nil
expect(zord.instance_variable_get(:@author)).not_to be_nil
expect(zord.instance_variable_get(:@object)).not_to be_nil
end
it 'valid for remote' do
salmon_double = double()
expect(salmon_double).to receive(:author_id).and_return(true)
expect(Salmon::EncryptedSlap).to receive(:from_xml).with(@salmon_xml, bob).and_return(salmon_double)
expect(Person).to receive(:find_or_fetch_by_identifier).and_return(true)
zord = Postzord::Receiver::Private.new(bob, :salmon_xml => @salmon_xml)
expect(zord.instance_variable_get(:@user)).not_to be_nil
expect(zord.instance_variable_get(:@author)).not_to be_nil
expect(zord.instance_variable_get(:@salmon_xml)).not_to be_nil
end
end
describe '#receive!' do
before do
@zord = Postzord::Receiver::Private.new(bob, :salmon_xml => @salmon_xml)
@salmon = @zord.instance_variable_get(:@salmon)
end
context "does not parse and receive" do
it "if the salmon author does not exist" do
@zord.instance_variable_set(:@author, nil)
expect(@zord).not_to receive(:parse_and_receive)
@zord.receive!
end
it "if the author does not match the signature" do
@zord.instance_variable_set(:@author, FactoryGirl.create(:person))
expect(@zord).not_to receive(:parse_and_receive)
@zord.receive!
end
end
it 'parses the salmon object' do
expect(Diaspora::Parser).to receive(:from_xml).with(@salmon.parsed_data).and_return(@alices_post)
@zord.receive!
end
end
end