Commit 97489673c6318dbfd4675c8a9b62213a6bc448ff

Authored by Braulio Bhavamitra
2 parents f6b51288 052b0480

Merge branch 'fixes-plugins' into 'master'

Fixes for ToleranceTimePlugin and RelevantContentPlugin

Fixes blocking crashes when enabling these plugins: NameError exception in RelevantContentPlugin and argument mismatch for ToleranceTimePlugin.

See merge request !450
plugins/relevant_content/lib/relevant_content_plugin/relevant_content_block.rb
... ... @@ -4,7 +4,7 @@ class RelevantContentPlugin::RelevantContentBlock < Block
4 4 end
5 5  
6 6 def default_title
7   - _('Relevant content')
  7 + _('Relevant content')
8 8 end
9 9  
10 10 def help
... ... @@ -53,7 +53,7 @@ class RelevantContentPlugin::RelevantContentBlock < Block
53 53 env = owner.environment
54 54 end
55 55  
56   - if env.plugin_enabled?(VotePlugin)
  56 + if env.plugin_enabled?('VotePlugin')
57 57 if self.show_most_liked
58 58 docs = Article.more_positive_votes(owner, self.limit)
59 59 if !docs.blank?
... ...
plugins/relevant_content/test/unit/article.rb
... ... @@ -20,10 +20,10 @@ class RelevantContentBlockTest < ActiveSupport::TestCase
20 20  
21 21 def enable_vote_plugin
22 22 enabled = false
23   - environment=Environment.default
  23 + environment = Environment.default
24 24 if Noosfero::Plugin.all.include?('VotePlugin')
25   - if not environment.enabled_plugins.include?(:vote)
26   - environment.enable_plugin(Vote)
  25 + if not environment.enabled_plugins.include?('VotePlugin')
  26 + environment.enable_plugin(VotePlugin)
27 27 environment.save!
28 28 end
29 29 enabled = true
... ... @@ -145,4 +145,4 @@ class RelevantContentBlockTest < ActiveSupport::TestCase
145 145 assert_equal '23 votes for 29 votes against', articles.first.name
146 146 assert_equal '2 votes against', articles.last.name
147 147 end
148   -end
149 148 \ No newline at end of file
  149 +end
... ...
plugins/relevant_content/test/unit/relevant_content_block_test.rb
... ... @@ -44,4 +44,19 @@ class RelevantContentBlockTest < ActiveSupport::TestCase
44 44 assert_equal RelevantContentPlugin::RelevantContentBlock.expire_on, {:environment=>[:article], :profile=>[:article]}
45 45 end
46 46  
  47 + should 'not crash if vote plugin is not found' do
  48 + box = fast_create(Box, :owner_id => @profile.id, :owner_type => 'Profile')
  49 + block = RelevantContentPlugin::RelevantContentBlock.new(:box => box)
  50 +
  51 + Environment.any_instance.stubs(:enabled_plugins).returns(['RelevantContent'])
  52 + # When the plugin is disabled from noosfero instance, its constant name is
  53 + # undefined. To test this case, I have to manually undefine the constant
  54 + # if necessary.
  55 + Object.send(:remove_const, VotePlugin.to_s) if defined? VotePlugin
  56 +
  57 + assert_nothing_raised do
  58 + block.content
  59 + end
  60 + end
  61 +
47 62 end
... ...
plugins/tolerance_time/lib/tolerance_time_plugin.rb
... ... @@ -28,8 +28,7 @@ class ToleranceTimePlugin < Noosfero::Plugin
28 28 end
29 29  
30 30 def cms_controller_filters
31   - p = Proc.new { |context| return if !context.environment.plugin_enabled?(ToleranceTimePlugin) }
32   - block = lambda do
  31 + block = proc do
33 32 content = Article.find(params[:id])
34 33 if ToleranceTimePlugin.expired?(content)
35 34 session[:notice] = _("This content can't be edited anymore because it expired the tolerance time")
... ... @@ -43,8 +42,7 @@ class ToleranceTimePlugin < Noosfero::Plugin
43 42 end
44 43  
45 44 def content_viewer_controller_filters
46   - p = Proc.new { |context| return if !context.environment.plugin_enabled?(ToleranceTimePlugin) }
47   - block = lambda do
  45 + block = proc do
48 46 content = Comment.find(params[:id])
49 47 if ToleranceTimePlugin.expired?(content)
50 48 session[:notice] = _("This content can't be edited anymore because it expired the tolerance time")
... ...