diff --git a/app/models/blog.rb b/app/models/blog.rb index 2512064..9f27b66 100644 --- a/app/models/blog.rb +++ b/app/models/blog.rb @@ -6,7 +6,7 @@ class Blog < Folder attr_accessor :filter after_create do |blog| - blog.children << RssFeed.new(:name => 'feed', :profile => blog.profile, :include => 'parent_and_children') + blog.children << RssFeed.new(:name => 'feed', :profile => blog.profile, :feed_item_description => 'body') blog.feed = blog.feed_attrs end diff --git a/app/models/rss_feed.rb b/app/models/rss_feed.rb index 67ac9d2..0a50b58 100644 --- a/app/models/rss_feed.rb +++ b/app/models/rss_feed.rb @@ -59,14 +59,20 @@ class RssFeed < Article end include ActionController::UrlWriter - def data + def fetch_articles + if parent && parent.blog? + return parent.posts.find(:all, :limit => self.limit, :order => 'id desc') + end + articles = if (self.include == 'parent_and_children') && self.parent self.parent.map_traversal else profile.recent_documents(self.limit || 10) end - + end + def data + articles = fetch_articles result = "" xml = Builder::XmlMarkup.new(:target => result) diff --git a/lib/acts_as_filesystem.rb b/lib/acts_as_filesystem.rb index 073c113..7e505a0 100644 --- a/lib/acts_as_filesystem.rb +++ b/lib/acts_as_filesystem.rb @@ -166,7 +166,7 @@ module ActsAsFileSystem result += current_level ids = current_level.select {|item| item.children_count > 0}.map(&:id) break if ids.empty? - current_level = self.class.find(:all, :conditions => { :parent_id => ids}) + current_level = self.class.base_class.find(:all, :conditions => { :parent_id => ids}) end block ||= (lambda { |x| x }) result.map(&block) diff --git a/test/unit/acts_as_filesystem_test.rb b/test/unit/acts_as_filesystem_test.rb index 518f81b..82739f1 100644 --- a/test/unit/acts_as_filesystem_test.rb +++ b/test/unit/acts_as_filesystem_test.rb @@ -73,6 +73,16 @@ class ActsAsFilesystemTest < Test::Unit::TestCase end + should 'be able to list text articles that are children of a folder' do + profile = create_user('testinguser').person + folder = Folder.create!(:name => 'folder', :profile => profile) + article1 = Article.create(:name => 'article 1', :profile => profile, :parent => folder) + article2 = Article.create(:name => 'article 2', :profile => profile, :parent => folder) + folder.reload + + assert_equal [folder, article1, article2], folder.map_traversal + end + should 'allow dots in slug' do assert_equal 'test.txt', Article.new(:name => 'test.txt').slug end diff --git a/test/unit/blog_test.rb b/test/unit/blog_test.rb index 0a54eb7..8a36433 100644 --- a/test/unit/blog_test.rb +++ b/test/unit/blog_test.rb @@ -32,6 +32,12 @@ class BlogTest < ActiveSupport::TestCase assert_kind_of RssFeed, b.feed end + should 'include articles body in feed by default' do + p = create_user('testuser').person + b = Blog.create!(:profile => p, :name => 'blog_feed_test') + assert_equal 'body', b.feed.feed_item_description + end + should 'get first blog from profile' do p = create_user('testuser').person b = Blog.create!(:profile => p, :name => 'blog_feed_test') diff --git a/test/unit/rss_feed_test.rb b/test/unit/rss_feed_test.rb index bd95ee8..389c5c1 100644 --- a/test/unit/rss_feed_test.rb +++ b/test/unit/rss_feed_test.rb @@ -107,6 +107,20 @@ class RssFeedTest < Test::Unit::TestCase assert_no_match /article 2<\/title>/, rss end + should 'list blog posts with more recent first and respecting limit' do + profile = create_user('testuser').person + blog = Blog.create(:name => 'blog', :profile => profile) + posts = [] + 6.times do |i| + posts << TextArticle.create!(:name => "post #{i}", :profile => profile, :parent => blog) + end + feed = blog.feed + feed.limit = 5 + feed.save! + + assert_equal [posts[5], posts[4], posts[3], posts[2], posts[1]], feed.fetch_articles + end + should 'provide link to profile' do profile = create_user('testuser').person feed = RssFeed.new(:name => 'testfeed') -- libgit2 0.21.2