From 052b0480b3b66187166b3454b76218c0361f8417 Mon Sep 17 00:00:00 2001 From: Larissa Reis Date: Tue, 3 Feb 2015 17:38:36 -0300 Subject: [PATCH] [relevant-content-plugin] Fixes crash when VotePlugin is not found --- plugins/relevant_content/lib/relevant_content_plugin/relevant_content_block.rb | 4 ++-- plugins/relevant_content/test/unit/article.rb | 8 ++++---- plugins/relevant_content/test/unit/relevant_content_block_test.rb | 15 +++++++++++++++ 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/plugins/relevant_content/lib/relevant_content_plugin/relevant_content_block.rb b/plugins/relevant_content/lib/relevant_content_plugin/relevant_content_block.rb index 16a4e28..4a0bafc 100644 --- a/plugins/relevant_content/lib/relevant_content_plugin/relevant_content_block.rb +++ b/plugins/relevant_content/lib/relevant_content_plugin/relevant_content_block.rb @@ -4,7 +4,7 @@ class RelevantContentPlugin::RelevantContentBlock < Block end def default_title - _('Relevant content') + _('Relevant content') end def help @@ -53,7 +53,7 @@ class RelevantContentPlugin::RelevantContentBlock < Block env = owner.environment end - if env.plugin_enabled?(VotePlugin) + if env.plugin_enabled?('VotePlugin') if self.show_most_liked docs = Article.more_positive_votes(owner, self.limit) if !docs.blank? diff --git a/plugins/relevant_content/test/unit/article.rb b/plugins/relevant_content/test/unit/article.rb index d986717..0e323e5 100644 --- a/plugins/relevant_content/test/unit/article.rb +++ b/plugins/relevant_content/test/unit/article.rb @@ -20,10 +20,10 @@ class RelevantContentBlockTest < ActiveSupport::TestCase def enable_vote_plugin enabled = false - environment=Environment.default + environment = Environment.default if Noosfero::Plugin.all.include?('VotePlugin') - if not environment.enabled_plugins.include?(:vote) - environment.enable_plugin(Vote) + if not environment.enabled_plugins.include?('VotePlugin') + environment.enable_plugin(VotePlugin) environment.save! end enabled = true @@ -145,4 +145,4 @@ class RelevantContentBlockTest < ActiveSupport::TestCase assert_equal '23 votes for 29 votes against', articles.first.name assert_equal '2 votes against', articles.last.name end -end \ No newline at end of file +end diff --git a/plugins/relevant_content/test/unit/relevant_content_block_test.rb b/plugins/relevant_content/test/unit/relevant_content_block_test.rb index 7823c05..1b97707 100644 --- a/plugins/relevant_content/test/unit/relevant_content_block_test.rb +++ b/plugins/relevant_content/test/unit/relevant_content_block_test.rb @@ -44,4 +44,19 @@ class RelevantContentBlockTest < ActiveSupport::TestCase assert_equal RelevantContentPlugin::RelevantContentBlock.expire_on, {:environment=>[:article], :profile=>[:article]} end + should 'not crash if vote plugin is not found' do + box = fast_create(Box, :owner_id => @profile.id, :owner_type => 'Profile') + block = RelevantContentPlugin::RelevantContentBlock.new(:box => box) + + Environment.any_instance.stubs(:enabled_plugins).returns(['RelevantContent']) + # When the plugin is disabled from noosfero instance, its constant name is + # undefined. To test this case, I have to manually undefine the constant + # if necessary. + Object.send(:remove_const, VotePlugin.to_s) if defined? VotePlugin + + assert_nothing_raised do + block.content + end + end + end -- libgit2 0.21.2