From 967cac32b6f332384dd124773a7a4408d798d014 Mon Sep 17 00:00:00 2001 From: JoenioCosta Date: Fri, 18 Apr 2008 00:31:27 +0000 Subject: [PATCH] ActionItem194: fixed criteria used to list or not articles in 'recent documents' --- app/models/article.rb | 6 +++++- app/models/profile.rb | 3 +-- app/models/recent_documents_block.rb | 9 ++------- app/models/rss_feed.rb | 8 +++++++- db/migrate/007_create_articles.rb | 4 ++++ test/functional/profile_controller_test.rb | 22 ++++++++++++++++++++++ test/unit/profile_test.rb | 23 +++++++++++++++++++++++ test/unit/recent_documents_block_test.rb | 15 ++++++++++----- test/unit/rss_feed_test.rb | 6 ++++++ 9 files changed, 80 insertions(+), 16 deletions(-) diff --git a/app/models/article.rb b/app/models/article.rb index 964cb81..9075fa5 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -19,7 +19,11 @@ class Article < ActiveRecord::Base acts_as_versioned acts_as_searchable :fields => [ :name, :abstract, :body, :tag_list ] - + + before_update do |article| + article.advertise = true + end + # retrieves all articles belonging to the given +profile+ that are not # sub-articles of any other article. def self.top_level_for(profile) diff --git a/app/models/profile.rb b/app/models/profile.rb index 55c2410..d2336b2 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -260,14 +260,13 @@ class Profile < ActiveRecord::Base hacked_after_create :insert_default_homepage_and_feed def insert_default_homepage_and_feed - hp = self.articles.build(:name => _("%s's home page") % self.name, :body => _("

This is a default homepage created for %s. It can be changed though the control panel.

") % self.name) + hp = self.articles.build(:name => _("%s's home page") % self.name, :body => _("

This is a default homepage created for %s. It can be changed though the control panel.

