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 | 102 | end |
103 | 103 | |
104 | 104 | def init_noosfero_plugins |
105 | - @plugins = Noosfero::Plugin::Manager.new(self) | |
105 | + @plugins = Noosfero::Plugin::Manager.new(environment, self) | |
106 | 106 | @plugins.each do |plugin| |
107 | 107 | prepend_view_path(plugin.class.view_path) |
108 | 108 | end | ... | ... |
lib/noosfero/plugin/manager.rb
1 | 1 | class Noosfero::Plugin::Manager |
2 | 2 | |
3 | + attr_reader :environment | |
3 | 4 | attr_reader :context |
4 | 5 | |
5 | - def initialize(controller) | |
6 | + def initialize(environment, controller) | |
7 | + @environment = environment | |
6 | 8 | @context = Noosfero::Plugin::Context.new(controller) |
7 | 9 | end |
8 | 10 | |
... | ... | @@ -22,7 +24,7 @@ class Noosfero::Plugin::Manager |
22 | 24 | end |
23 | 25 | |
24 | 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 | 28 | p = plugin.constantize.new |
27 | 29 | p.context = context |
28 | 30 | p | ... | ... |
test/unit/plugin_manager_test.rb
... | ... | @@ -8,9 +8,8 @@ class PluginManagerTest < ActiveSupport::TestCase |
8 | 8 | @controller.stubs(:profile).returns() |
9 | 9 | @controller.stubs(:request).returns() |
10 | 10 | @controller.stubs(:response).returns() |
11 | - @controller.stubs(:environment).returns(@environment) | |
12 | 11 | @controller.stubs(:params).returns() |
13 | - @manager = Noosfero::Plugin::Manager.new(@controller) | |
12 | + @manager = Noosfero::Plugin::Manager.new(@environment, @controller) | |
14 | 13 | end |
15 | 14 | attr_reader :environment |
16 | 15 | attr_reader :manager | ... | ... |