Commit 71066d56ee18279d8ef5f98534905536ad228967
1 parent
53ee2cd4
Exists in
master
and in
29 other branches
Consistent interface for Noosfero::Plugin::Manager
I had to change a lot of plugin hotspot tests that depended on heavy/evil mocking and stubbing to pass. (ActionItem2315)
Showing
21 changed files
with
123 additions
and
98 deletions
Show diff stats
app/controllers/application_controller.rb
... | ... | @@ -104,8 +104,8 @@ class ApplicationController < ActionController::Base |
104 | 104 | |
105 | 105 | def init_noosfero_plugins |
106 | 106 | @plugins = Noosfero::Plugin::Manager.new(self) |
107 | - @plugins.enabled_plugins.map(&:class).each do |plugin| | |
108 | - prepend_view_path(plugin.view_path) | |
107 | + @plugins.each do |plugin| | |
108 | + prepend_view_path(plugin.class.view_path) | |
109 | 109 | end |
110 | 110 | init_noosfero_plugins_controller_filters |
111 | 111 | end |
... | ... | @@ -113,7 +113,7 @@ class ApplicationController < ActionController::Base |
113 | 113 | # This is a generic method that initialize any possible filter defined by a |
114 | 114 | # plugin to the current controller being initialized. |
115 | 115 | def init_noosfero_plugins_controller_filters |
116 | - @plugins.enabled_plugins.each do |plugin| | |
116 | + @plugins.each do |plugin| | |
117 | 117 | plugin.send(self.class.name.underscore + '_filters').each do |plugin_filter| |
118 | 118 | self.class.send(plugin_filter[:type], plugin.class.name.underscore + '_' + plugin_filter[:method_name], (plugin_filter[:options] || {})) |
119 | 119 | self.class.send(:define_method, plugin.class.name.underscore + '_' + plugin_filter[:method_name], plugin_filter[:block]) | ... | ... |
app/controllers/my_profile/cms_controller.rb
... | ... | @@ -50,7 +50,7 @@ class CmsController < MyProfileController |
50 | 50 | end |
51 | 51 | |
52 | 52 | def special_article_types |
53 | - [Folder, Blog, UploadedFile, Forum, Gallery, RssFeed] + @plugins.map(:content_types) | |
53 | + [Folder, Blog, UploadedFile, Forum, Gallery, RssFeed] + @plugins.dispatch(:content_types) | |
54 | 54 | end |
55 | 55 | |
56 | 56 | def view | ... | ... |
app/controllers/public/account_controller.rb
... | ... | @@ -242,7 +242,7 @@ class AccountController < ApplicationController |
242 | 242 | session[:notice] = nil # consume the notice |
243 | 243 | end |
244 | 244 | |
245 | - @plugins.enabled_plugins.each { |plugin| user_data.merge!(plugin.user_data_extras) } | |
245 | + @plugins.each { |plugin| user_data.merge!(plugin.user_data_extras) } | |
246 | 246 | |
247 | 247 | render :text => user_data.to_json, :layout => false, :content_type => "application/javascript" |
248 | 248 | end | ... | ... |
app/helpers/application_helper.rb
... | ... | @@ -1020,7 +1020,7 @@ module ApplicationHelper |
1020 | 1020 | options.merge!(:page => params[:npage]) |
1021 | 1021 | content = article.to_html(options) |
1022 | 1022 | content = content.kind_of?(Proc) ? self.instance_eval(&content) : content |
1023 | - @plugins && @plugins.enabled_plugins.each do |plugin| | |
1023 | + @plugins && @plugins.each do |plugin| | |
1024 | 1024 | content = plugin.parse_content(content) |
1025 | 1025 | end |
1026 | 1026 | content | ... | ... |
app/helpers/boxes_helper.rb
... | ... | @@ -99,7 +99,7 @@ module BoxesHelper |
99 | 99 | unless block.visible? |
100 | 100 | options[:title] = _("This block is invisible. Your visitors will not see it.") |
101 | 101 | end |
102 | - @controller.send(:content_editor?) || @plugins.enabled_plugins.each do |plugin| | |
102 | + @controller.send(:content_editor?) || @plugins.each do |plugin| | |
103 | 103 | result = plugin.parse_content(result) |
104 | 104 | end |
105 | 105 | box_decorator.block_target(block.box, block) + | ... | ... |
app/views/admin_panel/index.rhtml
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | <tr><td><%= link_to _('Edit Templates'), :action => 'edit_templates' %></td></tr> |
16 | 16 | <tr><td><%= link_to _('Manage Fields'), :controller => 'features', :action => 'manage_fields' %></td></tr> |
17 | 17 | <tr><td><%= link_to _('Set Portal'), :action => 'set_portal_community' %></td></tr> |
18 | - <% @plugins.map(:admin_panel_links).each do |link| %> | |
18 | + <% @plugins.dispatch(:admin_panel_links).each do |link| %> | |
19 | 19 | <tr><td><%= link_to link[:title], link[:url] %></td></tr> |
20 | 20 | <% end %> |
21 | 21 | </table> | ... | ... |
app/views/catalog/index.rhtml
... | ... | @@ -5,8 +5,8 @@ |
5 | 5 | <li><h1><%= _('Products/Services') %></h1></li> |
6 | 6 | |
7 | 7 | <% @products.each do |product| %> |
8 | - <% extra_content = @plugins.map(:catalog_item_extras, product).collect { |content| instance_eval(&content) } %> | |
9 | - <% extra_content_list = @plugins.map(:catalog_list_item_extras, product).collect { |content| instance_eval(&content) } %> | |
8 | + <% extra_content = @plugins.dispatch(:catalog_item_extras, product).collect { |content| instance_eval(&content) } %> | |
9 | + <% extra_content_list = @plugins.dispatch(:catalog_list_item_extras, product).collect { |content| instance_eval(&content) } %> | |
10 | 10 | |
11 | 11 | <li class="product <%= "not-available" unless product.available %>"> |
12 | 12 | <ul> | ... | ... |
app/views/layouts/application-ng.rhtml
... | ... | @@ -13,7 +13,7 @@ |
13 | 13 | <%= stylesheet_link_tag icon_theme_stylesheet_path %> |
14 | 14 | <%= stylesheet_link_tag jquery_ui_theme_stylesheet_path %> |
15 | 15 | <% |
16 | - plugins_stylesheets = @plugins.enabled_plugins.select(&:stylesheet?).map { |plugin| plugin.class.public_path('style.css') } | |
16 | + plugins_stylesheets = @plugins.select(&:stylesheet?).map { |plugin| plugin.class.public_path('style.css') } | |
17 | 17 | %> |
18 | 18 | <%= stylesheet_link_tag(plugins_stylesheets, :cache => 'cache-plugins-style-' + Digest::MD5.hexdigest(plugins_stylesheets.to_s)) unless plugins_stylesheets.empty? %> |
19 | 19 | <%= stylesheet_link_tag theme_stylesheet_path %> |
... | ... | @@ -22,11 +22,11 @@ |
22 | 22 | <%= yield :head %> |
23 | 23 | <%= javascript_tag('render_all_jquery_ui_widgets()') %> |
24 | 24 | <% |
25 | - plugins_javascripts = @plugins.enabled_plugins.map { |plugin| plugin.js_files.map { |js| plugin.class.public_path(js) } }.flatten | |
25 | + plugins_javascripts = @plugins.map { |plugin| plugin.js_files.map { |js| plugin.class.public_path(js) } }.flatten | |
26 | 26 | %> |
27 | 27 | <%= javascript_include_tag(plugins_javascripts, :cache => 'cache-plugins-js-' + Digest::MD5.hexdigest(plugins_javascripts.to_s)) unless plugins_javascripts.empty? %> |
28 | 28 | <%= |
29 | - @plugins.map(:head_ending).collect do |content| | |
29 | + @plugins.dispatch(:head_ending).collect do |content| | |
30 | 30 | content.respond_to?(:call) ? content.call : content |
31 | 31 | end.join("\n") |
32 | 32 | %> |
... | ... | @@ -41,7 +41,7 @@ |
41 | 41 | |
42 | 42 | <a href="#content" id="link-go-content"><span><%= _("Go to the content") %></span></a> |
43 | 43 | <%= |
44 | - @plugins.map(:body_beginning).collect do |content| | |
44 | + @plugins.dispatch(:body_beginning).collect do |content| | |
45 | 45 | content.respond_to?(:call) ? content.call : content |
46 | 46 | end.join("\n") |
47 | 47 | %> | ... | ... |
app/views/manage_products/show.rhtml
... | ... | @@ -13,7 +13,7 @@ |
13 | 13 | <%= render :partial => 'manage_products/display_image' %> |
14 | 14 | </div> |
15 | 15 | <div id='product-extra-content'> |
16 | - <% extra_content = @plugins.map(:product_info_extras, @product).collect { |content| instance_eval(&content) } %> | |
16 | + <% extra_content = @plugins.dispatch(:product_info_extras, @product).collect { |content| instance_eval(&content) } %> | |
17 | 17 | <%= extra_content.join("\n") %> |
18 | 18 | </div> |
19 | 19 | <div id='product-info'> | ... | ... |
app/views/profile/_profile.rhtml
1 | 1 | <tr> |
2 | 2 | <td colspan='2'> |
3 | 3 | |
4 | - <% plugins_tabs = @plugins.map(:profile_tabs). | |
4 | + <% plugins_tabs = @plugins.dispatch(:profile_tabs). | |
5 | 5 | map { |tab| {:title => tab[:title], :id => tab[:id], :content => instance_eval(&tab[:content]), :start => tab[:title]} }%> |
6 | 6 | |
7 | 7 | <% tabs = plugins_tabs.select { |tab| tab[:start] } %> | ... | ... |
app/views/profile_editor/edit.rhtml
app/views/profile_editor/index.rhtml
... | ... | @@ -66,7 +66,7 @@ |
66 | 66 | |
67 | 67 | <%= control_panel_button(_('Manage my groups'), 'groups', :controller => 'memberships') if profile.person? %> |
68 | 68 | |
69 | - <% @plugins.map(:control_panel_buttons).each do |button| %> | |
69 | + <% @plugins.dispatch(:control_panel_buttons).each do |button| %> | |
70 | 70 | <%= control_panel_button(button[:title], button[:icon], button[:url]) %> |
71 | 71 | <% end %> |
72 | 72 | ... | ... |
app/views/profile_members/_index_buttons.rhtml
... | ... | @@ -5,7 +5,7 @@ |
5 | 5 | <%= button :search, _('Invite your friends to join %s') % profile.short_name, :controller => 'invite', :action => 'select_address_book' %> |
6 | 6 | <% end %> |
7 | 7 | <%= button :send, _('Send e-mail to members'), :action => 'send_mail' %> |
8 | - <% @plugins.map(:manage_members_extra_buttons).each do |plugin_button| %> | |
8 | + <% @plugins.dispatch(:manage_members_extra_buttons).each do |plugin_button| %> | |
9 | 9 | <%= button plugin_button[:icon], plugin_button[:title], plugin_button[:url] %> |
10 | 10 | <% end %> |
11 | 11 | <% end %> | ... | ... |
app/views/search/_product.rhtml
... | ... | @@ -5,8 +5,8 @@ product_item_pos = 0 if ! product_item_pos |
5 | 5 | product_item_pos += 1 |
6 | 6 | %> |
7 | 7 | |
8 | -<% extra_content = @plugins.map(:asset_product_extras, product, product.enterprise).collect { |content| instance_eval(&content) } %> | |
9 | -<% extra_properties = @plugins.map(:asset_product_properties, product)%> | |
8 | +<% extra_content = @plugins.dispatch(:asset_product_extras, product, product.enterprise).collect { |content| instance_eval(&content) } %> | |
9 | +<% extra_properties = @plugins.dispatch(:asset_product_properties, product)%> | |
10 | 10 | |
11 | 11 | <li class="product-item <%= ( pos % 2 == 0 ) ? 'odd' : 'even' %>"> |
12 | 12 | <%= link_to_product product, :class => 'product-pic', :style => 'background-image:url(%s)' % product.default_image(:minor) %> | ... | ... |
lib/noosfero/plugin/manager.rb
... | ... | @@ -6,12 +6,19 @@ class Noosfero::Plugin::Manager |
6 | 6 | @context = Noosfero::Plugin::Context.new(controller) |
7 | 7 | end |
8 | 8 | |
9 | - def map(event, *args) | |
10 | - enabled_plugins.map { |plugin| plugin.send(event, *args) }.compact.flatten | |
11 | - end | |
9 | + delegate :each, :to => :enabled_plugins | |
10 | + include Enumerable | |
12 | 11 | |
13 | - def collect(&block) | |
14 | - enabled_plugins.collect(&block) | |
12 | + # Dispatches +event+ to each enabled plugin and collect the results. | |
13 | + # | |
14 | + # Returns an Array containing the objects returned by the event method in | |
15 | + # each plugin. This array is compacted (i.e. nils are removed) and flattened | |
16 | + # (i.e. elements of arrays are added to the resulting array). For example, if | |
17 | + # the enabled plugins return 1, 0, nil, and [1,2,3], then this method will | |
18 | + # return [1,0,1,2,3] | |
19 | + # | |
20 | + def dispatch(event, *args) | |
21 | + map { |plugin| plugin.send(event, *args) }.compact.flatten | |
15 | 22 | end |
16 | 23 | |
17 | 24 | def enabled_plugins | ... | ... |
test/functional/admin_panel_controller_test.rb
... | ... | @@ -332,20 +332,23 @@ class AdminPanelControllerTest < ActionController::TestCase |
332 | 332 | end |
333 | 333 | |
334 | 334 | should 'display plugins links' do |
335 | - plugin1_link = {:title => 'Plugin1 link', :url => 'plugin1.com'} | |
336 | - plugin2_link = {:title => 'Plugin2 link', :url => 'plugin2.com'} | |
337 | - links = [plugin1_link, plugin2_link] | |
338 | - plugins = mock() | |
339 | - plugins.stubs(:map).with(:admin_panel_links).returns(links) | |
340 | - plugins.stubs(:enabled_plugins).returns([]) | |
341 | - plugins.stubs(:map).with(:body_beginning).returns([]) | |
342 | - plugins.stubs(:map).with(:head_ending).returns([]) | |
343 | - Noosfero::Plugin::Manager.stubs(:new).returns(plugins) | |
335 | + class TestAdminPanelLinks1 < Noosfero::Plugin | |
336 | + def admin_panel_links | |
337 | + {:title => 'Plugin1 link', :url => 'plugin1.com'} | |
338 | + end | |
339 | + end | |
340 | + class TestAdminPanelLinks2 < Noosfero::Plugin | |
341 | + def admin_panel_links | |
342 | + {:title => 'Plugin2 link', :url => 'plugin2.com'} | |
343 | + end | |
344 | + end | |
345 | + | |
346 | + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestAdminPanelLinks1.new, TestAdminPanelLinks2.new]) | |
344 | 347 | |
345 | 348 | get :index |
346 | 349 | |
347 | - assert_tag :tag => 'a', :content => /#{plugin1_link[:title]}/, :attributes => {:href => /#{plugin1_link[:url]}/} | |
348 | - assert_tag :tag => 'a', :content => /#{plugin2_link[:title]}/, :attributes => {:href => /#{plugin2_link[:url]}/} | |
350 | + assert_tag :tag => 'a', :content => /Plugin1 link/, :attributes => {:href => /plugin1.com/} | |
351 | + assert_tag :tag => 'a', :content => /Plugin2 link/, :attributes => {:href => /plugin2.com/} | |
349 | 352 | end |
350 | 353 | |
351 | 354 | end | ... | ... |
test/functional/application_controller_test.rb
... | ... | @@ -392,38 +392,49 @@ class ApplicationControllerTest < ActionController::TestCase |
392 | 392 | end |
393 | 393 | |
394 | 394 | should 'include content in the beginning of body supplied by plugins regardless it is a block or html code' do |
395 | - plugin1_local_variable = "Plugin1" | |
396 | - plugin1_content = lambda {"<span id='plugin1'>This is #{plugin1_local_variable} speaking!</span>"} | |
397 | - plugin2_content = "<span id='plugin2'>This is Plugin2 speaking!</span>" | |
398 | - contents = [plugin1_content, plugin2_content] | |
395 | + class TestBodyBeginning1Plugin < Noosfero::Plugin | |
396 | + def plugin1_method | |
397 | + '[[plugin1]]' | |
398 | + end | |
399 | + def body_beginning | |
400 | + lambda {"<span id='plugin1'>This is #{plugin1_method} speaking!</span>"} | |
401 | + end | |
402 | + end | |
403 | + class TestBodyBeginning2Plugin < Noosfero::Plugin | |
404 | + def body_beginning | |
405 | + "<span id='plugin2'>This is Plugin2 speaking!</span>" | |
406 | + end | |
407 | + end | |
399 | 408 | |
400 | - plugins = mock() | |
401 | - plugins.stubs(:enabled_plugins).returns([]) | |
402 | - plugins.stubs(:map).with(:body_beginning).returns(contents) | |
403 | - plugins.stubs(:map).with(:head_ending).returns([]) | |
404 | - Noosfero::Plugin::Manager.stubs(:new).returns(plugins) | |
409 | + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestBodyBeginning1Plugin.new, TestBodyBeginning2Plugin.new]) | |
405 | 410 | |
406 | 411 | get :index |
407 | 412 | |
408 | - assert_tag :tag => 'span', :content => 'This is ' + plugin1_local_variable + ' speaking!', :attributes => {:id => 'plugin1'} | |
413 | + assert_tag :tag => 'span', :content => 'This is [[plugin1]] speaking!', :attributes => {:id => 'plugin1'} | |
409 | 414 | assert_tag :tag => 'span', :content => 'This is Plugin2 speaking!', :attributes => {:id => 'plugin2'} |
410 | 415 | end |
411 | 416 | |
412 | 417 | should 'include content in the ending of head supplied by plugins regardless it is a block or html code' do |
413 | - plugin1_local_variable = "Plugin1" | |
414 | - plugin1_content = lambda {"<script>alert('This is #{plugin1_local_variable} speaking!')</script>"} | |
415 | - plugin2_content = "<style>This is Plugin2 speaking!</style>" | |
416 | - contents = [plugin1_content, plugin2_content] | |
417 | 418 | |
418 | - plugins = mock() | |
419 | - plugins.stubs(:enabled_plugins).returns([]) | |
420 | - plugins.stubs(:map).with(:head_ending).returns(contents) | |
421 | - plugins.stubs(:map).with(:body_beginning).returns([]) | |
422 | - Noosfero::Plugin::Manager.stubs(:new).returns(plugins) | |
419 | + class TestHeadEnding1Plugin < Noosfero::Plugin | |
420 | + def plugin1_method | |
421 | + '[[plugin1]]' | |
422 | + end | |
423 | + def head_ending | |
424 | + lambda {"<script>alert('This is #{plugin1_method} speaking!')</script>"} | |
425 | + end | |
426 | + end | |
427 | + class TestHeadEnding2Plugin < Noosfero::Plugin | |
428 | + def head_ending | |
429 | + "<style>This is Plugin2 speaking!</style>" | |
430 | + end | |
431 | + end | |
432 | + | |
433 | + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestHeadEnding1Plugin.new, TestHeadEnding2Plugin.new]) | |
423 | 434 | |
424 | 435 | get :index |
425 | 436 | |
426 | - assert_tag :tag => 'script', :content => "alert('This is #{plugin1_local_variable} speaking!')" | |
437 | + assert_tag :tag => 'script', :content => "alert('This is [[plugin1]] speaking!')" | |
427 | 438 | assert_tag :tag => 'style', :content => 'This is Plugin2 speaking!' |
428 | 439 | end |
429 | 440 | ... | ... |
test/functional/cms_controller_test.rb
... | ... | @@ -1509,14 +1509,13 @@ class CmsControllerTest < ActionController::TestCase |
1509 | 1509 | end |
1510 | 1510 | |
1511 | 1511 | should 'include new contents special types from plugins' do |
1512 | - types = [Integer, Float] | |
1513 | - plugins = mock() | |
1514 | - | |
1515 | - Noosfero::Plugin::Manager.expects(:new).with(@controller).returns(plugins).times(2) | |
1516 | - plugins.stubs(:map).with(:content_types).returns(types) | |
1517 | - plugins.stubs(:map).with(:body_beginning).returns([]) | |
1518 | - plugins.stubs(:map).with(:head_ending).returns([]) | |
1519 | - plugins.stubs(:enabled_plugins).returns([]) | |
1512 | + class TestContentTypesPlugin < Noosfero::Plugin | |
1513 | + def content_types | |
1514 | + [Integer, Float] | |
1515 | + end | |
1516 | + end | |
1517 | + | |
1518 | + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestContentTypesPlugin.new]) | |
1520 | 1519 | |
1521 | 1520 | get :index, :profile => profile.identifier |
1522 | 1521 | ... | ... |
test/functional/manage_products_controller_test.rb
... | ... | @@ -437,24 +437,25 @@ class ManageProductsControllerTest < ActionController::TestCase |
437 | 437 | end |
438 | 438 | |
439 | 439 | should 'include extra content supplied by plugins on products info extras' do |
440 | + class TestProductInfoExtras1Plugin < Noosfero::Plugin | |
441 | + def product_info_extras(p) | |
442 | + lambda {"<span id='plugin1'>This is Plugin1 speaking!</span>"} | |
443 | + end | |
444 | + end | |
445 | + class TestProductInfoExtras2Plugin < Noosfero::Plugin | |
446 | + def product_info_extras(p) | |
447 | + lambda { "<span id='plugin2'>This is Plugin2 speaking!</span>" } | |
448 | + end | |
449 | + end | |
450 | + | |
440 | 451 | product = fast_create(Product, :enterprise_id => @enterprise.id) |
441 | - plugin1_local_variable = "Plugin1" | |
442 | - plugin1_content = lambda {"<span id='plugin1'>This is #{plugin1_local_variable} speaking!</span>"} | |
443 | - plugin2_local_variable = "Plugin2" | |
444 | - plugin2_content = lambda {"<span id='plugin2'>This is #{plugin2_local_variable} speaking!</span>"} | |
445 | - contents = [plugin1_content, plugin2_content] | |
446 | - | |
447 | - plugins = mock() | |
448 | - plugins.stubs(:enabled_plugins).returns([]) | |
449 | - plugins.stubs(:map).with(:body_beginning).returns([]) | |
450 | - plugins.stubs(:map).with(:head_ending).returns([]) | |
451 | - plugins.stubs(:map).with(:product_info_extras, product).returns(contents) | |
452 | - Noosfero::Plugin::Manager.stubs(:new).returns(plugins) | |
452 | + | |
453 | + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestProductInfoExtras1Plugin.new, TestProductInfoExtras2Plugin.new]) | |
453 | 454 | |
454 | 455 | get :show, :id => product.id, :profile => @enterprise.identifier |
455 | 456 | |
456 | - assert_tag :tag => 'span', :content => 'This is ' + plugin1_local_variable + ' speaking!', :attributes => {:id => 'plugin1'} | |
457 | - assert_tag :tag => 'span', :content => 'This is ' + plugin2_local_variable + ' speaking!', :attributes => {:id => 'plugin2'} | |
457 | + assert_tag :tag => 'span', :content => 'This is Plugin1 speaking!', :attributes => {:id => 'plugin1'} | |
458 | + assert_tag :tag => 'span', :content => 'This is Plugin2 speaking!', :attributes => {:id => 'plugin2'} | |
458 | 459 | end |
459 | 460 | |
460 | 461 | should 'not allow product creation for profiles that can\'t do it' do | ... | ... |
test/functional/profile_editor_controller_test.rb
... | ... | @@ -864,30 +864,34 @@ class ProfileEditorControllerTest < ActionController::TestCase |
864 | 864 | end |
865 | 865 | |
866 | 866 | should 'display plugins buttons on the control panel' do |
867 | - plugin1_button = {:title => "Plugin1 button", :icon => 'plugin1_icon', :url => 'plugin1_url'} | |
868 | - plugin2_button = {:title => "Plugin2 button", :icon => 'plugin2_icon', :url => 'plugin2_url'} | |
869 | - buttons = [plugin1_button, plugin2_button] | |
870 | - plugins = mock() | |
871 | - plugins.stubs(:map).with(:control_panel_buttons).returns(buttons) | |
872 | - plugins.stubs(:enabled_plugins).returns([]) | |
873 | - plugins.stubs(:map).with(:body_beginning).returns([]) | |
874 | - plugins.stubs(:map).with(:head_ending).returns([]) | |
875 | - Noosfero::Plugin::Manager.stubs(:new).returns(plugins) | |
867 | + | |
868 | + class TestControlPanelButtons1 < Noosfero::Plugin | |
869 | + def control_panel_buttons | |
870 | + {:title => "Plugin1 button", :icon => 'plugin1_icon', :url => 'plugin1_url'} | |
871 | + end | |
872 | + end | |
873 | + class TestControlPanelButtons2 < Noosfero::Plugin | |
874 | + def control_panel_buttons | |
875 | + {:title => "Plugin2 button", :icon => 'plugin2_icon', :url => 'plugin2_url'} | |
876 | + end | |
877 | + end | |
878 | + | |
879 | + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestControlPanelButtons1.new, TestControlPanelButtons2.new]) | |
876 | 880 | |
877 | 881 | get :index, :profile => profile.identifier |
878 | 882 | |
879 | - assert_tag :tag => 'a', :content => plugin1_button[:title], :attributes => {:class => /#{plugin1_button[:icon]}/, :href => /#{plugin1_button[:url]}/} | |
880 | - assert_tag :tag => 'a', :content => plugin2_button[:title], :attributes => {:class => /#{plugin2_button[:icon]}/, :href => /#{plugin2_button[:url]}/} | |
883 | + assert_tag :tag => 'a', :content => 'Plugin1 button', :attributes => {:class => /plugin1_icon/, :href => /plugin1_url/} | |
884 | + assert_tag :tag => 'a', :content => 'Plugin2 button', :attributes => {:class => /plugin2_icon/, :href => /plugin2_url/} | |
881 | 885 | end |
882 | 886 | |
883 | 887 | should 'add extra content provided by plugins on edit' do |
884 | - plugin1_content = "<input id='field_added_by_plugin' value='value_of_field_added_by_plugin'/>" | |
885 | - plugins = mock() | |
886 | - plugins.stubs(:enabled_plugins).returns([]) | |
887 | - plugins.stubs(:map).with(:profile_editor_extras).returns([plugin1_content]) | |
888 | - plugins.stubs(:map).with(:head_ending).returns([]) | |
889 | - plugins.stubs(:map).with(:body_beginning).returns([]) | |
890 | - Noosfero::Plugin::Manager.stubs(:new).returns(plugins) | |
888 | + class TestProfileEditPlugin < Noosfero::Plugin | |
889 | + def profile_editor_extras | |
890 | + "<input id='field_added_by_plugin' value='value_of_field_added_by_plugin'/>" | |
891 | + end | |
892 | + end | |
893 | + | |
894 | + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestProfileEditPlugin.new]) | |
891 | 895 | |
892 | 896 | get :edit, :profile => profile.identifier |
893 | 897 | ... | ... |
test/unit/plugin_manager_test.rb
... | ... | @@ -51,7 +51,7 @@ class PluginManagerTest < ActiveSupport::TestCase |
51 | 51 | p1 = Plugin1.new |
52 | 52 | p2 = Plugin2.new |
53 | 53 | |
54 | - assert_equal [p1.random_event, p2.random_event], manager.map(:random_event) | |
54 | + assert_equal [p1.random_event, p2.random_event], manager.dispatch(:random_event) | |
55 | 55 | end |
56 | 56 | |
57 | 57 | end | ... | ... |