write more tests for retractions
This commit is contained in:
parent
f88a3abb3d
commit
2db0931ce5
8 changed files with 46 additions and 1 deletions
|
|
@ -44,7 +44,7 @@ module DiasporaFederation
|
||||||
|
|
||||||
def self.fetch_target(target_type, target_guid)
|
def self.fetch_target(target_type, target_guid)
|
||||||
DiasporaFederation.callbacks.trigger(:fetch_related_entity, target_type, target_guid).tap do |target|
|
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
|
||||||
end
|
end
|
||||||
private_class_method :fetch_target
|
private_class_method :fetch_target
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,8 @@ XML
|
||||||
|
|
||||||
it_behaves_like "an XML Entity", %i(parent_author_signature target_author_signature)
|
it_behaves_like "an XML Entity", %i(parent_author_signature target_author_signature)
|
||||||
|
|
||||||
|
it_behaves_like "a retraction"
|
||||||
|
|
||||||
describe "#to_xml" do
|
describe "#to_xml" do
|
||||||
let(:author_pkey) { OpenSSL::PKey::RSA.generate(1024) }
|
let(:author_pkey) { OpenSSL::PKey::RSA.generate(1024) }
|
||||||
let(:hash) { FactoryGirl.attributes_for(:relayable_retraction_entity) }
|
let(:hash) { FactoryGirl.attributes_for(:relayable_retraction_entity) }
|
||||||
|
|
|
||||||
|
|
@ -24,5 +24,7 @@ XML
|
||||||
it_behaves_like "an Entity subclass", [:target]
|
it_behaves_like "an Entity subclass", [:target]
|
||||||
|
|
||||||
it_behaves_like "an XML Entity"
|
it_behaves_like "an XML Entity"
|
||||||
|
|
||||||
|
it_behaves_like "a retraction"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,8 @@ XML
|
||||||
|
|
||||||
it_behaves_like "an XML Entity", [:target_author_signature]
|
it_behaves_like "an XML Entity", [:target_author_signature]
|
||||||
|
|
||||||
|
it_behaves_like "a retraction"
|
||||||
|
|
||||||
describe "#to_xml" do
|
describe "#to_xml" do
|
||||||
let(:author_pkey) { OpenSSL::PKey::RSA.generate(1024) }
|
let(:author_pkey) { OpenSSL::PKey::RSA.generate(1024) }
|
||||||
let(:hash) { FactoryGirl.attributes_for(:signed_retraction_entity) }
|
let(:hash) { FactoryGirl.attributes_for(:signed_retraction_entity) }
|
||||||
|
|
|
||||||
|
|
@ -17,5 +17,13 @@ module DiasporaFederation
|
||||||
let(:property) { :target_type }
|
let(:property) { :target_type }
|
||||||
end
|
end
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -17,5 +17,13 @@ module DiasporaFederation
|
||||||
let(:property) { :target_type }
|
let(:property) { :target_type }
|
||||||
end
|
end
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -17,5 +17,13 @@ module DiasporaFederation
|
||||||
let(:property) { :target_type }
|
let(:property) { :target_type }
|
||||||
end
|
end
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -92,3 +92,18 @@ shared_examples "a relayable Entity" do
|
||||||
end
|
end
|
||||||
end
|
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
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue