Commit 41eb41714ca8067d7d6df04d5582fb00a8ebfca3

Authored by Eduardo Tourinho Edington
Committed by Victor Costa
1 parent b942e7fe

Bug correction. The article inside a Step, wasn't showing the step / track in the folder combo.

app/models/article.rb
... ... @@ -449,8 +449,8 @@ class Article < ActiveRecord::Base
449 449 end
450 450  
451 451 named_scope :published, :conditions => { :published => true }
452   - named_scope :folders, :conditions => { :type => folder_types}
453   - named_scope :no_folders, :conditions => ['type NOT IN (?)', folder_types]
  452 + named_scope :folders, lambda {|profile|{:conditions => { :type => profile.folder_types} }}
  453 + named_scope :no_folders, lambda {|profile|{:conditions => ['type NOT IN (?)', profile.folder_types]}}
454 454 named_scope :galleries, :conditions => { :type => 'Gallery' }
455 455 named_scope :images, :conditions => { :is_image => true }
456 456 named_scope :text_articles, :conditions => [ 'articles.type IN (?)', text_article_types ]
... ...
app/models/blog.rb
... ... @@ -6,7 +6,7 @@ class Blog < Folder
6 6 #FIXME This should be used until there is a migration to fix all blogs that
7 7 # already have folders inside them
8 8 def posts_with_no_folders
9   - posts_without_no_folders.no_folders
  9 + posts_without_no_folders.no_folders(profile)
10 10 end
11 11 alias_method_chain :posts, :no_folders
12 12  
... ...
app/models/profile.rb
... ... @@ -760,8 +760,20 @@ private :generate_url, :url_options
760 760 !environment.enabled?('disable_contact_' + self.class.name.downcase)
761 761 end
762 762  
  763 + include Noosfero::Plugin::HotSpot
  764 +
  765 + def folder_types
  766 + types = Article.folder_types
  767 + plugins.dispatch(:content_types).each {|type|
  768 + if type < Folder
  769 + types << type.name
  770 + end
  771 + }
  772 + types
  773 + end
  774 +
763 775 def folders
764   - articles.folders
  776 + articles.folders(self)
765 777 end
766 778  
767 779 def image_galleries
... ...
test/unit/article_test.rb
... ... @@ -1405,30 +1405,32 @@ class ArticleTest &lt; ActiveSupport::TestCase
1405 1405 should 'return only folders' do
1406 1406 not_folders = [RssFeed, TinyMceArticle, Event, TextileArticle]
1407 1407 folders = [Folder, Blog, Gallery, Forum]
  1408 + profile = fast_create(Profile)
1408 1409  
1409 1410 not_folders.each do |klass|
1410 1411 item = fast_create(klass)
1411   - assert_not_includes Article.folders, item
  1412 + assert_not_includes Article.folders(profile), item
1412 1413 end
1413 1414  
1414 1415 folders.each do |klass|
1415 1416 item = fast_create(klass)
1416   - assert_includes Article.folders, item
  1417 + assert_includes Article.folders(profile), item
1417 1418 end
1418 1419 end
1419 1420  
1420 1421 should 'return no folders' do
1421 1422 not_folders = [RssFeed, TinyMceArticle, Event, TextileArticle]
1422 1423 folders = [Folder, Blog, Gallery, Forum]
  1424 + profile = fast_create(Profile)
1423 1425  
1424 1426 not_folders.each do |klass|
1425 1427 item = fast_create(klass)
1426   - assert_includes Article.no_folders, item
  1428 + assert_includes Article.no_folders(profile), item
1427 1429 end
1428 1430  
1429 1431 folders.each do |klass|
1430 1432 item = fast_create(klass)
1431   - assert_not_includes Article.no_folders, item
  1433 + assert_not_includes Article.no_folders(profile), item
1432 1434 end
1433 1435 end
1434 1436  
... ...
test/unit/blog_test.rb
... ... @@ -198,7 +198,8 @@ class BlogTest &lt; ActiveSupport::TestCase
198 198 #FIXME This should be used until there is a migration to fix all blogs that
199 199 # already have folders inside them
200 200 should 'not list folders in posts' do
201   - blog = fast_create(Blog)
  201 + p = create_user('testuser').person
  202 + blog = Blog.create!(:profile => p, :name => 'Blog test')
202 203 folder = fast_create(Folder, :parent_id => blog.id)
203 204 article = fast_create(TextileArticle, :parent_id => blog.id)
204 205  
... ... @@ -212,7 +213,8 @@ class BlogTest &lt; ActiveSupport::TestCase
212 213 end
213 214  
214 215 should 'know when blog has or when has no posts' do
215   - blog = fast_create(Blog)
  216 + p = create_user('testuser').person
  217 + blog = Blog.create!(:profile => p, :name => 'Blog test')
216 218 assert blog.empty?
217 219 fast_create(TextileArticle, :parent_id => blog.id)
218 220 assert ! blog.empty?
... ...
test/unit/profile_test.rb
... ... @@ -1888,4 +1888,20 @@ class ProfileTest &lt; ActiveSupport::TestCase
1888 1888 assert !profile.may_display_location_to?(user)
1889 1889 end
1890 1890  
  1891 + should 'folder_types search for folders in the plugins' do
  1892 + class Folder1 < Folder
  1893 + end
  1894 +
  1895 + class Plugin1 < Noosfero::Plugin
  1896 + def content_types
  1897 + [Folder1]
  1898 + end
  1899 + end
  1900 +
  1901 + environment = Environment.default
  1902 + environment.enable_plugin(Plugin1)
  1903 + plugins = Noosfero::Plugin::Manager.new(environment, self)
  1904 + p = fast_create(Profile)
  1905 + assert p.folder_types.include?('ProfileTest::Folder1')
  1906 + end
1891 1907 end
... ...