From 46095aa0e2b0e02d11d6e7899c527b79311071a7 Mon Sep 17 00:00:00 2001 From: Leandro Nunes dos Santos Date: Thu, 4 Apr 2013 17:23:40 -0300 Subject: [PATCH] Show only text article and folders on tree content --- plugins/display_content/lib/display_content_block.rb | 5 ++++- plugins/display_content/test/unit/display_content_block_test.rb | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+), 1 deletion(-) diff --git a/plugins/display_content/lib/display_content_block.rb b/plugins/display_content/lib/display_content_block.rb index 138282a..1d6e929 100644 --- a/plugins/display_content/lib/display_content_block.rb +++ b/plugins/display_content/lib/display_content_block.rb @@ -18,6 +18,7 @@ class DisplayContentBlock < Block self.holder.articles.find(params.keys).map do |article| if article.folder? articles = articles + article.children + parent_articles << article.id else articles<< article end @@ -27,9 +28,11 @@ class DisplayContentBlock < Block self.nodes = articles.map{|a| a.id if a.is_a?(TextArticle) }.compact end + VALID_CONTENT = ['RawHTMLArticle', 'TextArticle', 'TextileArticle', 'TinyMceArticle', 'Folder', 'Blog', 'Forum'] + def articles_of_parent(parent = nil) return [] if self.holder.nil? - holder.articles.find(:all, :conditions => {:parent_id => parent.nil? ? nil : parent}) + holder.articles.find(:all, :conditions => {:type => VALID_CONTENT, :parent_id => (parent.nil? ? nil : parent)}) end include ActionController::UrlWriter diff --git a/plugins/display_content/test/unit/display_content_block_test.rb b/plugins/display_content/test/unit/display_content_block_test.rb index d189fe2..4c996cc 100644 --- a/plugins/display_content/test/unit/display_content_block_test.rb +++ b/plugins/display_content/test/unit/display_content_block_test.rb @@ -1,6 +1,9 @@ require File.dirname(__FILE__) + '/../test_helper' class DisplayContentBlockTest < ActiveSupport::TestCase + INVALID_KIND_OF_ARTICLE = [EnterpriseHomepage, Event, RssFeed, UploadedFile, Gallery] + VALID_KIND_OF_ARTICLE = [RawHTMLArticle, TextArticle, TextileArticle, TinyMceArticle, Folder, Blog, Forum] + should 'describe itself' do assert_not_equal Block.description, DisplayContentBlock.description end @@ -376,6 +379,57 @@ class DisplayContentBlockTest < ActiveSupport::TestCase assert_equal [], block.parent_nodes - [f1.id, f2.id, f3.id, f4.id, f5.id] end + should "save the folder in parent_nodes variable if it was checked" do + profile = create_user('testuser').person + Article.delete_all + f1 = fast_create(Folder, :name => 'test folder 1', :profile_id => profile.id) + a1 = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id, :parent_id => f1.id) + a2 = fast_create(TextileArticle, :name => 'test article 4', :profile_id => profile.id, :parent_id => f1.id) + + checked_articles= {f1.id => 1} + + block = DisplayContentBlock.new + block.stubs(:holder).returns(profile) + block.checked_nodes= checked_articles + + assert_equal [], [f1.id] - block.parent_nodes + assert_equal [], block.parent_nodes - [f1.id] + end + + should "save the blog in parent_nodes variable if it was checked" do + profile = create_user('testuser').person + Article.delete_all + b1 = fast_create(Blog, :name => 'test folder 1', :profile_id => profile.id) + a1 = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id, :parent_id => b1.id) + a2 = fast_create(TextileArticle, :name => 'test article 4', :profile_id => profile.id, :parent_id => b1.id) + + checked_articles= {b1.id => 1} + + block = DisplayContentBlock.new + block.stubs(:holder).returns(profile) + block.checked_nodes= checked_articles + + assert_equal [], [b1.id] - block.parent_nodes + assert_equal [], block.parent_nodes - [b1.id] + end + + should "save the forum in parent_nodes variable if it was checked" do + profile = create_user('testuser').person + Article.delete_all + f1 = fast_create(Forum, :name => 'test folder 1', :profile_id => profile.id) + a1 = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id, :parent_id => f1.id) + a2 = fast_create(TextileArticle, :name => 'test article 4', :profile_id => profile.id, :parent_id => f1.id) + + checked_articles= {f1.id => 1} + + block = DisplayContentBlock.new + block.stubs(:holder).returns(profile) + block.checked_nodes= checked_articles + + assert_equal [], [f1.id] - block.parent_nodes + assert_equal [], block.parent_nodes - [f1.id] + end + should "return all root articles from profile" do profile = create_user('testuser').person Article.delete_all @@ -454,6 +508,41 @@ class DisplayContentBlockTest < ActiveSupport::TestCase assert_equal [], block.articles_of_parent() end + INVALID_KIND_OF_ARTICLE.map do |invalid_article| + + define_method "test_should_not_return_#{invalid_article.name}_articles_in_articles_of_parent_method" do + profile = create_user('testuser').person + Article.delete_all + a1 = fast_create(invalid_article, :name => 'test article 1', :profile_id => profile.id) + a2 = fast_create(VALID_KIND_OF_ARTICLE.first, :name => 'test article 2', :profile_id => profile.id) + + block = DisplayContentBlock.new + box = mock() + box.stubs(:owner).returns(profile) + block.stubs(:box).returns(box) + assert_equal [], [a2] - block.articles_of_parent + assert_equal [], block.articles_of_parent - [a2] + end + + end + + VALID_KIND_OF_ARTICLE.map do |valid_article| + + define_method "test_should_return_#{valid_article.name}_articles_in_articles_of_parent_method" do + profile = create_user('testuser').person + Article.delete_all + a1 = fast_create(valid_article, :name => 'test article 1', :profile_id => profile.id) + a2 = fast_create(INVALID_KIND_OF_ARTICLE.first, :name => 'test article 2', :profile_id => profile.id) + + block = DisplayContentBlock.new + box = mock() + box.stubs(:owner).returns(profile) + block.stubs(:box).returns(box) + assert_equal [a1], block.articles_of_parent + end + + end + should 'list links for all articles title defined in nodes' do profile = create_user('testuser').person Article.delete_all -- libgit2 0.21.2