Commit 037e6360f53129c37e4e065cbe6185920dbff7fd
1 parent
d32bf3a4
Exists in
master
and in
29 other branches
Revert "plugins: only call default value if result is blank"
This reverts commit 8a3fb6f312e27c4225b95dff84ea365432e361ed.
Showing
3 changed files
with
12 additions
and
23 deletions
Show diff stats
lib/noosfero/plugin/manager.rb
@@ -33,24 +33,26 @@ class Noosfero::Plugin::Manager | @@ -33,24 +33,26 @@ class Noosfero::Plugin::Manager | ||
33 | 33 | ||
34 | alias :dispatch_scopes :dispatch_without_flatten | 34 | alias :dispatch_scopes :dispatch_without_flatten |
35 | 35 | ||
36 | - def default_for event, *args | ||
37 | - Noosfero::Plugin.new.send event, *args | ||
38 | - end | ||
39 | - | ||
40 | def dispatch_first(event, *args) | 36 | def dispatch_first(event, *args) |
37 | + default = Noosfero::Plugin.new.send(event, *args) | ||
38 | + result = default | ||
41 | each do |plugin| | 39 | each do |plugin| |
42 | result = plugin.send(event, *args) | 40 | result = plugin.send(event, *args) |
43 | - return result if result.present? | 41 | + break if result != default |
44 | end | 42 | end |
45 | - default_for event, *args | 43 | + result |
46 | end | 44 | end |
47 | 45 | ||
48 | def fetch_first_plugin(event, *args) | 46 | def fetch_first_plugin(event, *args) |
47 | + default = Noosfero::Plugin.new.send(event, *args) | ||
48 | + result = nil | ||
49 | each do |plugin| | 49 | each do |plugin| |
50 | - result = plugin.send event, *args | ||
51 | - return plugin.class if result.present? | 50 | + if plugin.send(event, *args) != default |
51 | + result = plugin.class | ||
52 | + break | ||
53 | + end | ||
52 | end | 54 | end |
53 | - nil | 55 | + result |
54 | end | 56 | end |
55 | 57 | ||
56 | def pipeline(event, *args) | 58 | def pipeline(event, *args) |
test/unit/plugin_manager_test.rb
@@ -291,17 +291,4 @@ class PluginManagerTest < ActiveSupport::TestCase | @@ -291,17 +291,4 @@ class PluginManagerTest < ActiveSupport::TestCase | ||
291 | assert_equal [7,9], manager.filter(:invalid_numbers, [1,2,3,4,5,6,7,8,9,10]) | 291 | assert_equal [7,9], manager.filter(:invalid_numbers, [1,2,3,4,5,6,7,8,9,10]) |
292 | end | 292 | end |
293 | 293 | ||
294 | - should 'only call default if value is blank' do | ||
295 | - class Plugin1 < Noosfero::Plugin | ||
296 | - def find_by_contents asset, scope, query, paginate_options={}, options={} | ||
297 | - {results: [1,2,3]} | ||
298 | - end | ||
299 | - end | ||
300 | - Noosfero::Plugin.stubs(:all).returns(['PluginManagerTest::Plugin1']) | ||
301 | - environment.enable_plugin(Plugin1) | ||
302 | - | ||
303 | - Noosfero::Plugin.any_instance.expects(:find_by_contents).never | ||
304 | - @manager.dispatch_first :find_by_contents, :products, environment.products, 'product' | ||
305 | - end | ||
306 | - | ||
307 | end | 294 | end |
test/unit/plugin_test.rb
@@ -23,7 +23,7 @@ class PluginTest < ActiveSupport::TestCase | @@ -23,7 +23,7 @@ class PluginTest < ActiveSupport::TestCase | ||
23 | end | 23 | end |
24 | 24 | ||
25 | should 'returns empty hash for class method extra_blocks by default if no blocks are defined on plugin' do | 25 | should 'returns empty hash for class method extra_blocks by default if no blocks are defined on plugin' do |
26 | - | 26 | + |
27 | class SomePlugin1 < Noosfero::Plugin | 27 | class SomePlugin1 < Noosfero::Plugin |
28 | end | 28 | end |
29 | 29 |