HCard: searchable is now a Boolean

This commit is contained in:
Benjamin Neff 2015-06-28 00:27:00 +02:00
parent e2f2ef9f78
commit 880d6b39d5
2 changed files with 35 additions and 24 deletions

View file

@ -97,7 +97,7 @@ module DiasporaFederation
# installations). # installations).
# #
# flag if a user is searchable by name # flag if a user is searchable by name
# @return [String] searchable flag # @return [Boolean] searchable flag
attr_reader :searchable attr_reader :searchable
# CSS selectors for finding all the hCard fields # CSS selectors for finding all the hCard fields
@ -189,7 +189,7 @@ module DiasporaFederation
@photo_medium_url = photo_from_doc(doc, :photo_medium) @photo_medium_url = photo_from_doc(doc, :photo_medium)
@photo_small_url = photo_from_doc(doc, :photo_small) @photo_small_url = photo_from_doc(doc, :photo_small)
@pubkey = content_from_doc(doc, :key) unless element_from_doc(doc, :key).nil? @pubkey = content_from_doc(doc, :key) unless element_from_doc(doc, :key).nil?
@searchable = content_from_doc(doc, :searchable) @searchable = content_from_doc(doc, :searchable) == "true"
# TODO: change me! ################### # TODO: change me! ###################
@first_name = content_from_doc(doc, :given_name) @first_name = content_from_doc(doc, :given_name)

View file

@ -105,7 +105,7 @@ HTML
context "generation" do context "generation" do
it "creates an instance from a data hash" do it "creates an instance from a data hash" do
hc = WebFinger::HCard.from_profile( hcard = WebFinger::HCard.from_profile(
guid: guid, guid: guid,
nickname: nickname, nickname: nickname,
full_name: name, full_name: name,
@ -118,7 +118,7 @@ HTML
first_name: first_name, first_name: first_name,
last_name: last_name last_name: last_name
) )
expect(hc.to_html).to eq(html) expect(hcard.to_html).to eq(html)
end end
it "fails if some params are missing" do it "fails if some params are missing" do
@ -141,19 +141,30 @@ HTML
context "parsing" do context "parsing" do
it "reads its own output" do it "reads its own output" do
hc = WebFinger::HCard.from_html(html) hcard = WebFinger::HCard.from_html(html)
expect(hc.guid).to eq(guid) expect(hcard.guid).to eq(guid)
expect(hc.nickname).to eq(nickname) expect(hcard.nickname).to eq(nickname)
expect(hc.full_name).to eq(name) expect(hcard.full_name).to eq(name)
expect(hc.url).to eq(url) expect(hcard.url).to eq(url)
expect(hc.photo_full_url).to eq(photo_url) expect(hcard.photo_full_url).to eq(photo_url)
expect(hc.photo_medium_url).to eq(photo_url_m) expect(hcard.photo_medium_url).to eq(photo_url_m)
expect(hc.photo_small_url).to eq(photo_url_s) expect(hcard.photo_small_url).to eq(photo_url_s)
expect(hc.pubkey).to eq(key) expect(hcard.pubkey).to eq(key)
expect(hc.searchable).to eq(searchable.to_s) expect(hcard.searchable).to eq(searchable)
expect(hc.first_name).to eq(first_name) expect(hcard.first_name).to eq(first_name)
expect(hc.last_name).to eq(last_name) expect(hcard.last_name).to eq(last_name)
end
it "searchable is false, if it is empty in html" do
changed_html = html.sub(
"class=\"searchable\">#{searchable}<",
"class=\"searchable\"><"
)
hcard = WebFinger::HCard.from_html(changed_html)
expect(hcard.searchable).to eq(false)
end end
it "reads old-style HTML" do it "reads old-style HTML" do
@ -222,15 +233,15 @@ HTML
</div> </div>
HTML HTML
hc = WebFinger::HCard.from_html(historic_html) hcard = WebFinger::HCard.from_html(historic_html)
expect(hc.url).to eq(url) expect(hcard.url).to eq(url)
expect(hc.photo_full_url).to eq(photo_url) expect(hcard.photo_full_url).to eq(photo_url)
expect(hc.photo_medium_url).to eq(photo_url_m) expect(hcard.photo_medium_url).to eq(photo_url_m)
expect(hc.photo_small_url).to eq(photo_url_s) expect(hcard.photo_small_url).to eq(photo_url_s)
expect(hc.searchable).to eq(searchable.to_s) expect(hcard.searchable).to eq(searchable)
expect(hc.first_name).to eq(first_name) expect(hcard.first_name).to eq(first_name)
expect(hc.last_name).to eq(last_name) expect(hcard.last_name).to eq(last_name)
end end
it "fails if the document is incomplete" do it "fails if the document is incomplete" do