Skip to content

Commit

Permalink
Use enclosure_url when url is missing
Browse files Browse the repository at this point in the history
Some feeds, especially the podcasts, don't have an URL for their
stories. That's fine, the url is not mandatory but we decided to link to
the media object when it is present and the url is not.
  • Loading branch information
gabrielpoca committed Dec 1, 2017
1 parent 3543597 commit b4ae4c1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
10 changes: 7 additions & 3 deletions app/repositories/story_repository.rb
Expand Up @@ -6,11 +6,9 @@ class StoryRepository
extend UrlHelpers

def self.add(entry, feed)
entry.url = normalize_url(entry.url, feed.url) unless entry.url.nil?

Story.create(feed: feed,
title: extract_title(entry),
permalink: entry.url,
permalink: extract_url(entry, feed),
body: extract_content(entry),
is_read: false,
is_starred: false,
Expand Down Expand Up @@ -83,6 +81,12 @@ def self.read_count
Story.where(is_read: true).count
end

def self.extract_url(entry, feed)
return entry.enclosure_url if entry.url.nil? && entry.enclosure_url.present?

normalize_url(entry.url, feed.url) unless entry.url.nil?
end

def self.extract_content(entry)
sanitized_content = ""

Expand Down
16 changes: 16 additions & 0 deletions spec/repositories/story_repository_spec.rb
Expand Up @@ -26,6 +26,22 @@
end
end

describe ".extract_url" do
it "returns the url" do
feed = double(url: "http://github.com")
entry = double(url: "https://github.com/swanson/stringer")

expect(StoryRepository.extract_url(entry, feed)).to eq "https://github.com/swanson/stringer"
end

it "returns the enclosure_url when the url is nil" do
feed = double(url: "http://github.com")
entry = double(url: nil, enclosure_url: "https://github.com/swanson/stringer")

expect(StoryRepository.extract_url(entry, feed)).to eq "https://github.com/swanson/stringer"
end
end

describe ".extract_title" do
let(:entry) do
end
Expand Down

0 comments on commit b4ae4c1

Please sign in to comment.