Commit 51d3ac08b10f2f063a6915b83e95329dd14613dd
1 parent
3c94729b
Exists in
master
and in
29 other branches
plugins: don't crash on method_missing methods
Showing
2 changed files
with
11 additions
and
0 deletions
Show diff stats
lib/noosfero/plugin/manager.rb
... | ... | @@ -38,6 +38,8 @@ class Noosfero::Plugin::Manager |
38 | 38 | end |
39 | 39 | |
40 | 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 | 43 | method = plugin.method event |
42 | 44 | method.call *args if method.owner != Noosfero::Plugin |
43 | 45 | end | ... | ... |
test/unit/plugin_manager_test.rb
... | ... | @@ -178,6 +178,15 @@ class PluginManagerTest < ActiveSupport::TestCase |
178 | 178 | assert_equal Plugin2, manager.fetch_first_plugin(:random_event) |
179 | 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 | 190 | should 'parse macro' do |
182 | 191 | class Plugin1 < Noosfero::Plugin |
183 | 192 | def macros | ... | ... |
-
mentioned in commit 81478cba44472bcffd459ba21e866fdd4a1b315d