From f862eb4fdf58a8a84404b7a05fb4d06a2ae554f9 Mon Sep 17 00:00:00 2001 From: Rodrigo Souto Date: Tue, 13 Jan 2015 13:34:47 -0300 Subject: [PATCH] publish-button: refactor display logic and remove useless tests --- app/helpers/application_helper.rb | 2 +- app/helpers/cms_helper.rb | 4 +--- app/views/content_viewer/_article_toolbar.html.erb | 2 +- test/functional/content_viewer_controller_test.rb | 20 -------------------- test/unit/cms_helper_test.rb | 13 ++----------- 5 files changed, 5 insertions(+), 36 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 60288f9..74b0950 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1306,7 +1306,7 @@ module ApplicationHelper end def content_remove_spread(content) - not (profile != user || user.communities.present? || @portal_enabled) + !content.public? || content.folder? || (profile == user && user.communities.blank? && !environment.portal_enabled) end def remove_content_button(action) diff --git a/app/helpers/cms_helper.rb b/app/helpers/cms_helper.rb index a3ef064..fdec14c 100644 --- a/app/helpers/cms_helper.rb +++ b/app/helpers/cms_helper.rb @@ -41,9 +41,7 @@ module CmsHelper end def display_spread_button(article) - if article.public? - expirable_button article, :spread, _('Spread this'), {:action => 'publish', :id => article.id}, {:class => 'colorbox'} - end + expirable_button article, :spread, _('Spread this'), {:action => 'publish', :id => article.id}, {:class => 'colorbox'} end def display_delete_button(article) diff --git a/app/views/content_viewer/_article_toolbar.html.erb b/app/views/content_viewer/_article_toolbar.html.erb index aa37706..bd72af6 100644 --- a/app/views/content_viewer/_article_toolbar.html.erb +++ b/app/views/content_viewer/_article_toolbar.html.erb @@ -15,7 +15,7 @@ <%= expirable_button @page, :delete, content, url, options %> <% end %> - <% if !@page.folder? && @page.allow_spread?(user) && !remove_content_button(:spread) %> + <% if @page.allow_spread?(user) && !remove_content_button(:spread) %> <% url = profile.admin_url.merge({ :controller => 'cms', :action => 'publish', :id => @page.id }) %> <%= expirable_button @page, :spread, content_tag( 'span', _('Spread this') ), url, {:class => 'colorbox'} if url %> <% end %> diff --git a/test/functional/content_viewer_controller_test.rb b/test/functional/content_viewer_controller_test.rb index 03ef14c..07c6142 100644 --- a/test/functional/content_viewer_controller_test.rb +++ b/test/functional/content_viewer_controller_test.rb @@ -319,26 +319,6 @@ class ContentViewerControllerTest < ActionController::TestCase assert_tag :content => /list my comment/ end - should 'show link to publication on view' do - page = profile.articles.create!(:name => 'myarticle', :body => 'the body of the text') - login_as(profile.identifier) - - xhr :get, :view_page, :profile => profile.identifier, :page => ['myarticle'], :toolbar => true - - assert_tag :tag => 'a', :attributes => {:href => ('/myprofile/' + profile.identifier + '/cms/publish/' + page.id.to_s)} - end - - should 'not show link to publication on view if not on person profile' do - prof = Community.create!(:name => 'test comm', :identifier => 'test_comm') - page = prof.articles.create!(:name => 'myarticle', :body => 'the body of the text') - prof.affiliate(profile, Profile::Roles.all_roles(prof.environment.id)) - login_as(profile.identifier) - - xhr :get, :view_page, :profile => prof.identifier, :page => ['myarticle'], :toolbar => true - - assert_no_tag :tag => 'a', :attributes => {:href => ('/myprofile/' + prof.identifier + '/cms/publish/' + page.id.to_s)} - end - should 'redirect to new article path under an old path' do p = create_user('test_user').person a = p.articles.create(:name => 'old-name') diff --git a/test/unit/cms_helper_test.rb b/test/unit/cms_helper_test.rb index e758190..b95998e 100644 --- a/test/unit/cms_helper_test.rb +++ b/test/unit/cms_helper_test.rb @@ -48,20 +48,11 @@ class CmsHelperTest < ActionView::TestCase result = link_to_article(file) end - should 'display spread button when content is public' do + should 'display spread button' do plugins.stubs(:dispatch).returns([]) profile = fast_create(Person) article = fast_create(TinyMceArticle, :name => 'My article', :profile_id => profile.id) - expects(:link_to).with('Spread this', {:action => 'publish', :id => article.id}, :class => 'button with-text icon-spread', :title => nil) - - result = display_spread_button(article) - end - - should 'not display spread button when content is not public' do - plugins.stubs(:dispatch).returns([]) - profile = fast_create(Person) - article = fast_create(TinyMceArticle, :name => 'My article', :profile_id => profile.id, :published => false) - expects(:link_to).with('Spread this', {:action => 'publish', :id => article.id}, :class => 'button with-text icon-spread', :title => nil).never + expects(:link_to).with('Spread this', {:action => 'publish', :id => article.id}, :class => 'button with-text icon-spread colorbox', :title => nil) result = display_spread_button(article) end -- libgit2 0.21.2