diff --git a/app/models/feed_reader_block.rb b/app/models/feed_reader_block.rb index 7905ab8..fb1eb6d 100644 --- a/app/models/feed_reader_block.rb +++ b/app/models/feed_reader_block.rb @@ -41,7 +41,7 @@ class FeedReaderBlock < Block end def add_item(title, link, date, content) - self.feed_items << {:title => title, :link => link} + self.feed_items.unshift( {:title => title, :link => link}) end def clear diff --git a/test/unit/feed_handler_test.rb b/test/unit/feed_handler_test.rb index 3e27f1d..ea1b3e6 100644 --- a/test/unit/feed_handler_test.rb +++ b/test/unit/feed_handler_test.rb @@ -26,7 +26,7 @@ class FeedHandlerTest < Test::Unit::TestCase should 'process feed and populate container' do handler.process(container) assert_equal 'Feed for unit tests', container.feed_title - assert_equal ["First POST", "Second POST", "Last POST"], container.feed_items.map {|item| item[:title]} + assert_equivalent ["First POST", "Second POST", "Last POST"], container.feed_items.map {|item| item[:title]} end should 'raise exception when parser nil' do diff --git a/test/unit/feed_reader_block_test.rb b/test/unit/feed_reader_block_test.rb index 53eef41..8f9b127 100644 --- a/test/unit/feed_reader_block_test.rb +++ b/test/unit/feed_reader_block_test.rb @@ -73,4 +73,12 @@ class FeedReaderBlockTest < ActiveSupport::TestCase feed.finish_fetch end + should 'display the latest post first' do + %w[ first-post second-post last-post ].each do |i| + feed.add_item(i, "http://localhost/#{i}", Date.today, "some contet for #{i}") + end + + assert_equal %w[ last-post second-post first-post ], feed.feed_items.map{|i|i[:title]} + end + end -- libgit2 0.21.2