Commit 97489673c6318dbfd4675c8a9b62213a6bc448ff
Exists in
master
and in
27 other branches
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
Showing
4 changed files
with
23 additions
and
10 deletions
Show diff stats
plugins/relevant_content/lib/relevant_content_plugin/relevant_content_block.rb
| @@ -4,7 +4,7 @@ class RelevantContentPlugin::RelevantContentBlock < Block | @@ -4,7 +4,7 @@ class RelevantContentPlugin::RelevantContentBlock < Block | ||
| 4 | end | 4 | end |
| 5 | 5 | ||
| 6 | def default_title | 6 | def default_title |
| 7 | - _('Relevant content') | 7 | + _('Relevant content') |
| 8 | end | 8 | end |
| 9 | 9 | ||
| 10 | def help | 10 | def help |
| @@ -53,7 +53,7 @@ class RelevantContentPlugin::RelevantContentBlock < Block | @@ -53,7 +53,7 @@ class RelevantContentPlugin::RelevantContentBlock < Block | ||
| 53 | env = owner.environment | 53 | env = owner.environment |
| 54 | end | 54 | end |
| 55 | 55 | ||
| 56 | - if env.plugin_enabled?(VotePlugin) | 56 | + if env.plugin_enabled?('VotePlugin') |
| 57 | if self.show_most_liked | 57 | if self.show_most_liked |
| 58 | docs = Article.more_positive_votes(owner, self.limit) | 58 | docs = Article.more_positive_votes(owner, self.limit) |
| 59 | if !docs.blank? | 59 | if !docs.blank? |
plugins/relevant_content/test/unit/article.rb
| @@ -20,10 +20,10 @@ class RelevantContentBlockTest < ActiveSupport::TestCase | @@ -20,10 +20,10 @@ class RelevantContentBlockTest < ActiveSupport::TestCase | ||
| 20 | 20 | ||
| 21 | def enable_vote_plugin | 21 | def enable_vote_plugin |
| 22 | enabled = false | 22 | enabled = false |
| 23 | - environment=Environment.default | 23 | + environment = Environment.default |
| 24 | if Noosfero::Plugin.all.include?('VotePlugin') | 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 | environment.save! | 27 | environment.save! |
| 28 | end | 28 | end |
| 29 | enabled = true | 29 | enabled = true |
| @@ -145,4 +145,4 @@ class RelevantContentBlockTest < ActiveSupport::TestCase | @@ -145,4 +145,4 @@ class RelevantContentBlockTest < ActiveSupport::TestCase | ||
| 145 | assert_equal '23 votes for 29 votes against', articles.first.name | 145 | assert_equal '23 votes for 29 votes against', articles.first.name |
| 146 | assert_equal '2 votes against', articles.last.name | 146 | assert_equal '2 votes against', articles.last.name |
| 147 | end | 147 | end |
| 148 | -end | ||
| 149 | \ No newline at end of file | 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,4 +44,19 @@ class RelevantContentBlockTest < ActiveSupport::TestCase | ||
| 44 | assert_equal RelevantContentPlugin::RelevantContentBlock.expire_on, {:environment=>[:article], :profile=>[:article]} | 44 | assert_equal RelevantContentPlugin::RelevantContentBlock.expire_on, {:environment=>[:article], :profile=>[:article]} |
| 45 | end | 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 | end | 62 | end |
plugins/tolerance_time/lib/tolerance_time_plugin.rb
| @@ -28,8 +28,7 @@ class ToleranceTimePlugin < Noosfero::Plugin | @@ -28,8 +28,7 @@ class ToleranceTimePlugin < Noosfero::Plugin | ||
| 28 | end | 28 | end |
| 29 | 29 | ||
| 30 | def cms_controller_filters | 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 | content = Article.find(params[:id]) | 32 | content = Article.find(params[:id]) |
| 34 | if ToleranceTimePlugin.expired?(content) | 33 | if ToleranceTimePlugin.expired?(content) |
| 35 | session[:notice] = _("This content can't be edited anymore because it expired the tolerance time") | 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,8 +42,7 @@ class ToleranceTimePlugin < Noosfero::Plugin | ||
| 43 | end | 42 | end |
| 44 | 43 | ||
| 45 | def content_viewer_controller_filters | 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 | content = Comment.find(params[:id]) | 46 | content = Comment.find(params[:id]) |
| 49 | if ToleranceTimePlugin.expired?(content) | 47 | if ToleranceTimePlugin.expired?(content) |
| 50 | session[:notice] = _("This content can't be edited anymore because it expired the tolerance time") | 48 | session[:notice] = _("This content can't be edited anymore because it expired the tolerance time") |