From d27a79ec04bd611e328d30a976bef7c8ad02526f Mon Sep 17 00:00:00 2001 From: Rodrigo Souto Date: Wed, 11 Aug 2010 11:15:02 -0300 Subject: [PATCH] Feed articles are listed even in private profiles --- app/models/profile.rb | 10 ++++++++++ app/models/rss_feed.rb | 2 +- test/unit/rss_feed_test.rb | 24 +++++++++++++++++++++--- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/app/models/profile.rb b/app/models/profile.rb index dca5508..089ff50 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -332,6 +332,16 @@ class Profile < ActiveRecord::Base self.articles.recent(limit, options) end + def last_articles(limit = 10, options = {}) + options = { :limit => limit, + :conditions => ["advertise = ? AND published = ? AND + ((articles.type != ? and articles.type != ? and articles.type != ?) OR + articles.type is NULL)", + true, true, 'UploadedFile', 'RssFeed', 'Blog'], + :order => 'articles.published_at desc, articles.id desc' }.merge(options) + self.articles.find(:all, options) + end + class << self # finds a profile by its identifier. This method is a shortcut to diff --git a/app/models/rss_feed.rb b/app/models/rss_feed.rb index cbaa98c..d2f821c 100644 --- a/app/models/rss_feed.rb +++ b/app/models/rss_feed.rb @@ -68,7 +68,7 @@ class RssFeed < Article if (self.include == 'parent_and_children') && self.parent self.parent.map_traversal else - profile.recent_documents(self.limit) + profile.last_articles(self.limit) end end def data diff --git a/test/unit/rss_feed_test.rb b/test/unit/rss_feed_test.rb index 73c477c..92d7c07 100644 --- a/test/unit/rss_feed_test.rb +++ b/test/unit/rss_feed_test.rb @@ -58,7 +58,7 @@ class RssFeedTest < Test::Unit::TestCase feed = RssFeed.new feed.expects(:profile).returns(profile).at_least_once array = [] - profile.expects(:recent_documents).returns(array) + profile.expects(:last_articles).returns(array) feed.data end @@ -150,11 +150,11 @@ class RssFeedTest < Test::Unit::TestCase feed.profile = profile feed.save! - feed.profile.expects(:recent_documents).with(10).returns([]).once + feed.profile.expects(:last_articles).with(10).returns([]).once feed.data feed.limit = 5 - feed.profile.expects(:recent_documents).with(5).returns([]).once + feed.profile.expects(:last_articles).with(5).returns([]).once feed.data end @@ -218,4 +218,22 @@ class RssFeedTest < Test::Unit::TestCase assert_match published_article.to_html, feed.data end + should 'display articles even within a private profile' do + profile = create_user('testuser').person + profile.public_profile = false + profile.save! + a1 = profile.articles.build(:name => 'article 1'); a1.save! + a2 = profile.articles.build(:name => 'article 2'); a2.save! + a3 = profile.articles.build(:name => 'article 3'); a3.save! + + feed = RssFeed.new(:name => 'testfeed') + feed.profile = profile + feed.save! + + rss = feed.data + assert_match /article 1<\/title>/, rss + assert_match /<item><title>article 2<\/title>/, rss + assert_match /<item><title>article 3<\/title>/, rss + end + end -- libgit2 0.21.2