Commit e1db8da3c08b21fc00b7f120f76539e1719664ed
Committed by
Antonio Terceiro
1 parent
959d88c4
Exists in
master
and in
28 other branches
ActionItem1114: reorder entries in feed block
fixed also a test in the feed_handler that relied in the order of the items
Showing
3 changed files
with
10 additions
and
2 deletions
Show diff stats
app/models/feed_reader_block.rb
@@ -41,7 +41,7 @@ class FeedReaderBlock < Block | @@ -41,7 +41,7 @@ class FeedReaderBlock < Block | ||
41 | end | 41 | end |
42 | 42 | ||
43 | def add_item(title, link, date, content) | 43 | def add_item(title, link, date, content) |
44 | - self.feed_items << {:title => title, :link => link} | 44 | + self.feed_items.unshift( {:title => title, :link => link}) |
45 | end | 45 | end |
46 | 46 | ||
47 | def clear | 47 | def clear |
test/unit/feed_handler_test.rb
@@ -26,7 +26,7 @@ class FeedHandlerTest < Test::Unit::TestCase | @@ -26,7 +26,7 @@ class FeedHandlerTest < Test::Unit::TestCase | ||
26 | should 'process feed and populate container' do | 26 | should 'process feed and populate container' do |
27 | handler.process(container) | 27 | handler.process(container) |
28 | assert_equal 'Feed for unit tests', container.feed_title | 28 | assert_equal 'Feed for unit tests', container.feed_title |
29 | - assert_equal ["First POST", "Second POST", "Last POST"], container.feed_items.map {|item| item[:title]} | 29 | + assert_equivalent ["First POST", "Second POST", "Last POST"], container.feed_items.map {|item| item[:title]} |
30 | end | 30 | end |
31 | 31 | ||
32 | should 'raise exception when parser nil' do | 32 | should 'raise exception when parser nil' do |
test/unit/feed_reader_block_test.rb
@@ -73,4 +73,12 @@ class FeedReaderBlockTest < ActiveSupport::TestCase | @@ -73,4 +73,12 @@ class FeedReaderBlockTest < ActiveSupport::TestCase | ||
73 | feed.finish_fetch | 73 | feed.finish_fetch |
74 | end | 74 | end |
75 | 75 | ||
76 | + should 'display the latest post first' do | ||
77 | + %w[ first-post second-post last-post ].each do |i| | ||
78 | + feed.add_item(i, "http://localhost/#{i}", Date.today, "some contet for #{i}") | ||
79 | + end | ||
80 | + | ||
81 | + assert_equal %w[ last-post second-post first-post ], feed.feed_items.map{|i|i[:title]} | ||
82 | + end | ||
83 | + | ||
76 | end | 84 | end |