Commit f9db76298c3d1b7d1f2042969528b7efb9c9f617
1 parent
15e3d3ad
Exists in
master
and in
29 other branches
ActionItem806: enhancements in RSS feed
Showing
6 changed files
with
40 additions
and
4 deletions
Show diff stats
app/models/blog.rb
| ... | ... | @@ -6,7 +6,7 @@ class Blog < Folder |
| 6 | 6 | attr_accessor :filter |
| 7 | 7 | |
| 8 | 8 | after_create do |blog| |
| 9 | - blog.children << RssFeed.new(:name => 'feed', :profile => blog.profile, :include => 'parent_and_children') | |
| 9 | + blog.children << RssFeed.new(:name => 'feed', :profile => blog.profile, :feed_item_description => 'body') | |
| 10 | 10 | blog.feed = blog.feed_attrs |
| 11 | 11 | end |
| 12 | 12 | ... | ... |
app/models/rss_feed.rb
| ... | ... | @@ -59,14 +59,20 @@ class RssFeed < Article |
| 59 | 59 | end |
| 60 | 60 | |
| 61 | 61 | include ActionController::UrlWriter |
| 62 | - def data | |
| 62 | + def fetch_articles | |
| 63 | + if parent && parent.blog? | |
| 64 | + return parent.posts.find(:all, :limit => self.limit, :order => 'id desc') | |
| 65 | + end | |
| 66 | + | |
| 63 | 67 | articles = |
| 64 | 68 | if (self.include == 'parent_and_children') && self.parent |
| 65 | 69 | self.parent.map_traversal |
| 66 | 70 | else |
| 67 | 71 | profile.recent_documents(self.limit || 10) |
| 68 | 72 | end |
| 69 | - | |
| 73 | + end | |
| 74 | + def data | |
| 75 | + articles = fetch_articles | |
| 70 | 76 | |
| 71 | 77 | result = "" |
| 72 | 78 | xml = Builder::XmlMarkup.new(:target => result) | ... | ... |
lib/acts_as_filesystem.rb
| ... | ... | @@ -166,7 +166,7 @@ module ActsAsFileSystem |
| 166 | 166 | result += current_level |
| 167 | 167 | ids = current_level.select {|item| item.children_count > 0}.map(&:id) |
| 168 | 168 | break if ids.empty? |
| 169 | - current_level = self.class.find(:all, :conditions => { :parent_id => ids}) | |
| 169 | + current_level = self.class.base_class.find(:all, :conditions => { :parent_id => ids}) | |
| 170 | 170 | end |
| 171 | 171 | block ||= (lambda { |x| x }) |
| 172 | 172 | result.map(&block) | ... | ... |
test/unit/acts_as_filesystem_test.rb
| ... | ... | @@ -73,6 +73,16 @@ class ActsAsFilesystemTest < Test::Unit::TestCase |
| 73 | 73 | |
| 74 | 74 | end |
| 75 | 75 | |
| 76 | + should 'be able to list text articles that are children of a folder' do | |
| 77 | + profile = create_user('testinguser').person | |
| 78 | + folder = Folder.create!(:name => 'folder', :profile => profile) | |
| 79 | + article1 = Article.create(:name => 'article 1', :profile => profile, :parent => folder) | |
| 80 | + article2 = Article.create(:name => 'article 2', :profile => profile, :parent => folder) | |
| 81 | + folder.reload | |
| 82 | + | |
| 83 | + assert_equal [folder, article1, article2], folder.map_traversal | |
| 84 | + end | |
| 85 | + | |
| 76 | 86 | should 'allow dots in slug' do |
| 77 | 87 | assert_equal 'test.txt', Article.new(:name => 'test.txt').slug |
| 78 | 88 | end | ... | ... |
test/unit/blog_test.rb
| ... | ... | @@ -32,6 +32,12 @@ class BlogTest < ActiveSupport::TestCase |
| 32 | 32 | assert_kind_of RssFeed, b.feed |
| 33 | 33 | end |
| 34 | 34 | |
| 35 | + should 'include articles body in feed by default' do | |
| 36 | + p = create_user('testuser').person | |
| 37 | + b = Blog.create!(:profile => p, :name => 'blog_feed_test') | |
| 38 | + assert_equal 'body', b.feed.feed_item_description | |
| 39 | + end | |
| 40 | + | |
| 35 | 41 | should 'get first blog from profile' do |
| 36 | 42 | p = create_user('testuser').person |
| 37 | 43 | b = Blog.create!(:profile => p, :name => 'blog_feed_test') | ... | ... |
test/unit/rss_feed_test.rb
| ... | ... | @@ -107,6 +107,20 @@ class RssFeedTest < Test::Unit::TestCase |
| 107 | 107 | assert_no_match /<item><title>article 2<\/title>/, rss |
| 108 | 108 | end |
| 109 | 109 | |
| 110 | + should 'list blog posts with more recent first and respecting limit' do | |
| 111 | + profile = create_user('testuser').person | |
| 112 | + blog = Blog.create(:name => 'blog', :profile => profile) | |
| 113 | + posts = [] | |
| 114 | + 6.times do |i| | |
| 115 | + posts << TextArticle.create!(:name => "post #{i}", :profile => profile, :parent => blog) | |
| 116 | + end | |
| 117 | + feed = blog.feed | |
| 118 | + feed.limit = 5 | |
| 119 | + feed.save! | |
| 120 | + | |
| 121 | + assert_equal [posts[5], posts[4], posts[3], posts[2], posts[1]], feed.fetch_articles | |
| 122 | + end | |
| 123 | + | |
| 110 | 124 | should 'provide link to profile' do |
| 111 | 125 | profile = create_user('testuser').person |
| 112 | 126 | feed = RssFeed.new(:name => 'testfeed') | ... | ... |