diff --git a/db/migrate/20140715190749_add_setting_to_comments.rb b/db/migrate/20140715190749_add_setting_to_comments.rb deleted file mode 100644 index b709771..0000000 --- a/db/migrate/20140715190749_add_setting_to_comments.rb +++ /dev/null @@ -1,9 +0,0 @@ -class AddSettingToComments < ActiveRecord::Migration - def self.up - add_column :comments, :setting, :text unless column_exists?(:comments, :setting) - end - - def self.down - remove_column :comments, :setting - end -end diff --git a/lib/comment_paragraph_plugin.rb b/lib/comment_paragraph_plugin.rb index c430fd0..8ac1689 100644 --- a/lib/comment_paragraph_plugin.rb +++ b/lib/comment_paragraph_plugin.rb @@ -44,11 +44,14 @@ class CommentParagraphPlugin < Noosfero::Plugin 'manual' end - def article_toolbar_actions(article) - return unless article.comment_paragraph_plugin_enabled? - proc do - button :toggle_comment_paragraph, article.comment_paragraph_plugin_activated? ? _('Deactivate Comments') : _('Activate Comments'), :controller => 'comment_paragraph_plugin_myprofile', :profile => article.profile.identifier, :action => 'toggle_activation', :id => article.id if article.allow_edit?(user) - end + def article_extra_toolbar_buttons(article) + return [] if !article.comment_paragraph_plugin_enabled? || !article.allow_edit?(current_person) + { + :title => article.comment_paragraph_plugin_activated? ? _('Deactivate Comments') : _('Activate Comments'), + :url => {:controller => 'comment_paragraph_plugin_myprofile', :profile => article.profile.identifier, :action => 'toggle_activation', :id => article.id}, + :icon => :toggle_comment_paragraph + } + end end diff --git a/test/unit/comment_paragraph_plugin_test.rb b/test/unit/comment_paragraph_plugin_test.rb index cac7a8a..c8257e2 100644 --- a/test/unit/comment_paragraph_plugin_test.rb +++ b/test/unit/comment_paragraph_plugin_test.rb @@ -5,8 +5,10 @@ class CommentParagraphPluginTest < ActiveSupport::TestCase def setup @environment = Environment.default - @plugin = CommentParagraphPlugin.new @user = create_user('testuser').person + context = mock() + context.stubs(:current_person).returns(@user) + @plugin = CommentParagraphPlugin.new(context) end attr_reader :environment, :plugin, :user @@ -42,9 +44,7 @@ class CommentParagraphPluginTest < ActiveSupport::TestCase article.expects(:comment_paragraph_plugin_enabled?).returns(true) article.expects(:allow_edit?).with(user).returns(true) - content = plugin.article_toolbar_actions(article) - expects(:button).once - instance_eval(&content) + assert_not_equal [], plugin.article_extra_toolbar_buttons(article) end should 'not display button to toggle comment paragraph for users which can not edit the article' do @@ -53,8 +53,7 @@ class CommentParagraphPluginTest < ActiveSupport::TestCase article.expects(:comment_paragraph_plugin_enabled?).returns(true) article.expects(:allow_edit?).with(user).returns(false) - content = plugin.article_toolbar_actions(article) - assert_equal nil, instance_eval(&content) + assert_equal [], plugin.article_extra_toolbar_buttons(article) end should 'not display button to toggle comment paragraph if plugin is not enabled' do @@ -62,7 +61,27 @@ class CommentParagraphPluginTest < ActiveSupport::TestCase article = fast_create(Article, :profile_id => profile.id) article.expects(:comment_paragraph_plugin_enabled?).returns(false) - assert_equal nil, plugin.article_toolbar_actions(article) + assert_equal [], plugin.article_extra_toolbar_buttons(article) + end + + should 'display Activate Comments title if comment paragraph plugin is activated' do + profile = fast_create(Profile) + article = fast_create(Article, :profile_id => profile.id) + article.expects(:comment_paragraph_plugin_enabled?).returns(true) + article.expects(:allow_edit?).with(user).returns(true) + article.expects(:comment_paragraph_plugin_activated?).returns(false) + + assert_equal 'Activate Comments', plugin.article_extra_toolbar_buttons(article)[:title] + end + + should 'display Deactivate Comments title if comment paragraph plugin is deactivated' do + profile = fast_create(Profile) + article = fast_create(Article, :profile_id => profile.id) + article.expects(:comment_paragraph_plugin_enabled?).returns(true) + article.expects(:allow_edit?).with(user).returns(true) + article.expects(:comment_paragraph_plugin_activated?).returns(true) + + assert_equal 'Deactivate Comments', plugin.article_extra_toolbar_buttons(article)[:title] end end -- libgit2 0.21.2