Skip to content

Commit

Permalink
blog title is set to author if author is blank
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigomanhaes committed Jan 14, 2011
1 parent be9c743 commit 5065f2a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
1 change: 1 addition & 0 deletions app/models/feed_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def entries
feeds = Feedzirra::Feed.fetch_and_parse(url)
begin
feeds.entries.each do |entry|
entry.author = feeds.title if entry.author.blank?
entry.author = entry.author.split('(')[1].chop if entry.author.include?('(')
entry.content = entry.summary unless entry.content.present?
entry.content.gsub!('href="/', 'href="https://github.com/') if entry.content.present? && github?
Expand Down
22 changes: 17 additions & 5 deletions spec/models/feed_source_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
require 'feedzirra'

class FakeEntry
def initialize(options)
@author = options[:author] || "anything"
def initialize(options = {})
@author = options[:author]
@content = options[:content]
@published = options[:published]
@title = options[:title]
Expand All @@ -24,7 +24,7 @@ def to_ary; nil; end
def stub_feed
@entries_result = [FakeEntry.new(:author => "",
:content => "need to have something here")]
stub(:entries => @entries_result)
stub(:entries => @entries_result, :title => '')
end


Expand Down Expand Up @@ -95,7 +95,8 @@ def fake_entry(description)
Feedzirra::Feed.stub(:fetch_and_parse).with('some_url').
and_return(stub(:entries => [entry_stub = fake_entry('nada'),
fake_entry('martinfowler started following planetansi'),
fake_entry('linustorvalds started watching planetansi')]))
fake_entry('linustorvalds started watching planetansi')],
:title => ''))
feed_source.feed_type = 'Blog'
feed_source.should have(3).entries

Expand All @@ -111,7 +112,7 @@ def ensure_idiosyncrasy(entry_options)
feed_source.feed_type = entry_options.delete(:feed_type) if entry_options.has_key?(:feed_type)
entry = FakeEntry.new(entry_options)
Feedzirra::Feed.should_receive(:fetch_and_parse).with('some_url').
and_return(stub(:entries => [entry]))
and_return(stub(:entries => [entry], :title => ''))
feed_source.entries
yield(entry)
end
Expand Down Expand Up @@ -170,6 +171,17 @@ def ensure_idiosyncrasy(entry_options)
end
end
end

context 'author field is blank' do
it 'puts blog title as author' do
Feedzirra::Feed.stub(:fetch_and_parse).
and_return(stub(:entries => [FakeEntry.new],
:title => 'My cool blog'))
FeedSource.stub(:find_all_by_feed_type).
and_return([FeedSource.new])
FeedSource.blogs[0].author.should == 'My cool blog'
end
end
end

context 'something wrong happens' do
Expand Down

0 comments on commit 5065f2a

Please sign in to comment.