Commit b443571b3a01df50cf007e97afeb42b5ddb2d6e4
1 parent
e2a20332
Exists in
master
and in
28 other branches
ActionItem23: checkpoint
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1121 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
2 changed files
with
81 additions
and
19 deletions
Show diff stats
app/models/rss_feed.rb
| ... | ... | @@ -17,8 +17,16 @@ class RssFeed < Article |
| 17 | 17 | 'text/xml' |
| 18 | 18 | end |
| 19 | 19 | |
| 20 | - # FIXME - feed real data into the RSS feed | |
| 20 | + # FIXME feed real data into the RSS feed | |
| 21 | 21 | def data |
| 22 | + articles = | |
| 23 | + if (self.settings[:include] == :parent_and_children) && self.parent | |
| 24 | + self.parent.map_traversal | |
| 25 | + else | |
| 26 | + profile.recent_documents(10) | |
| 27 | + end | |
| 28 | + | |
| 29 | + | |
| 22 | 30 | result = "" |
| 23 | 31 | xml = Builder::XmlMarkup.new(:target => result) |
| 24 | 32 | |
| ... | ... | @@ -29,14 +37,20 @@ class RssFeed < Article |
| 29 | 37 | xml.link("http://www.yourDomain.com") |
| 30 | 38 | xml.description('Description here') |
| 31 | 39 | xml.language("pt_BR") |
| 32 | - for article in profile.recent_documents(10) | |
| 33 | - xml.item do | |
| 34 | - xml.title(article.name) | |
| 35 | - xml.description(article.abstract) | |
| 36 | - # rfc822 | |
| 37 | - xml.pubDate(article.created_on.rfc2822) | |
| 38 | - xml.link("http://www.yourDomain.com/linkToYourPost") | |
| 39 | - xml.guid("http://www.yourDomain.com/linkToYourPost") | |
| 40 | + for article in articles | |
| 41 | + unless self == article | |
| 42 | + xml.item do | |
| 43 | + xml.title(article.name) | |
| 44 | + if self.settings[:description] == :body | |
| 45 | + xml.description(article.body) | |
| 46 | + else | |
| 47 | + xml.description(article.abstract) | |
| 48 | + end | |
| 49 | + # rfc822 | |
| 50 | + xml.pubDate(article.created_on.rfc2822) | |
| 51 | + xml.link("http://www.yourDomain.com/linkToYourPost") | |
| 52 | + xml.guid("http://www.yourDomain.com/linkToYourPost") | |
| 53 | + end | |
| 40 | 54 | end |
| 41 | 55 | end |
| 42 | 56 | end | ... | ... |
test/unit/rss_feed_test.rb
| ... | ... | @@ -11,8 +11,8 @@ class RssFeedTest < Test::Unit::TestCase |
| 11 | 11 | assert_kind_of Hash, feed.body |
| 12 | 12 | |
| 13 | 13 | feed.body = { |
| 14 | - :include => :abstract, | |
| 15 | - :search => :parent, | |
| 14 | + :description => :abstract, | |
| 15 | + :search => :parent_and_children, | |
| 16 | 16 | } |
| 17 | 17 | feed.valid? |
| 18 | 18 | assert !feed.errors.invalid?(:body) |
| ... | ... | @@ -34,9 +34,23 @@ class RssFeedTest < Test::Unit::TestCase |
| 34 | 34 | feed.save! |
| 35 | 35 | |
| 36 | 36 | rss = feed.data |
| 37 | - assert_match /<title>article 1<\/title>/, rss | |
| 38 | - assert_match /<title>article 2<\/title>/, rss | |
| 39 | - assert_match /<title>article 3<\/title>/, rss | |
| 37 | + assert_match /<item><title>article 1<\/title>/, rss | |
| 38 | + assert_match /<item><title>article 2<\/title>/, rss | |
| 39 | + assert_match /<item><title>article 3<\/title>/, rss | |
| 40 | + end | |
| 41 | + | |
| 42 | + should 'not list self' do | |
| 43 | + profile = create_user('testuser').person | |
| 44 | + a1 = profile.articles.build(:name => 'article 1'); a1.save! | |
| 45 | + a2 = profile.articles.build(:name => 'article 2'); a2.save! | |
| 46 | + a3 = profile.articles.build(:name => 'article 3'); a3.save! | |
| 47 | + | |
| 48 | + feed = RssFeed.new(:name => 'feed') | |
| 49 | + feed.profile = profile | |
| 50 | + feed.save! | |
| 51 | + | |
| 52 | + rss = feed.data | |
| 53 | + assert_no_match /<item><title>feed<\/title>/, rss | |
| 40 | 54 | end |
| 41 | 55 | |
| 42 | 56 | should 'list recent article from parent article' do |
| ... | ... | @@ -49,13 +63,47 @@ class RssFeedTest < Test::Unit::TestCase |
| 49 | 63 | end |
| 50 | 64 | |
| 51 | 65 | should 'be able to choose to put abstract or entire body on feed' do |
| 52 | - #feed = RssFeed.new | |
| 53 | - #feed. | |
| 54 | - flunk 'pending' | |
| 66 | + profile = create_user('testuser').person | |
| 67 | + a1 = profile.articles.build(:name => 'article 1', :abstract => 'my abstract', :body => 'my text'); a1.save! | |
| 68 | + | |
| 69 | + feed = RssFeed.new(:name => 'feed') | |
| 70 | + feed.profile = profile | |
| 71 | + feed.save! | |
| 72 | + | |
| 73 | + rss = feed.data | |
| 74 | + assert_match /<description>my abstract<\/description>/, rss | |
| 75 | + assert_no_match /<description>my text<\/description>/, rss | |
| 76 | + | |
| 77 | + feed.settings[:description] = :body | |
| 78 | + rss = feed.data | |
| 79 | + assert_match /<description>my text<\/description>/, rss | |
| 80 | + assert_no_match /<description>my abstract<\/description>/, rss | |
| 55 | 81 | end |
| 56 | 82 | |
| 57 | - should 'be able to choose search in all articles or in subarticles of parent' do | |
| 58 | - flunk 'pending' | |
| 83 | + should "be able to search only children of feed's parent" do | |
| 84 | + profile = create_user('testuser').person | |
| 85 | + a1 = profile.articles.build(:name => 'article 1'); a1.save! | |
| 86 | + a2 = profile.articles.build(:name => 'article 2'); a2.save! | |
| 87 | + | |
| 88 | + a3 = profile.articles.build(:name => 'article 3'); a3.save! | |
| 89 | + a3_1 = a3.children.build(:name => 'article 3.1', :parent => a3, :profile => profile); a3_1.save! | |
| 90 | + a3_2 = a3.children.build(:name => 'article 3.2', :parent => a3, :profile => profile); a3_2.save! | |
| 91 | + a3_2_1 = a3_2.children.build(:name => 'article 3.2.1', :parent => a3_2, :profile => profile); a3_2_1.save! | |
| 92 | + | |
| 93 | + feed = RssFeed.new(:name => 'feed') | |
| 94 | + feed.parent = a3 | |
| 95 | + feed.profile = profile | |
| 96 | + feed.settings[:include] = :parent_and_children | |
| 97 | + feed.save! | |
| 98 | + | |
| 99 | + rss = feed.data | |
| 100 | + assert_match /<item><title>article 3<\/title>/, rss | |
| 101 | + assert_match /<item><title>article 3\.1<\/title>/, rss | |
| 102 | + assert_match /<item><title>article 3\.2<\/title>/, rss | |
| 103 | + assert_match /<item><title>article 3\.2\.1<\/title>/, rss | |
| 104 | + | |
| 105 | + assert_no_match /<item><title>article 1<\/title>/, rss | |
| 106 | + assert_no_match /<item><title>article 2<\/title>/, rss | |
| 59 | 107 | end |
| 60 | 108 | |
| 61 | 109 | should 'be able to indicate maximum number of items' do | ... | ... |