~srushe/indieweb-authorship

de02072befc5fb0bcfd70a0fa62480510df39009 — Barry Frost 1 year, 7 months ago 61babb4
Allow for h-cards without a photo.
M lib/indieweb/authorship.rb => lib/indieweb/authorship.rb +1 -1
@@ 35,7 35,7 @@ module Indieweb
          return hcard_data_for(
            URI.join(url, hcard['properties']['url'][0]).to_s,
            hcard['properties']['name'][0],
            URI.join(url, hcard['properties']['photo'][0]).to_s
            hcard['properties'].key?('photo') ? URI.join(url, hcard['properties']['photo'][0]).to_s : nil
          )

        # 5.2. otherwise if author property is an http(s) URL, let the

A spec/examples/h-entry-has-h-card-with-no-photo => spec/examples/h-entry-has-h-card-with-no-photo +27 -0
@@ 0,0 1,27 @@
HTTP/1.1 200 OK
Server: Apache
Date: Wed, 09 Dec 2015 03:29:14 GMT
Content-Type: text/html; charset=utf-8

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Example</title>
</head>
<body>

  <div class="h-entry">

    <div class="p-author h-card">
      <a href="/about" class="u-url">
        <span class="p-name">Author</span>
      </a>
    </div>

    <p class="p-name e-content">Hello World</p>
    
  </div>

</body>
</html>
\ No newline at end of file

A spec/h-entry-has-h-card-with-no-photo_spec.rb => spec/h-entry-has-h-card-with-no-photo_spec.rb +26 -0
@@ 0,0 1,26 @@
RSpec.describe Indieweb::Authorship do
  let(:page) { 'h-entry-has-h-card-with-no-photo' }
  let(:url) { "http://author.example.com/#{page}" }
  let(:html) { html_for(page) }
  let(:linked_url) { 'http://author.example.com/about' }
  let(:expected_data) do
    {
      'url' => 'http://author.example.com/about',
      'name' => 'Author',
      'photo' => nil
    }
  end

  before do
    allow(Net::HTTP).to receive(:get).with(URI(url)) { html }
    allow(Net::HTTP).to receive(:get).with(linked_url) { html_for('about') }
  end

  context 'when given just a URL' do
    it { expect(described_class.identify(url)).to eq expected_data }
  end

  context 'when given both a URL and HTML' do
    it { expect(described_class.identify(url, html)).to eq expected_data }
  end
end