") % self.name, :advertise => false) hp.save! self.home_page = hp self.save! feed = RssFeed.new(:name => 'feed') self.articles << feed - feed.save! end # Adds a person as member of this Profile. diff --git a/app/models/recent_documents_block.rb b/app/models/recent_documents_block.rb index 15720b2..6ffe667 100644 --- a/app/models/recent_documents_block.rb +++ b/app/models/recent_documents_block.rb @@ -8,14 +8,9 @@ class RecentDocumentsBlock < Block include ActionController::UrlWriter def content - docs = - if self.limit.nil? - owner.recent_documents - else - owner.recent_documents(self.limit) - end + docs = self.limit.nil? ? owner.recent_documents : owner.recent_documents(self.limit) - docs = docs.select{|d| d.kind_of?(TextArticle)} + docs.delete_if{|d| d.kind_of?(Article) and !d.advertise?} block_title(_('Recent content')) + content_tag('ul', docs.map {|item| content_tag('li', link_to(item.title, item.url))}.join("\n")) diff --git a/app/models/rss_feed.rb b/app/models/rss_feed.rb index 2e1177e..5465326 100644 --- a/app/models/rss_feed.rb +++ b/app/models/rss_feed.rb @@ -1,8 +1,14 @@ class RssFeed < Article + # i dont know why before filter dont work here + def initialize(*args) + super(*args) + self.advertise = false + end + # store setting in body serialize :body, Hash - + def body self[:body] ||= {} end diff --git a/db/migrate/007_create_articles.rb b/db/migrate/007_create_articles.rb index f9aff5c..b1fe8cf 100644 --- a/db/migrate/007_create_articles.rb +++ b/db/migrate/007_create_articles.rb @@ -35,6 +35,10 @@ class CreateArticles < ActiveRecord::Migration # attachment_fu data for images t.column :height, :integer # in pixels t.column :width, :integer # in pixels + + # show in recent content? + t.column :advertise, :boolean, :default => true + end Article.create_versioned_table diff --git a/test/functional/profile_controller_test.rb b/test/functional/profile_controller_test.rb index 5073694..58402c5 100644 --- a/test/functional/profile_controller_test.rb +++ b/test/functional/profile_controller_test.rb @@ -88,4 +88,26 @@ class ProfileControllerTest < Test::Unit::TestCase assert_tag :tag => 'a', :content => 'Friends', :attributes => { :href => /profile\/#{person.identifier}\/friends$/ } end + should 'not show homepage and feed automatically created on recent content' do + person = create_user('person_1').person + get :index, :profile => person.identifier + assert_tag :tag => 'div', :content => 'Recent content', :attributes => { :class => 'block recent-documents-block' }, :child => { :tag => 'ul', :content => '' } + end + + should 'show homepage on recent content after update' do + person = create_user('person_1').person + person.home_page.name = 'Changed name' + assert person.home_page.save! + get :index, :profile => person.identifier + assert_tag :tag => 'div', :content => 'Recent content', :attributes => { :class => 'block recent-documents-block' }, :child => { :tag => 'ul', :content => /#{person.home_page.name}/ } + end + + should 'show feed on recent content after update' do + person = create_user('person_1').person + person.articles.find_by_path('feed').name = 'Changed name' + assert person.articles.find_by_path('feed').save! + get :index, :profile => person.identifier + assert_tag :tag => 'div', :content => 'Recent content', :attributes => { :class => 'block recent-documents-block' }, :child => { :tag => 'ul', :content => /#{person.articles.find_by_path('feed').name}/ } + end + end diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb index e52f4b8..514add4 100644 --- a/test/unit/profile_test.rb +++ b/test/unit/profile_test.rb @@ -410,6 +410,28 @@ class ProfileTest < Test::Unit::TestCase assert_equal [p3,p2], Profile.recent(2) end + should 'advertise false to homepage and feed on creation' do + profile = Profile.create!(:name => 'my test profile', :identifier => 'mytestprofile') + assert !profile.home_page.advertise? + assert !profile.articles.find_by_path('feed').advertise? + end + + should 'advertise true to homepage after update' do + profile = Profile.create!(:name => 'my test profile', :identifier => 'mytestprofile') + assert !profile.home_page.advertise? + profile.home_page.name = 'Changed name' + assert profile.home_page.save! + assert profile.home_page.advertise? + end + + should 'advertise true to feed after update' do + profile = Profile.create!(:name => 'my test profile', :identifier => 'mytestprofile') + assert !profile.articles.find_by_path('feed').advertise? + profile.articles.find_by_path('feed').name = 'Changed name' + assert profile.articles.find_by_path('feed').save! + assert profile.articles.find_by_path('feed').advertise? + end + private def assert_invalid_identifier(id) @@ -417,4 +439,5 @@ class ProfileTest < Test::Unit::TestCase assert !profile.valid? assert profile.errors.invalid?(:identifier) end + end diff --git a/test/unit/recent_documents_block_test.rb b/test/unit/recent_documents_block_test.rb index e94a089..463acc5 100644 --- a/test/unit/recent_documents_block_test.rb +++ b/test/unit/recent_documents_block_test.rb @@ -40,14 +40,19 @@ class RecentDocumentsBlockTest < Test::Unit::TestCase assert_no_match /href=.*\/testinguser\/first/, output end - should 'not list rss feed articles' do - profile.articles << RssFeed.create(:name => 'sixth') - profile.save! - + should 'not list rss feed articles automatically created' do + assert_equal 'feed', profile.articles.find_by_path('feed').name output = block.content + assert_match /href=.*\/testinguser\/first/, output + assert_no_match /href=.*\/testinguser\/feed/, output + end + should 'list rss feed articles after update' do + profile.articles.find_by_path('feed').name = 'chaged name' + assert profile.articles.find_by_path('feed').save! + output = block.content assert_match /href=.*\/testinguser\/first/, output - assert_no_match /href=.*\/testinguser\/sixth/, output + assert_match /href=.*\/testinguser\/feed/, output end end diff --git a/test/unit/rss_feed_test.rb b/test/unit/rss_feed_test.rb index 7e39205..1de19eb 100644 --- a/test/unit/rss_feed_test.rb +++ b/test/unit/rss_feed_test.rb @@ -201,4 +201,10 @@ class RssFeedTest < Test::Unit::TestCase assert_equal 'rss-feed', RssFeed.new.icon_name end + should 'advertise is false before create' do + profile = create_user('testuser').person + feed = RssFeed.create!(:name => 'testfeed', :profile => profile) + assert !feed.advertise? + end + end -- libgit2 0.21.2