Skip to content

Commit

Permalink
Merge pull request stringer-rss#479 from naps62/mp/fix-enclosure-url
Browse files Browse the repository at this point in the history
Prevents crash when both url and enclosure_url dont exist
  • Loading branch information
gabrielpoca authored Mar 30, 2018
2 parents fee8ae1 + c84d7b8 commit 2ac95a2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/repositories/story_repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def self.read_count
end

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

normalize_url(entry.url, feed.url) unless entry.url.nil?
end
Expand Down
7 changes: 7 additions & 0 deletions spec/repositories/story_repository_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@

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

it "does not crash if url is nil but enclosure_url does not exist" do
feed = double(url: "http://github.com")
entry = double(url: nil)

expect(StoryRepository.extract_url(entry, feed)).to eq nil
end
end

describe ".extract_title" do
Expand Down
3 changes: 0 additions & 3 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
require "ostruct"
require "date"

require "coveralls"
Coveralls.wear!

require "factories/feed_factory"
require "factories/story_factory"
require "factories/user_factory"
Expand Down

0 comments on commit 2ac95a2

Please sign in to comment.