Commit bf559b5fee8f679ed2038bbc339339f4f5c56c53
1 parent
7ccc0c5b
Exists in
master
and in
29 other branches
box: pass holder class as type for extra blocks hotspot
(ActionItem2958)
Showing
2 changed files
with
22 additions
and
1 deletions
Show diff stats
app/models/box.rb
... | ... | @@ -10,7 +10,7 @@ class Box < ActiveRecord::Base |
10 | 10 | end |
11 | 11 | |
12 | 12 | def acceptable_blocks |
13 | - blocks_classes = central? ? Box.acceptable_center_blocks + plugins.dispatch(:extra_blocks, :position => 1) : Box.acceptable_side_blocks + plugins.dispatch(:extra_blocks, :position => [2, 3]) | |
13 | + blocks_classes = central? ? Box.acceptable_center_blocks + plugins.dispatch(:extra_blocks, :type => owner.class, :position => 1) : Box.acceptable_side_blocks + plugins.dispatch(:extra_blocks, :type => owner.class, :position => [2, 3]) | |
14 | 14 | to_css_class_name(blocks_classes) |
15 | 15 | end |
16 | 16 | ... | ... |
test/unit/box_test.rb
... | ... | @@ -119,4 +119,25 @@ class BoxTest < ActiveSupport::TestCase |
119 | 119 | assert blocks.include?('box-test_plugin-block') |
120 | 120 | end |
121 | 121 | |
122 | + should 'list plugin block as allowed for the right holder' do | |
123 | + class SomePlugin < Noosfero::Plugin | |
124 | + def self.extra_blocks | |
125 | + { PluginBlock => {:position => 1, :type => [Person, Enterprise]} } | |
126 | + end | |
127 | + end | |
128 | + class PluginBlock < Block | |
129 | + def self.to_s; 'plugin-block'; end | |
130 | + end | |
131 | + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([SomePlugin.new]) | |
132 | + | |
133 | + blocks = Box.new(:position => 1, :owner => Person.new).acceptable_blocks | |
134 | + assert blocks.include?('box-test_plugin-block') | |
135 | + | |
136 | + blocks = Box.new(:position => 1, :owner => Enterprise.new).acceptable_blocks | |
137 | + assert blocks.include?('box-test_plugin-block') | |
138 | + | |
139 | + blocks = Box.new(:position => 1, :owner => Community.new).acceptable_blocks | |
140 | + assert !blocks.include?('box-test_plugin-block') | |
141 | + end | |
142 | + | |
122 | 143 | end | ... | ... |