From 880d6b39d539db4f8a615e648263772ac65f12db Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Sun, 28 Jun 2015 00:27:00 +0200 Subject: [PATCH] HCard: searchable is now a Boolean --- lib/diaspora_federation/web_finger/h_card.rb | 4 +- .../web_finger/h_card_spec.rb | 55 +++++++++++-------- 2 files changed, 35 insertions(+), 24 deletions(-) diff --git a/lib/diaspora_federation/web_finger/h_card.rb b/lib/diaspora_federation/web_finger/h_card.rb index ecc37a0..c66d16a 100644 --- a/lib/diaspora_federation/web_finger/h_card.rb +++ b/lib/diaspora_federation/web_finger/h_card.rb @@ -97,7 +97,7 @@ module DiasporaFederation # installations). # # flag if a user is searchable by name - # @return [String] searchable flag + # @return [Boolean] searchable flag attr_reader :searchable # CSS selectors for finding all the hCard fields @@ -189,7 +189,7 @@ module DiasporaFederation @photo_medium_url = photo_from_doc(doc, :photo_medium) @photo_small_url = photo_from_doc(doc, :photo_small) @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! ################### @first_name = content_from_doc(doc, :given_name) diff --git a/spec/lib/diaspora_federation/web_finger/h_card_spec.rb b/spec/lib/diaspora_federation/web_finger/h_card_spec.rb index 4727cd3..cabcde4 100644 --- a/spec/lib/diaspora_federation/web_finger/h_card_spec.rb +++ b/spec/lib/diaspora_federation/web_finger/h_card_spec.rb @@ -105,7 +105,7 @@ HTML context "generation" do it "creates an instance from a data hash" do - hc = WebFinger::HCard.from_profile( + hcard = WebFinger::HCard.from_profile( guid: guid, nickname: nickname, full_name: name, @@ -118,7 +118,7 @@ HTML first_name: first_name, last_name: last_name ) - expect(hc.to_html).to eq(html) + expect(hcard.to_html).to eq(html) end it "fails if some params are missing" do @@ -141,19 +141,30 @@ HTML context "parsing" do it "reads its own output" do - hc = WebFinger::HCard.from_html(html) - expect(hc.guid).to eq(guid) - expect(hc.nickname).to eq(nickname) - expect(hc.full_name).to eq(name) - expect(hc.url).to eq(url) - expect(hc.photo_full_url).to eq(photo_url) - expect(hc.photo_medium_url).to eq(photo_url_m) - expect(hc.photo_small_url).to eq(photo_url_s) - expect(hc.pubkey).to eq(key) - expect(hc.searchable).to eq(searchable.to_s) + hcard = WebFinger::HCard.from_html(html) + expect(hcard.guid).to eq(guid) + expect(hcard.nickname).to eq(nickname) + expect(hcard.full_name).to eq(name) + expect(hcard.url).to eq(url) + expect(hcard.photo_full_url).to eq(photo_url) + expect(hcard.photo_medium_url).to eq(photo_url_m) + expect(hcard.photo_small_url).to eq(photo_url_s) + expect(hcard.pubkey).to eq(key) + expect(hcard.searchable).to eq(searchable) - expect(hc.first_name).to eq(first_name) - expect(hc.last_name).to eq(last_name) + expect(hcard.first_name).to eq(first_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 it "reads old-style HTML" do @@ -222,15 +233,15 @@ HTML HTML - hc = WebFinger::HCard.from_html(historic_html) - expect(hc.url).to eq(url) - expect(hc.photo_full_url).to eq(photo_url) - expect(hc.photo_medium_url).to eq(photo_url_m) - expect(hc.photo_small_url).to eq(photo_url_s) - expect(hc.searchable).to eq(searchable.to_s) + hcard = WebFinger::HCard.from_html(historic_html) + expect(hcard.url).to eq(url) + expect(hcard.photo_full_url).to eq(photo_url) + expect(hcard.photo_medium_url).to eq(photo_url_m) + expect(hcard.photo_small_url).to eq(photo_url_s) + expect(hcard.searchable).to eq(searchable) - expect(hc.first_name).to eq(first_name) - expect(hc.last_name).to eq(last_name) + expect(hcard.first_name).to eq(first_name) + expect(hcard.last_name).to eq(last_name) end it "fails if the document is incomplete" do