Commit 51d3ac08b10f2f063a6915b83e95329dd14613dd

Authored by Braulio Bhavamitra
1 parent 3c94729b

plugins: don't crash on method_missing methods

lib/noosfero/plugin/manager.rb
@@ -38,6 +38,8 @@ class Noosfero::Plugin::Manager @@ -38,6 +38,8 @@ class Noosfero::Plugin::Manager
38 end 38 end
39 39
40 def result_for plugin, event, *args 40 def result_for plugin, event, *args
  41 + # check if defined to avoid crash, as there is hotspots using method_missing
  42 + return unless plugin.respond_to? event
41 method = plugin.method event 43 method = plugin.method event
42 method.call *args if method.owner != Noosfero::Plugin 44 method.call *args if method.owner != Noosfero::Plugin
43 end 45 end
test/unit/plugin_manager_test.rb
@@ -178,6 +178,15 @@ class PluginManagerTest < ActiveSupport::TestCase @@ -178,6 +178,15 @@ class PluginManagerTest < ActiveSupport::TestCase
178 assert_equal Plugin2, manager.fetch_first_plugin(:random_event) 178 assert_equal Plugin2, manager.fetch_first_plugin(:random_event)
179 end 179 end
180 180
  181 + should 'return nil if missing method is called' do
  182 + class Plugin1 < Noosfero::Plugin
  183 + end
  184 + Noosfero::Plugin.stubs(:all).returns(['PluginManagerTest::Plugin1'])
  185 + environment.enable_plugin(Plugin1)
  186 +
  187 + assert_equal nil, @manager.result_for(Plugin1.new, :content_remove_new)
  188 + end
  189 +
181 should 'parse macro' do 190 should 'parse macro' do
182 class Plugin1 < Noosfero::Plugin 191 class Plugin1 < Noosfero::Plugin
183 def macros 192 def macros