Commit 1cf42fc1b5ae7b8b152e8f856c31bae624fe08ec
1 parent
e60b2450
Exists in
master
and in
29 other branches
Require environment to instantiate plugin manager
This a way the controller is optional, because all data needed to obtain the list of plugins to be instantiated comes from the environment.
Showing
3 changed files
with
6 additions
and
5 deletions
Show diff stats
app/controllers/application_controller.rb
@@ -102,7 +102,7 @@ class ApplicationController < ActionController::Base | @@ -102,7 +102,7 @@ class ApplicationController < ActionController::Base | ||
102 | end | 102 | end |
103 | 103 | ||
104 | def init_noosfero_plugins | 104 | def init_noosfero_plugins |
105 | - @plugins = Noosfero::Plugin::Manager.new(self) | 105 | + @plugins = Noosfero::Plugin::Manager.new(environment, self) |
106 | @plugins.each do |plugin| | 106 | @plugins.each do |plugin| |
107 | prepend_view_path(plugin.class.view_path) | 107 | prepend_view_path(plugin.class.view_path) |
108 | end | 108 | end |
lib/noosfero/plugin/manager.rb
1 | class Noosfero::Plugin::Manager | 1 | class Noosfero::Plugin::Manager |
2 | 2 | ||
3 | + attr_reader :environment | ||
3 | attr_reader :context | 4 | attr_reader :context |
4 | 5 | ||
5 | - def initialize(controller) | 6 | + def initialize(environment, controller) |
7 | + @environment = environment | ||
6 | @context = Noosfero::Plugin::Context.new(controller) | 8 | @context = Noosfero::Plugin::Context.new(controller) |
7 | end | 9 | end |
8 | 10 | ||
@@ -22,7 +24,7 @@ class Noosfero::Plugin::Manager | @@ -22,7 +24,7 @@ class Noosfero::Plugin::Manager | ||
22 | end | 24 | end |
23 | 25 | ||
24 | def enabled_plugins | 26 | def enabled_plugins |
25 | - @enabled_plugins ||= (Noosfero::Plugin.all & context.environment.enabled_plugins).map do |plugin| | 27 | + @enabled_plugins ||= (Noosfero::Plugin.all & environment.enabled_plugins).map do |plugin| |
26 | p = plugin.constantize.new | 28 | p = plugin.constantize.new |
27 | p.context = context | 29 | p.context = context |
28 | p | 30 | p |
test/unit/plugin_manager_test.rb
@@ -8,9 +8,8 @@ class PluginManagerTest < ActiveSupport::TestCase | @@ -8,9 +8,8 @@ class PluginManagerTest < ActiveSupport::TestCase | ||
8 | @controller.stubs(:profile).returns() | 8 | @controller.stubs(:profile).returns() |
9 | @controller.stubs(:request).returns() | 9 | @controller.stubs(:request).returns() |
10 | @controller.stubs(:response).returns() | 10 | @controller.stubs(:response).returns() |
11 | - @controller.stubs(:environment).returns(@environment) | ||
12 | @controller.stubs(:params).returns() | 11 | @controller.stubs(:params).returns() |
13 | - @manager = Noosfero::Plugin::Manager.new(@controller) | 12 | + @manager = Noosfero::Plugin::Manager.new(@environment, @controller) |
14 | end | 13 | end |
15 | attr_reader :environment | 14 | attr_reader :environment |
16 | attr_reader :manager | 15 | attr_reader :manager |