add entities tests and shared examples for entities
This commit is contained in:
parent
fe704fb981
commit
2b8aad766d
5 changed files with 85 additions and 38 deletions
|
|
@ -5,6 +5,23 @@ module DiasporaFederation
|
||||||
let(:photo_medium_url) { "#{person.url}/upload/medium.png" }
|
let(:photo_medium_url) { "#{person.url}/upload/medium.png" }
|
||||||
let(:photo_small_url) { "#{person.url}/upload/small.png" }
|
let(:photo_small_url) { "#{person.url}/upload/small.png" }
|
||||||
|
|
||||||
|
let(:data) {
|
||||||
|
{
|
||||||
|
guid: person.guid,
|
||||||
|
nickname: person.nickname,
|
||||||
|
full_name: person.full_name,
|
||||||
|
url: person.url,
|
||||||
|
photo_large_url: photo_large_url,
|
||||||
|
photo_medium_url: photo_medium_url,
|
||||||
|
photo_small_url: photo_small_url,
|
||||||
|
public_key: person.serialized_public_key,
|
||||||
|
searchable: person.searchable,
|
||||||
|
first_name: person.first_name,
|
||||||
|
last_name: person.last_name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let(:klass) { Discovery::HCard }
|
||||||
|
|
||||||
let(:html) {
|
let(:html) {
|
||||||
<<-HTML
|
<<-HTML
|
||||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
|
||||||
|
|
@ -92,31 +109,13 @@ module DiasporaFederation
|
||||||
HTML
|
HTML
|
||||||
}
|
}
|
||||||
|
|
||||||
it "must not create blank instances" do
|
it_behaves_like "an Entity subclass"
|
||||||
expect { Discovery::HCard.new({}) }.to raise_error ArgumentError
|
|
||||||
end
|
|
||||||
|
|
||||||
context "generation" do
|
context "generation" do
|
||||||
it "creates an instance from a data hash" do
|
it "creates an instance from a data hash" do
|
||||||
hcard = Discovery::HCard.new(
|
hcard = Discovery::HCard.new(data)
|
||||||
guid: person.guid,
|
|
||||||
nickname: person.nickname,
|
|
||||||
full_name: person.full_name,
|
|
||||||
url: person.url,
|
|
||||||
photo_large_url: photo_large_url,
|
|
||||||
photo_medium_url: photo_medium_url,
|
|
||||||
photo_small_url: photo_small_url,
|
|
||||||
public_key: person.serialized_public_key,
|
|
||||||
searchable: person.searchable,
|
|
||||||
first_name: person.first_name,
|
|
||||||
last_name: person.last_name
|
|
||||||
)
|
|
||||||
expect(hcard.to_html).to eq(html)
|
expect(hcard.to_html).to eq(html)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "fails if nil was given" do
|
|
||||||
expect { Discovery::HCard.new(nil) }.to raise_error ArgumentError, "expected a Hash"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "parsing" do
|
context "parsing" do
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,21 @@ module DiasporaFederation
|
||||||
let(:acct) { "acct:#{person.diaspora_id}" }
|
let(:acct) { "acct:#{person.diaspora_id}" }
|
||||||
let(:public_key_base64) { Base64.strict_encode64(person.serialized_public_key) }
|
let(:public_key_base64) { Base64.strict_encode64(person.serialized_public_key) }
|
||||||
|
|
||||||
|
let(:data) {
|
||||||
|
{
|
||||||
|
acct_uri: "acct:#{person.diaspora_id}",
|
||||||
|
alias_url: person.alias_url,
|
||||||
|
hcard_url: person.hcard_url,
|
||||||
|
seed_url: person.url,
|
||||||
|
profile_url: person.profile_url,
|
||||||
|
atom_url: person.atom_url,
|
||||||
|
salmon_url: person.salmon_url,
|
||||||
|
guid: person.guid,
|
||||||
|
public_key: person.serialized_public_key
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let(:klass) { Discovery::WebFinger }
|
||||||
|
|
||||||
let(:xml) {
|
let(:xml) {
|
||||||
<<-XML
|
<<-XML
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
@ -21,29 +36,13 @@ module DiasporaFederation
|
||||||
XML
|
XML
|
||||||
}
|
}
|
||||||
|
|
||||||
it "must not create blank instances" do
|
it_behaves_like "an Entity subclass"
|
||||||
expect { Discovery::WebFinger.new({}) }.to raise_error ArgumentError
|
|
||||||
end
|
|
||||||
|
|
||||||
context "generation" do
|
context "generation" do
|
||||||
it "creates a nice XML document" do
|
it "creates a nice XML document" do
|
||||||
wf = Discovery::WebFinger.new(
|
wf = Discovery::WebFinger.new(data)
|
||||||
acct_uri: "acct:#{person.diaspora_id}",
|
|
||||||
alias_url: person.alias_url,
|
|
||||||
hcard_url: person.hcard_url,
|
|
||||||
seed_url: person.url,
|
|
||||||
profile_url: person.profile_url,
|
|
||||||
atom_url: person.atom_url,
|
|
||||||
salmon_url: person.salmon_url,
|
|
||||||
guid: person.guid,
|
|
||||||
public_key: person.serialized_public_key
|
|
||||||
)
|
|
||||||
expect(wf.to_xml).to eq(xml)
|
expect(wf.to_xml).to eq(xml)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "fails if nil was given" do
|
|
||||||
expect { Discovery::WebFinger.new(nil) }.to raise_error ArgumentError, "expected a Hash"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "parsing" do
|
context "parsing" do
|
||||||
|
|
|
||||||
8
spec/lib/diaspora_federation/entities/person_spec.rb
Normal file
8
spec/lib/diaspora_federation/entities/person_spec.rb
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
module DiasporaFederation
|
||||||
|
describe Entities::Person do
|
||||||
|
let(:data) { FactoryGirl.attributes_for(:person_entity) }
|
||||||
|
let(:klass) { Entities::Person }
|
||||||
|
|
||||||
|
it_behaves_like "an Entity subclass"
|
||||||
|
end
|
||||||
|
end
|
||||||
8
spec/lib/diaspora_federation/entities/profile_spec.rb
Normal file
8
spec/lib/diaspora_federation/entities/profile_spec.rb
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
module DiasporaFederation
|
||||||
|
describe Entities::Profile do
|
||||||
|
let(:data) { FactoryGirl.attributes_for(:profile_entity) }
|
||||||
|
let(:klass) { Entities::Profile }
|
||||||
|
|
||||||
|
it_behaves_like "an Entity subclass"
|
||||||
|
end
|
||||||
|
end
|
||||||
33
spec/support/shared_entity_specs.rb
Normal file
33
spec/support/shared_entity_specs.rb
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
shared_examples "an Entity subclass" do
|
||||||
|
it "should be an Entity" do
|
||||||
|
expect(klass).to be < DiasporaFederation::Entity
|
||||||
|
end
|
||||||
|
|
||||||
|
it "has its properties set" do
|
||||||
|
expect(klass.class_prop_names).to include(*data.keys)
|
||||||
|
end
|
||||||
|
|
||||||
|
context "behaviour" do
|
||||||
|
let(:instance) { klass.new(data) }
|
||||||
|
|
||||||
|
describe "initialize" do
|
||||||
|
it "must not create blank instances" do
|
||||||
|
expect { klass.new({}) }.to raise_error ArgumentError
|
||||||
|
end
|
||||||
|
|
||||||
|
it "fails if nil was given" do
|
||||||
|
expect { klass.new(nil) }.to raise_error ArgumentError, "expected a Hash"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should be frozen" do
|
||||||
|
expect(instance).to be_frozen
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "#to_h" do
|
||||||
|
it "should resemble the input data" do
|
||||||
|
expect(instance.to_h).to eq(data)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
Reference in a new issue