add more shared examples

This commit is contained in:
Benjamin Neff 2015-09-27 03:17:45 +02:00
parent 5a81d38e60
commit 0848ada216
7 changed files with 103 additions and 1 deletions

View file

@ -109,7 +109,9 @@ module DiasporaFederation
HTML
}
it_behaves_like "an Entity subclass"
it_behaves_like "an Entity subclass" do
let(:xml) { nil } # disable to_xml test
end
context "generation" do
it "creates an instance from a data hash" do

View file

@ -3,6 +3,32 @@ module DiasporaFederation
let(:data) { FactoryGirl.attributes_for(:person_entity) }
let(:klass) { Entities::Person }
let(:xml) {
<<-XML
<person>
<guid>#{data[:guid]}</guid>
<diaspora_handle>#{data[:diaspora_id]}</diaspora_handle>
<url>#{data[:url]}</url>
<profile>
<diaspora_handle>#{data[:profile].diaspora_id}</diaspora_handle>
<first_name>#{data[:profile].first_name}</first_name>
<last_name/>
<image_url>#{data[:profile].image_url}</image_url>
<image_url_medium>#{data[:profile].image_url}</image_url_medium>
<image_url_small>#{data[:profile].image_url}</image_url_small>
<birthday>#{data[:profile].birthday}</birthday>
<gender>#{data[:profile].gender}</gender>
<bio>#{data[:profile].bio}</bio>
<location>#{data[:profile].location}</location>
<searchable>#{data[:profile].searchable}</searchable>
<nsfw>#{data[:profile].nsfw}</nsfw>
<tag_string>#{data[:profile].tag_string}</tag_string>
</profile>
<exported_key>#{data[:exported_key]}</exported_key>
</person>
XML
}
it_behaves_like "an Entity subclass"
end
end

View file

@ -3,6 +3,26 @@ module DiasporaFederation
let(:data) { FactoryGirl.attributes_for(:profile_entity) }
let(:klass) { Entities::Profile }
let(:xml) {
<<-XML
<profile>
<diaspora_handle>#{data[:diaspora_id]}</diaspora_handle>
<first_name>#{data[:first_name]}</first_name>
<last_name/>
<image_url>#{data[:image_url]}</image_url>
<image_url_medium>#{data[:image_url]}</image_url_medium>
<image_url_small>#{data[:image_url]}</image_url_small>
<birthday>#{data[:birthday]}</birthday>
<gender>#{data[:gender]}</gender>
<bio>#{data[:bio]}</bio>
<location>#{data[:location]}</location>
<searchable>#{data[:searchable]}</searchable>
<nsfw>#{data[:nsfw]}</nsfw>
<tag_string>#{data[:tag_string]}</tag_string>
</profile>
XML
}
it_behaves_like "an Entity subclass"
end
end

View file

@ -113,5 +113,15 @@ XML
end
end
end
context "generated instance" do
subject { Salmon::EncryptedSlap.from_xml(slap_xml, okey) }
it "should have cipher params set" do
expect(subject.cipher_params).to_not be_nil
end
it_behaves_like "a Slap instance"
end
end
end

View file

@ -72,5 +72,11 @@ XML
end
end
end
context "generated instance" do
it_behaves_like "a Slap instance" do
subject { Salmon::Slap.from_xml(slap) }
end
end
end
end

View file

@ -29,5 +29,11 @@ shared_examples "an Entity subclass" do
expect(instance.to_h).to eq(data)
end
end
describe "#to_xml" do
it "produces correct XML" do
expect(instance.to_xml.to_s.strip).to eq(xml.strip) unless xml.nil?
end
end
end
end

View file

@ -0,0 +1,32 @@
shared_examples "a Slap instance" do
it "should match the author_id" do
expect(subject.author_id).to eq(author_id)
end
context "#entity" do
it "requires the pubkey for the first time (to verify the signature)" do
expect { subject.entity }.to raise_error
end
it "works when the pubkey is given" do
expect {
subject.entity(pkey.public_key)
}.not_to raise_error
end
it "returns the entity" do
entity = subject.entity(pkey.public_key)
expect(entity).to be_an_instance_of DiasporaFederation::Entities::TestEntity
expect(entity.test).to eq("qwertzuiop")
end
it "does not require the pubkey in consecutive calls" do
e1, e2 = nil
expect {
e1 = subject.entity(pkey.public_key)
e2 = subject.entity
}.not_to raise_error
expect(e1).to eq(e2)
end
end
end