write more tests for retractions

This commit is contained in:
Benjamin Neff 2016-03-29 02:30:43 +02:00
parent f88a3abb3d
commit 2db0931ce5
8 changed files with 46 additions and 1 deletions

View file

@ -44,7 +44,7 @@ module DiasporaFederation
def self.fetch_target(target_type, target_guid)
DiasporaFederation.callbacks.trigger(:fetch_related_entity, target_type, target_guid).tap do |target|
raise TargetNotFound unless target
raise TargetNotFound, "not found: #{target_type}:#{target_guid}" unless target
end
end
private_class_method :fetch_target

View file

@ -37,6 +37,8 @@ XML
it_behaves_like "an XML Entity", %i(parent_author_signature target_author_signature)
it_behaves_like "a retraction"
describe "#to_xml" do
let(:author_pkey) { OpenSSL::PKey::RSA.generate(1024) }
let(:hash) { FactoryGirl.attributes_for(:relayable_retraction_entity) }

View file

@ -24,5 +24,7 @@ XML
it_behaves_like "an Entity subclass", [:target]
it_behaves_like "an XML Entity"
it_behaves_like "a retraction"
end
end

View file

@ -27,6 +27,8 @@ XML
it_behaves_like "an XML Entity", [:target_author_signature]
it_behaves_like "a retraction"
describe "#to_xml" do
let(:author_pkey) { OpenSSL::PKey::RSA.generate(1024) }
let(:hash) { FactoryGirl.attributes_for(:signed_retraction_entity) }

View file

@ -17,5 +17,13 @@ module DiasporaFederation
let(:property) { :target_type }
end
end
describe "#target" do
it_behaves_like "a property with a value validation/restriction" do
let(:property) { :target }
let(:wrong_values) { [nil] }
let(:correct_values) { [FactoryGirl.build(:related_entity)] }
end
end
end
end

View file

@ -17,5 +17,13 @@ module DiasporaFederation
let(:property) { :target_type }
end
end
describe "#target" do
it_behaves_like "a property with a value validation/restriction" do
let(:property) { :target }
let(:wrong_values) { [nil] }
let(:correct_values) { [FactoryGirl.build(:related_entity)] }
end
end
end
end

View file

@ -17,5 +17,13 @@ module DiasporaFederation
let(:property) { :target_type }
end
end
describe "#target" do
it_behaves_like "a property with a value validation/restriction" do
let(:property) { :target }
let(:wrong_values) { [nil] }
let(:correct_values) { [FactoryGirl.build(:related_entity)] }
end
end
end
end

View file

@ -92,3 +92,18 @@ shared_examples "a relayable Entity" do
end
end
end
shared_examples "a retraction" do
context "receive with no target found" do
let(:unknown_guid) { FactoryGirl.generate(:guid) }
let(:instance) { described_class.new(data.merge(target_guid: unknown_guid)) }
it "raises when no target is found" do
xml = instance.to_xml
expect {
described_class.from_xml(xml)
}.to raise_error DiasporaFederation::Entities::Retraction::TargetNotFound,
"not found: #{data[:target_type]}:#{unknown_guid}"
end
end
end