Commit 41eb41714ca8067d7d6df04d5582fb00a8ebfca3
Committed by
Victor Costa
1 parent
b942e7fe
Exists in
master
and in
29 other branches
Bug correction. The article inside a Step, wasn't showing the step / track in the folder combo.
Showing
6 changed files
with
42 additions
and
10 deletions
Show diff stats
app/models/article.rb
@@ -449,8 +449,8 @@ class Article < ActiveRecord::Base | @@ -449,8 +449,8 @@ class Article < ActiveRecord::Base | ||
449 | end | 449 | end |
450 | 450 | ||
451 | named_scope :published, :conditions => { :published => true } | 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 | named_scope :galleries, :conditions => { :type => 'Gallery' } | 454 | named_scope :galleries, :conditions => { :type => 'Gallery' } |
455 | named_scope :images, :conditions => { :is_image => true } | 455 | named_scope :images, :conditions => { :is_image => true } |
456 | named_scope :text_articles, :conditions => [ 'articles.type IN (?)', text_article_types ] | 456 | named_scope :text_articles, :conditions => [ 'articles.type IN (?)', text_article_types ] |
app/models/blog.rb
@@ -6,7 +6,7 @@ class Blog < Folder | @@ -6,7 +6,7 @@ class Blog < Folder | ||
6 | #FIXME This should be used until there is a migration to fix all blogs that | 6 | #FIXME This should be used until there is a migration to fix all blogs that |
7 | # already have folders inside them | 7 | # already have folders inside them |
8 | def posts_with_no_folders | 8 | def posts_with_no_folders |
9 | - posts_without_no_folders.no_folders | 9 | + posts_without_no_folders.no_folders(profile) |
10 | end | 10 | end |
11 | alias_method_chain :posts, :no_folders | 11 | alias_method_chain :posts, :no_folders |
12 | 12 |
app/models/profile.rb
@@ -760,8 +760,20 @@ private :generate_url, :url_options | @@ -760,8 +760,20 @@ private :generate_url, :url_options | ||
760 | !environment.enabled?('disable_contact_' + self.class.name.downcase) | 760 | !environment.enabled?('disable_contact_' + self.class.name.downcase) |
761 | end | 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 | def folders | 775 | def folders |
764 | - articles.folders | 776 | + articles.folders(self) |
765 | end | 777 | end |
766 | 778 | ||
767 | def image_galleries | 779 | def image_galleries |
test/unit/article_test.rb
@@ -1405,30 +1405,32 @@ class ArticleTest < ActiveSupport::TestCase | @@ -1405,30 +1405,32 @@ class ArticleTest < ActiveSupport::TestCase | ||
1405 | should 'return only folders' do | 1405 | should 'return only folders' do |
1406 | not_folders = [RssFeed, TinyMceArticle, Event, TextileArticle] | 1406 | not_folders = [RssFeed, TinyMceArticle, Event, TextileArticle] |
1407 | folders = [Folder, Blog, Gallery, Forum] | 1407 | folders = [Folder, Blog, Gallery, Forum] |
1408 | + profile = fast_create(Profile) | ||
1408 | 1409 | ||
1409 | not_folders.each do |klass| | 1410 | not_folders.each do |klass| |
1410 | item = fast_create(klass) | 1411 | item = fast_create(klass) |
1411 | - assert_not_includes Article.folders, item | 1412 | + assert_not_includes Article.folders(profile), item |
1412 | end | 1413 | end |
1413 | 1414 | ||
1414 | folders.each do |klass| | 1415 | folders.each do |klass| |
1415 | item = fast_create(klass) | 1416 | item = fast_create(klass) |
1416 | - assert_includes Article.folders, item | 1417 | + assert_includes Article.folders(profile), item |
1417 | end | 1418 | end |
1418 | end | 1419 | end |
1419 | 1420 | ||
1420 | should 'return no folders' do | 1421 | should 'return no folders' do |
1421 | not_folders = [RssFeed, TinyMceArticle, Event, TextileArticle] | 1422 | not_folders = [RssFeed, TinyMceArticle, Event, TextileArticle] |
1422 | folders = [Folder, Blog, Gallery, Forum] | 1423 | folders = [Folder, Blog, Gallery, Forum] |
1424 | + profile = fast_create(Profile) | ||
1423 | 1425 | ||
1424 | not_folders.each do |klass| | 1426 | not_folders.each do |klass| |
1425 | item = fast_create(klass) | 1427 | item = fast_create(klass) |
1426 | - assert_includes Article.no_folders, item | 1428 | + assert_includes Article.no_folders(profile), item |
1427 | end | 1429 | end |
1428 | 1430 | ||
1429 | folders.each do |klass| | 1431 | folders.each do |klass| |
1430 | item = fast_create(klass) | 1432 | item = fast_create(klass) |
1431 | - assert_not_includes Article.no_folders, item | 1433 | + assert_not_includes Article.no_folders(profile), item |
1432 | end | 1434 | end |
1433 | end | 1435 | end |
1434 | 1436 |
test/unit/blog_test.rb
@@ -198,7 +198,8 @@ class BlogTest < ActiveSupport::TestCase | @@ -198,7 +198,8 @@ class BlogTest < ActiveSupport::TestCase | ||
198 | #FIXME This should be used until there is a migration to fix all blogs that | 198 | #FIXME This should be used until there is a migration to fix all blogs that |
199 | # already have folders inside them | 199 | # already have folders inside them |
200 | should 'not list folders in posts' do | 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 | folder = fast_create(Folder, :parent_id => blog.id) | 203 | folder = fast_create(Folder, :parent_id => blog.id) |
203 | article = fast_create(TextileArticle, :parent_id => blog.id) | 204 | article = fast_create(TextileArticle, :parent_id => blog.id) |
204 | 205 | ||
@@ -212,7 +213,8 @@ class BlogTest < ActiveSupport::TestCase | @@ -212,7 +213,8 @@ class BlogTest < ActiveSupport::TestCase | ||
212 | end | 213 | end |
213 | 214 | ||
214 | should 'know when blog has or when has no posts' do | 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 | assert blog.empty? | 218 | assert blog.empty? |
217 | fast_create(TextileArticle, :parent_id => blog.id) | 219 | fast_create(TextileArticle, :parent_id => blog.id) |
218 | assert ! blog.empty? | 220 | assert ! blog.empty? |
test/unit/profile_test.rb
@@ -1888,4 +1888,20 @@ class ProfileTest < ActiveSupport::TestCase | @@ -1888,4 +1888,20 @@ class ProfileTest < ActiveSupport::TestCase | ||
1888 | assert !profile.may_display_location_to?(user) | 1888 | assert !profile.may_display_location_to?(user) |
1889 | end | 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 | end | 1907 | end |