Commit 3c42961da48b8901b92a18ed949b4114ff3880b6
1 parent
6f746463
Exists in
master
and in
29 other branches
Add plugin blocks in acceptable_blocks for boxes
Showing
2 changed files
with
39 additions
and
1 deletions
Show diff stats
app/models/box.rb
... | ... | @@ -3,12 +3,15 @@ class Box < ActiveRecord::Base |
3 | 3 | acts_as_list :scope => 'owner_id = #{owner_id} and owner_type = \'#{owner_type}\'' |
4 | 4 | has_many :blocks, :dependent => :destroy, :order => 'position' |
5 | 5 | |
6 | + include Noosfero::Plugin::HotSpot | |
7 | + | |
6 | 8 | def environment |
7 | 9 | owner ? (owner.kind_of?(Environment) ? owner : owner.environment) : nil |
8 | 10 | end |
9 | 11 | |
10 | 12 | def acceptable_blocks |
11 | - to_css_class_name central? ? Box.acceptable_center_blocks : Box.acceptable_side_blocks | |
13 | + blocks = central? ? Box.acceptable_center_blocks + plugins.dispatch(:extra_blocks, :position => 1) : Box.acceptable_side_blocks + plugins.dispatch(:extra_blocks, :position => [2, 3]) | |
14 | + to_css_class_name(blocks) | |
12 | 15 | end |
13 | 16 | |
14 | 17 | def central? | ... | ... |
test/unit/box_test.rb
1 | 1 | require File.dirname(__FILE__) + '/../test_helper' |
2 | 2 | |
3 | 3 | class BoxTest < ActiveSupport::TestCase |
4 | + | |
5 | + def setup | |
6 | + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([]) | |
7 | + end | |
8 | + | |
4 | 9 | should 'retrieve environment based on owner' do |
5 | 10 | profile = fast_create(Profile) |
6 | 11 | box = fast_create(Box, :owner_id => profile.id, :owner_type => 'Profile') |
... | ... | @@ -84,4 +89,34 @@ class BoxTest < ActiveSupport::TestCase |
84 | 89 | assert blocks.include?('tags-block') |
85 | 90 | end |
86 | 91 | |
92 | + should 'list plugin block as allowed for box at position 1' do | |
93 | + class SomePlugin < Noosfero::Plugin | |
94 | + def self.extra_blocks | |
95 | + { PluginBlock => {:position => 1} } | |
96 | + end | |
97 | + end | |
98 | + class PluginBlock < Block | |
99 | + def self.to_s; 'plugin-block'; end | |
100 | + end | |
101 | + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([SomePlugin.new]) | |
102 | + | |
103 | + blocks = Box.new(:position => 1).acceptable_blocks | |
104 | + assert blocks.include?('plugin-block') | |
105 | + end | |
106 | + | |
107 | + should 'list plugin block as allowed for box at position 2' do | |
108 | + class SomePlugin < Noosfero::Plugin | |
109 | + def self.extra_blocks | |
110 | + { PluginBlock => {:position => 2} } | |
111 | + end | |
112 | + end | |
113 | + class PluginBlock < Block | |
114 | + def self.to_s; 'plugin-block'; end | |
115 | + end | |
116 | + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([SomePlugin.new]) | |
117 | + | |
118 | + blocks = Box.new(:position => 2).acceptable_blocks | |
119 | + assert blocks.include?('plugin-block') | |
120 | + end | |
121 | + | |
87 | 122 | end | ... | ... |