From 41eb41714ca8067d7d6df04d5582fb00a8ebfca3 Mon Sep 17 00:00:00 2001 From: Eduardo Tourinho Edington Date: Thu, 21 Nov 2013 17:02:57 -0300 Subject: [PATCH] Bug correction. The article inside a Step, wasn't showing the step / track in the folder combo. --- app/models/article.rb | 4 ++-- app/models/blog.rb | 2 +- app/models/profile.rb | 14 +++++++++++++- test/unit/article_test.rb | 10 ++++++---- test/unit/blog_test.rb | 6 ++++-- test/unit/profile_test.rb | 16 ++++++++++++++++ 6 files changed, 42 insertions(+), 10 deletions(-) diff --git a/app/models/article.rb b/app/models/article.rb index 5e66ee4..608cb21 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -449,8 +449,8 @@ class Article < ActiveRecord::Base end named_scope :published, :conditions => { :published => true } - named_scope :folders, :conditions => { :type => folder_types} - named_scope :no_folders, :conditions => ['type NOT IN (?)', folder_types] + named_scope :folders, lambda {|profile|{:conditions => { :type => profile.folder_types} }} + named_scope :no_folders, lambda {|profile|{:conditions => ['type NOT IN (?)', profile.folder_types]}} named_scope :galleries, :conditions => { :type => 'Gallery' } named_scope :images, :conditions => { :is_image => true } named_scope :text_articles, :conditions => [ 'articles.type IN (?)', text_article_types ] diff --git a/app/models/blog.rb b/app/models/blog.rb index 52316da..a61988b 100644 --- a/app/models/blog.rb +++ b/app/models/blog.rb @@ -6,7 +6,7 @@ class Blog < Folder #FIXME This should be used until there is a migration to fix all blogs that # already have folders inside them def posts_with_no_folders - posts_without_no_folders.no_folders + posts_without_no_folders.no_folders(profile) end alias_method_chain :posts, :no_folders diff --git a/app/models/profile.rb b/app/models/profile.rb index 525df3d..54853d4 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -760,8 +760,20 @@ private :generate_url, :url_options !environment.enabled?('disable_contact_' + self.class.name.downcase) end + include Noosfero::Plugin::HotSpot + + def folder_types + types = Article.folder_types + plugins.dispatch(:content_types).each {|type| + if type < Folder + types << type.name + end + } + types + end + def folders - articles.folders + articles.folders(self) end def image_galleries diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb index f72b0c8..3d1c8fc 100644 --- a/test/unit/article_test.rb +++ b/test/unit/article_test.rb @@ -1405,30 +1405,32 @@ class ArticleTest < ActiveSupport::TestCase should 'return only folders' do not_folders = [RssFeed, TinyMceArticle, Event, TextileArticle] folders = [Folder, Blog, Gallery, Forum] + profile = fast_create(Profile) not_folders.each do |klass| item = fast_create(klass) - assert_not_includes Article.folders, item + assert_not_includes Article.folders(profile), item end folders.each do |klass| item = fast_create(klass) - assert_includes Article.folders, item + assert_includes Article.folders(profile), item end end should 'return no folders' do not_folders = [RssFeed, TinyMceArticle, Event, TextileArticle] folders = [Folder, Blog, Gallery, Forum] + profile = fast_create(Profile) not_folders.each do |klass| item = fast_create(klass) - assert_includes Article.no_folders, item + assert_includes Article.no_folders(profile), item end folders.each do |klass| item = fast_create(klass) - assert_not_includes Article.no_folders, item + assert_not_includes Article.no_folders(profile), item end end diff --git a/test/unit/blog_test.rb b/test/unit/blog_test.rb index 70b2a36..cfed10d 100644 --- a/test/unit/blog_test.rb +++ b/test/unit/blog_test.rb @@ -198,7 +198,8 @@ class BlogTest < ActiveSupport::TestCase #FIXME This should be used until there is a migration to fix all blogs that # already have folders inside them should 'not list folders in posts' do - blog = fast_create(Blog) + p = create_user('testuser').person + blog = Blog.create!(:profile => p, :name => 'Blog test') folder = fast_create(Folder, :parent_id => blog.id) article = fast_create(TextileArticle, :parent_id => blog.id) @@ -212,7 +213,8 @@ class BlogTest < ActiveSupport::TestCase end should 'know when blog has or when has no posts' do - blog = fast_create(Blog) + p = create_user('testuser').person + blog = Blog.create!(:profile => p, :name => 'Blog test') assert blog.empty? fast_create(TextileArticle, :parent_id => blog.id) assert ! blog.empty? diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb index 5da1312..ba48a53 100644 --- a/test/unit/profile_test.rb +++ b/test/unit/profile_test.rb @@ -1888,4 +1888,20 @@ class ProfileTest < ActiveSupport::TestCase assert !profile.may_display_location_to?(user) end + should 'folder_types search for folders in the plugins' do + class Folder1 < Folder + end + + class Plugin1 < Noosfero::Plugin + def content_types + [Folder1] + end + end + + environment = Environment.default + environment.enable_plugin(Plugin1) + plugins = Noosfero::Plugin::Manager.new(environment, self) + p = fast_create(Profile) + assert p.folder_types.include?('ProfileTest::Folder1') + end end -- libgit2 0.21.2