Commit 5ba67c24fbf817389497a5254db3f29ccb07c788
1 parent
6b50d1d9
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
Allow article types to define when media panel should be displayed
Showing
11 changed files
with
69 additions
and
4 deletions
Show diff stats
app/models/article.rb
... | ... | @@ -634,6 +634,14 @@ class Article < ActiveRecord::Base |
634 | 634 | can_display_hits? && display_hits |
635 | 635 | end |
636 | 636 | |
637 | + def display_media_panel? | |
638 | + can_display_media_panel? && environment.enabled?('media_panel') | |
639 | + end | |
640 | + | |
641 | + def can_display_media_panel? | |
642 | + false | |
643 | + end | |
644 | + | |
637 | 645 | def image? |
638 | 646 | false |
639 | 647 | end | ... | ... |
app/models/enterprise_homepage.rb
app/models/event.rb
app/models/textile_article.rb
app/models/tiny_mce_article.rb
app/views/cms/edit.html.erb
1 | 1 | <%= error_messages_for 'article' %> |
2 | 2 | |
3 | -<% show_media_panel = environment.enabled?('media_panel') && [TinyMceArticle, TextileArticle, Event, EnterpriseHomepage].any?{|klass| @article.kind_of?(klass)} %> | |
4 | - | |
5 | -<div class='<%= (show_media_panel ? 'with_media_panel' : 'no_media_panel') %>'> | |
3 | +<div class='<%= (@article.display_media_panel? ? 'with_media_panel' : 'no_media_panel') %>'> | |
6 | 4 | <%= labelled_form_for 'article', :html => { :multipart => true, :class => @type } do |f| %> |
7 | 5 | |
8 | 6 | <%= hidden_field_tag("type", @type) if @type %> |
... | ... | @@ -68,7 +66,7 @@ |
68 | 66 | <% end %> |
69 | 67 | </div> |
70 | 68 | |
71 | -<% if show_media_panel %> | |
69 | +<% if @article.display_media_panel? %> | |
72 | 70 | <%= render :partial => 'text_editor_sidebar' %> |
73 | 71 | <% end %> |
74 | 72 | ... | ... |
test/unit/article_test.rb
... | ... | @@ -2180,4 +2180,27 @@ class ArticleTest < ActiveSupport::TestCase |
2180 | 2180 | article.destroy |
2181 | 2181 | end |
2182 | 2182 | |
2183 | + should 'have can_display_media_panel with default false' do | |
2184 | + a = Article.new | |
2185 | + assert !a.can_display_media_panel? | |
2186 | + end | |
2187 | + | |
2188 | + should 'display media panel when allowed by the environment' do | |
2189 | + a = Article.new | |
2190 | + a.expects(:can_display_media_panel?).returns(true) | |
2191 | + environment = mock | |
2192 | + a.expects(:environment).returns(environment) | |
2193 | + environment.expects(:enabled?).with('media_panel').returns(true) | |
2194 | + assert a.display_media_panel? | |
2195 | + end | |
2196 | + | |
2197 | + should 'not display media panel when not allowed by the environment' do | |
2198 | + a = Article.new | |
2199 | + a.expects(:can_display_media_panel?).returns(true) | |
2200 | + environment = mock | |
2201 | + a.expects(:environment).returns(environment) | |
2202 | + environment.expects(:enabled?).with('media_panel').returns(false) | |
2203 | + assert !a.display_media_panel? | |
2204 | + end | |
2205 | + | |
2183 | 2206 | end | ... | ... |
test/unit/enterprise_homepage_test.rb
... | ... | @@ -26,4 +26,9 @@ class EnterpriseHomepageTest < ActiveSupport::TestCase |
26 | 26 | assert_equal false, a.can_display_hits? |
27 | 27 | end |
28 | 28 | |
29 | + should 'have can_display_media_panel with default true' do | |
30 | + a = EnterpriseHomepage.new | |
31 | + assert a.can_display_media_panel? | |
32 | + end | |
33 | + | |
29 | 34 | end | ... | ... |
test/unit/event_test.rb
test/unit/textile_article_test.rb
... | ... | @@ -175,6 +175,11 @@ class TextileArticleTest < ActiveSupport::TestCase |
175 | 175 | assert_equal "<p>one\nparagraph</p>", build_article("one\nparagraph").to_html |
176 | 176 | end |
177 | 177 | |
178 | + should 'have can_display_media_panel with default true' do | |
179 | + a = TextileArticle.new | |
180 | + assert a.can_display_media_panel? | |
181 | + end | |
182 | + | |
178 | 183 | protected |
179 | 184 | |
180 | 185 | def build_article(input = nil, options = {}) | ... | ... |
test/unit/tiny_mce_article_test.rb