diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index b4e3846..b6dc00e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -178,7 +178,7 @@ class ApplicationController < ActionController::Base def find_by_contents(asset, scope, query, paginate_options={:page => 1}, options={}) scope = scope.send(options[:filter]) if options[:filter] - @plugins.first(:find_by_contents, asset, scope, query, paginate_options, options) || + @plugins.dispatch_first(:find_by_contents, asset, scope, query, paginate_options, options) || fallback_find_by_contents(asset, scope, query, paginate_options, options) end diff --git a/app/controllers/public/content_viewer_controller.rb b/app/controllers/public/content_viewer_controller.rb index bf8089e..7818de9 100644 --- a/app/controllers/public/content_viewer_controller.rb +++ b/app/controllers/public/content_viewer_controller.rb @@ -98,7 +98,7 @@ class ContentViewerController < ApplicationController session[:notice] = _("Notification of new comments to '%s' was successfully canceled") % params[:email] end end - + @comments = @plugins.dispatch_first(:load_comments, @page) @comments ||= @page.comments.without_spam.as_thread @comments = [@comments] unless @comments.is_a?(Array) diff --git a/lib/noosfero/plugin/manager.rb b/lib/noosfero/plugin/manager.rb index 3859249..ec4ce93 100644 --- a/lib/noosfero/plugin/manager.rb +++ b/lib/noosfero/plugin/manager.rb @@ -24,7 +24,7 @@ class Noosfero::Plugin::Manager dispatch_without_flatten(event, *args).flatten end - def dispatch_plugins(event, *args) + def fetch_plugins(event, *args) map { |plugin| plugin.class if plugin.send(event, *args) }.compact.flatten end @@ -32,18 +32,9 @@ class Noosfero::Plugin::Manager map { |plugin| plugin.send(event, *args) }.compact end - def dispatch_first(event, *args) - value = nil - map do |plugin| - value = plugin.send(event, *args) - break if value - end - value - end - alias :dispatch_scopes :dispatch_without_flatten - def first(event, *args) + def dispatch_first(event, *args) result = nil each do |plugin| result = plugin.send(event, *args) @@ -52,7 +43,7 @@ class Noosfero::Plugin::Manager result end - def first_plugin(event, *args) + def fetch_first_plugin(event, *args) result = nil each do |plugin| if plugin.send(event, *args) diff --git a/test/unit/plugin_manager_test.rb b/test/unit/plugin_manager_test.rb index a2220ff..7bb6e11 100644 --- a/test/unit/plugin_manager_test.rb +++ b/test/unit/plugin_manager_test.rb @@ -135,7 +135,7 @@ class PluginManagerTest < ActiveSupport::TestCase environment.enable_plugin(Plugin2.name) environment.enable_plugin(Plugin3.name) - results = manager.dispatch_plugins(:random_event) + results = manager.fetch_plugins(:random_event) assert_includes results, Plugin2 assert_includes results, Plugin3 @@ -165,35 +165,7 @@ class PluginManagerTest < ActiveSupport::TestCase Plugin3.any_instance.expects(:random_event).never - assert_equal Plugin2, manager.first_plugin(:random_event) - end - - should 'dispatch_first method returns the first plugin response if there is many plugins to responde the event and the first one respond nil' do - - class Plugin1 < Noosfero::Plugin - def random_event - nil - end - end - - class Plugin2 < Noosfero::Plugin - def random_event - 'Plugin 2 action.' - end - end - - class Plugin3 < Noosfero::Plugin - def random_event - 'Plugin 3 action.' - end - end - - environment.stubs(:enabled_plugins).returns([Plugin1.to_s, Plugin2.to_s, Plugin3.to_s]) - - p2 = Plugin2.new - - assert_equal p2.random_event, plugins.dispatch_first(:random_event) + assert_equal Plugin2, manager.fetch_first_plugin(:random_event) end end - -- libgit2 0.21.2