Loading app/services/diaspora_link_service.rb +6 −4 Original line number Diff line number Diff line Loading @@ -10,8 +10,10 @@ class DiasporaLinkService end def find_or_fetch_entity if type && guid entity_finder.find || fetch_entity end end private Loading @@ -38,8 +40,8 @@ class DiasporaLinkService def parse normalize match = DiasporaFederation::Federation::DiasporaUrlParser::DIASPORA_URL_REGEX.match(link) @author = match[1] @type = match[2] @guid = match[3] if match @author, @type, @guid = match.captures end end end spec/services/diaspora_link_service_spec.rb +12 −0 Original line number Diff line number Diff line Loading @@ -40,5 +40,17 @@ describe DiasporaLinkService do expect(service.find_or_fetch_entity).to be_nil end end context "with invalid links" do it "returns nil when the link is invalid" do service = described_class.new("web+diaspora://something_invalid") expect(service.find_or_fetch_entity).to be_nil end it "returns nil when the author is valid, but rest of the link is invalid" do service = described_class.new("web+diaspora://#{alice.diaspora_handle}/foo/bar") expect(service.find_or_fetch_entity).to be_nil end end end end Loading
app/services/diaspora_link_service.rb +6 −4 Original line number Diff line number Diff line Loading @@ -10,8 +10,10 @@ class DiasporaLinkService end def find_or_fetch_entity if type && guid entity_finder.find || fetch_entity end end private Loading @@ -38,8 +40,8 @@ class DiasporaLinkService def parse normalize match = DiasporaFederation::Federation::DiasporaUrlParser::DIASPORA_URL_REGEX.match(link) @author = match[1] @type = match[2] @guid = match[3] if match @author, @type, @guid = match.captures end end end
spec/services/diaspora_link_service_spec.rb +12 −0 Original line number Diff line number Diff line Loading @@ -40,5 +40,17 @@ describe DiasporaLinkService do expect(service.find_or_fetch_entity).to be_nil end end context "with invalid links" do it "returns nil when the link is invalid" do service = described_class.new("web+diaspora://something_invalid") expect(service.find_or_fetch_entity).to be_nil end it "returns nil when the author is valid, but rest of the link is invalid" do service = described_class.new("web+diaspora://#{alice.diaspora_handle}/foo/bar") expect(service.find_or_fetch_entity).to be_nil end end end end