diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb index 8620ba2..79e0c77 100644 --- a/app/controllers/my_profile/cms_controller.rb +++ b/app/controllers/my_profile/cms_controller.rb @@ -443,9 +443,7 @@ class CmsController < MyProfileController end def refuse_blocks - if ['TinyMceArticle', 'TextileArticle', 'Event', 'EnterpriseHomepage'].include?(@type) - @no_design_blocks = true - end + @no_design_blocks = @type.present? && valid_article_type?(@type) ? !@type.constantize.can_display_blocks? : false end def per_page diff --git a/app/models/article.rb b/app/models/article.rb index a4cf042..0b5cb46 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -864,6 +864,10 @@ class Article < ApplicationRecord HashWithIndifferentAccess.new :name => name, :abstract => abstract, :body => body, :id => id, :parent_id => parent_id, :author => author end + def self.can_display_blocks? + true + end + private def sanitize_tag_list diff --git a/app/models/event.rb b/app/models/event.rb index 0dbe2e7..eef64fd 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -134,6 +134,10 @@ class Event < Article true end + def self.can_display_blocks? + false + end + include Noosfero::TranslatableContent include MaybeAddHttp diff --git a/app/models/textile_article.rb b/app/models/textile_article.rb index 8e9fc0c..f9c47b1 100644 --- a/app/models/textile_article.rb +++ b/app/models/textile_article.rb @@ -29,6 +29,10 @@ class TextileArticle < TextArticle true end + def self.can_display_blocks? + false + end + protected def convert_to_html(textile) diff --git a/app/models/tiny_mce_article.rb b/app/models/tiny_mce_article.rb index 1b18a5a..536c6c6 100644 --- a/app/models/tiny_mce_article.rb +++ b/app/models/tiny_mce_article.rb @@ -32,4 +32,8 @@ class TinyMceArticle < TextArticle true end + def self.can_display_blocks? + false + end + end diff --git a/plugins/comment_paragraph/test/unit/discussion_test.rb b/plugins/comment_paragraph/test/unit/discussion_test.rb index 6e80701..6a7c514 100644 --- a/plugins/comment_paragraph/test/unit/discussion_test.rb +++ b/plugins/comment_paragraph/test/unit/discussion_test.rb @@ -29,4 +29,8 @@ class DiscussionTest < ActiveSupport::TestCase discussion = CommentParagraphPlugin::Discussion.create!(profile: profile, name: "discussion", start_date: Time.now + 1.day, end_date: Time.now + 2.days) assert !discussion.accept_comments? end + + should 'have can_display_blocks with default false' do + assert !CommentParagraphPlugin::Discussion.can_display_blocks? + end end diff --git a/plugins/products/models/products_plugin/enterprise_homepage.rb b/plugins/products/models/products_plugin/enterprise_homepage.rb index c08f325..61ee4d2 100644 --- a/plugins/products/models/products_plugin/enterprise_homepage.rb +++ b/plugins/products/models/products_plugin/enterprise_homepage.rb @@ -48,5 +48,9 @@ module ProductsPlugin true end + def self.can_display_blocks? + false + end + end end diff --git a/plugins/products/test/unit/products_plugin/enterprise_homepage_test.rb b/plugins/products/test/unit/products_plugin/enterprise_homepage_test.rb index f817410..b2edbf4 100644 --- a/plugins/products/test/unit/products_plugin/enterprise_homepage_test.rb +++ b/plugins/products/test/unit/products_plugin/enterprise_homepage_test.rb @@ -30,4 +30,7 @@ class EnterpriseHomepageTest < ActiveSupport::TestCase assert a.can_display_media_panel? end + should 'have can_display_blocks with default false' do + assert !EnterpriseHomepage.can_display_blocks? + end end diff --git a/test/functional/cms_controller_test.rb b/test/functional/cms_controller_test.rb index 8529408..30e7844 100644 --- a/test/functional/cms_controller_test.rb +++ b/test/functional/cms_controller_test.rb @@ -1993,6 +1993,39 @@ class CmsControllerTest < ActionController::TestCase assert_match main_article.body, @response.body end + should 'set no_design_blocks as false when create a new document without type' do + get :new, profile: profile.identifier + assert !assigns(:no_design_blocks) + end + + should 'set no_design_blocks as false when create a new document with invalid type' do + assert_raise RuntimeError do + get :new, profile: profile.identifier, type: 'InvalidType' + assert !assigns(:no_design_blocks) + end + end + + [TextileArticle, Event, TinyMceArticle].each do |klass| + should "set no_design_blocks as true when create #{klass.name}" do + get :new, profile: profile.identifier, type: klass.name + assert assigns(:no_design_blocks) + end + end + + should "set no_design_blocks as false when edit Article" do + article = fast_create(Article, profile_id: profile.id) + get :edit, profile: profile.identifier, id: article.id + assert !assigns(:no_design_blocks) + end + + [TextileArticle, Event, TinyMceArticle].each do |klass| + should "set no_design_blocks as true when edit #{klass.name}" do + article = fast_create(klass, profile_id: profile.id) + get :edit, profile: profile.identifier, id: article.id + assert assigns(:no_design_blocks) + end + end + protected # FIXME this is to avoid adding an extra dependency for a proper JSON parser. diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb index bf061cd..68cb57f 100644 --- a/test/unit/article_test.rb +++ b/test/unit/article_test.rb @@ -2327,4 +2327,7 @@ class ArticleTest < ActiveSupport::TestCase assert_match 'Parent folder is archived', err.message end + should 'have can_display_blocks with default true' do + assert Article.can_display_blocks? + end end diff --git a/test/unit/event_test.rb b/test/unit/event_test.rb index 2666c1c..3fade78 100644 --- a/test/unit/event_test.rb +++ b/test/unit/event_test.rb @@ -333,4 +333,7 @@ class EventTest < ActiveSupport::TestCase assert_equal 1, e.duration end + should 'have can_display_blocks with default false' do + assert !Event.can_display_blocks? + end end diff --git a/test/unit/textile_article_test.rb b/test/unit/textile_article_test.rb index 21d0a18..01a949d 100644 --- a/test/unit/textile_article_test.rb +++ b/test/unit/textile_article_test.rb @@ -178,6 +178,10 @@ class TextileArticleTest < ActiveSupport::TestCase assert a.can_display_media_panel? end + should 'have can_display_blocks with default false' do + assert !TextileArticle.can_display_blocks? + end + protected def build_article(input = nil, options = {}) diff --git a/test/unit/tiny_mce_article_test.rb b/test/unit/tiny_mce_article_test.rb index 70dc77e..e924d64 100644 --- a/test/unit/tiny_mce_article_test.rb +++ b/test/unit/tiny_mce_article_test.rb @@ -237,4 +237,7 @@ class TinyMceArticleTest < ActiveSupport::TestCase assert a.can_display_media_panel? end + should 'have can_display_blocks with default false' do + assert !TinyMceArticle.can_display_blocks? + end end -- libgit2 0.21.2