Commit c9f4c639e9c21b4440281364e0e8b1d9cd556b68
1 parent
096a8402
Exists in
master
and in
29 other branches
Show block plugins for specified types only
Showing
3 changed files
with
110 additions
and
33 deletions
Show diff stats
app/controllers/box_organizer_controller.rb
@@ -68,8 +68,8 @@ class BoxOrganizerController < ApplicationController | @@ -68,8 +68,8 @@ class BoxOrganizerController < ApplicationController | ||
68 | raise ArgumentError.new("Type %s is not allowed. Go away." % type) | 68 | raise ArgumentError.new("Type %s is not allowed. Go away." % type) |
69 | end | 69 | end |
70 | else | 70 | else |
71 | - @center_block_types = (Box.acceptable_center_blocks & available_blocks) + plugins.dispatch(:extra_blocks, :type => :all, :position => 1) | ||
72 | - @side_block_types = (Box.acceptable_side_blocks & available_blocks) + plugins.dispatch(:extra_blocks, :type => :all, :position => [2,3]) | 71 | + @center_block_types = (Box.acceptable_center_blocks & available_blocks) + plugins.dispatch(:extra_blocks, :type => boxes_holder.class, :position => 1) |
72 | + @side_block_types = (Box.acceptable_side_blocks & available_blocks) + plugins.dispatch(:extra_blocks, :type => boxes_holder.class, :position => [2,3]) | ||
73 | @boxes = boxes_holder.boxes | 73 | @boxes = boxes_holder.boxes |
74 | render :action => 'add_block', :layout => false | 74 | render :action => 'add_block', :layout => false |
75 | end | 75 | end |
test/functional/environment_design_controller_test.rb
@@ -247,15 +247,15 @@ class EnvironmentDesignControllerTest < ActionController::TestCase | @@ -247,15 +247,15 @@ class EnvironmentDesignControllerTest < ActionController::TestCase | ||
247 | class TestBlockPlugin < Noosfero::Plugin | 247 | class TestBlockPlugin < Noosfero::Plugin |
248 | def self.extra_blocks | 248 | def self.extra_blocks |
249 | { | 249 | { |
250 | - CustomBlock1 => {:type => Person, :position => [1]}, | ||
251 | - CustomBlock2 => {:type => Enterprise, :position => 1}, | ||
252 | - CustomBlock3 => {:type => Community, :position => '1'}, | ||
253 | - CustomBlock4 => {:type => Person, :position => [2]}, | ||
254 | - CustomBlock5 => {:type => Enterprise, :position => 2}, | ||
255 | - CustomBlock6 => {:type => Community, :position => '2'}, | ||
256 | - CustomBlock7 => {:type => Person, :position => [3]}, | ||
257 | - CustomBlock8 => {:type => Enterprise, :position => 3}, | ||
258 | - CustomBlock9 => {:type => Community, :position => '3'}, | 250 | + CustomBlock1 => {:type => Environment, :position => [1]}, |
251 | + CustomBlock2 => {:type => Environment, :position => 1}, | ||
252 | + CustomBlock3 => {:type => Environment, :position => '1'}, | ||
253 | + CustomBlock4 => {:type => Environment, :position => [2]}, | ||
254 | + CustomBlock5 => {:type => Environment, :position => 2}, | ||
255 | + CustomBlock6 => {:type => Environment, :position => '2'}, | ||
256 | + CustomBlock7 => {:type => Environment, :position => [3]}, | ||
257 | + CustomBlock8 => {:type => Environment, :position => 3}, | ||
258 | + CustomBlock9 => {:type => Environment, :position => '3'}, | ||
259 | } | 259 | } |
260 | end | 260 | end |
261 | end | 261 | end |
@@ -265,7 +265,6 @@ class EnvironmentDesignControllerTest < ActionController::TestCase | @@ -265,7 +265,6 @@ class EnvironmentDesignControllerTest < ActionController::TestCase | ||
265 | get :add_block | 265 | get :add_block |
266 | 266 | ||
267 | assert_response :success | 267 | assert_response :success |
268 | - | ||
269 | assert @controller.instance_variable_get('@center_block_types').include?(CustomBlock1) | 268 | assert @controller.instance_variable_get('@center_block_types').include?(CustomBlock1) |
270 | assert @controller.instance_variable_get('@center_block_types').include?(CustomBlock2) | 269 | assert @controller.instance_variable_get('@center_block_types').include?(CustomBlock2) |
271 | assert @controller.instance_variable_get('@center_block_types').include?(CustomBlock3) | 270 | assert @controller.instance_variable_get('@center_block_types').include?(CustomBlock3) |
@@ -291,15 +290,15 @@ class EnvironmentDesignControllerTest < ActionController::TestCase | @@ -291,15 +290,15 @@ class EnvironmentDesignControllerTest < ActionController::TestCase | ||
291 | class TestBlockPlugin < Noosfero::Plugin | 290 | class TestBlockPlugin < Noosfero::Plugin |
292 | def self.extra_blocks | 291 | def self.extra_blocks |
293 | { | 292 | { |
294 | - CustomBlock1 => {:type => Person, :position => [1]}, | ||
295 | - CustomBlock2 => {:type => Enterprise, :position => 1}, | ||
296 | - CustomBlock3 => {:type => Community, :position => '1'}, | ||
297 | - CustomBlock4 => {:type => Person, :position => [2]}, | ||
298 | - CustomBlock5 => {:type => Enterprise, :position => 2}, | ||
299 | - CustomBlock6 => {:type => Community, :position => '2'}, | ||
300 | - CustomBlock7 => {:type => Person, :position => [3]}, | ||
301 | - CustomBlock8 => {:type => Enterprise, :position => 3}, | ||
302 | - CustomBlock9 => {:type => Community, :position => '3'}, | 293 | + CustomBlock1 => {:type => Environment, :position => [1]}, |
294 | + CustomBlock2 => {:type => Environment, :position => 1}, | ||
295 | + CustomBlock3 => {:type => Environment, :position => '1'}, | ||
296 | + CustomBlock4 => {:type => Environment, :position => [2]}, | ||
297 | + CustomBlock5 => {:type => Environment, :position => 2}, | ||
298 | + CustomBlock6 => {:type => Environment, :position => '2'}, | ||
299 | + CustomBlock7 => {:type => Environment, :position => [3]}, | ||
300 | + CustomBlock8 => {:type => Environment, :position => 3}, | ||
301 | + CustomBlock9 => {:type => Environment, :position => '3'}, | ||
303 | } | 302 | } |
304 | end | 303 | end |
305 | end | 304 | end |
@@ -320,4 +319,44 @@ class EnvironmentDesignControllerTest < ActionController::TestCase | @@ -320,4 +319,44 @@ class EnvironmentDesignControllerTest < ActionController::TestCase | ||
320 | assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock9) | 319 | assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock9) |
321 | end | 320 | end |
322 | 321 | ||
322 | + should 'a block plugin cannot be listed for unspecified types' do | ||
323 | + class CustomBlock1 < Block; end; | ||
324 | + class CustomBlock2 < Block; end; | ||
325 | + class CustomBlock3 < Block; end; | ||
326 | + class CustomBlock4 < Block; end; | ||
327 | + class CustomBlock5 < Block; end; | ||
328 | + class CustomBlock6 < Block; end; | ||
329 | + class CustomBlock7 < Block; end; | ||
330 | + class CustomBlock8 < Block; end; | ||
331 | + | ||
332 | + class TestBlockPlugin < Noosfero::Plugin | ||
333 | + def self.extra_blocks | ||
334 | + { | ||
335 | + CustomBlock1 => {:type => Person, :position => 1}, | ||
336 | + CustomBlock2 => {:type => Community, :position => 1}, | ||
337 | + CustomBlock3 => {:type => Enterprise, :position => 1}, | ||
338 | + CustomBlock4 => {:type => Environment, :position => 1}, | ||
339 | + CustomBlock5 => {:type => Person, :position => 2}, | ||
340 | + CustomBlock6 => {:type => Community, :position => 3}, | ||
341 | + CustomBlock7 => {:type => Enterprise, :position => 2}, | ||
342 | + CustomBlock8 => {:type => Environment, :position => 3}, | ||
343 | + } | ||
344 | + end | ||
345 | + end | ||
346 | + | ||
347 | + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestBlockPlugin.new]) | ||
348 | + login_as(create_admin_user(Environment.default)) | ||
349 | + get :add_block | ||
350 | + assert_response :success | ||
351 | + | ||
352 | + assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock1) | ||
353 | + assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock2) | ||
354 | + assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock3) | ||
355 | + assert @controller.instance_variable_get('@center_block_types').include?(CustomBlock4) | ||
356 | + assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock5) | ||
357 | + assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock6) | ||
358 | + assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock7) | ||
359 | + assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock8) | ||
360 | + end | ||
361 | + | ||
323 | end | 362 | end |
test/functional/profile_design_controller_test.rb
@@ -192,14 +192,14 @@ class ProfileDesignControllerTest < ActionController::TestCase | @@ -192,14 +192,14 @@ class ProfileDesignControllerTest < ActionController::TestCase | ||
192 | def self.extra_blocks | 192 | def self.extra_blocks |
193 | { | 193 | { |
194 | CustomBlock1 => {:type => Person, :position => [1]}, | 194 | CustomBlock1 => {:type => Person, :position => [1]}, |
195 | - CustomBlock2 => {:type => Enterprise, :position => 1}, | ||
196 | - CustomBlock3 => {:type => Community, :position => '1'}, | 195 | + CustomBlock2 => {:type => Person, :position => 1}, |
196 | + CustomBlock3 => {:type => Person, :position => '1'}, | ||
197 | CustomBlock4 => {:type => Person, :position => [2]}, | 197 | CustomBlock4 => {:type => Person, :position => [2]}, |
198 | - CustomBlock5 => {:type => Enterprise, :position => 2}, | ||
199 | - CustomBlock6 => {:type => Community, :position => '2'}, | 198 | + CustomBlock5 => {:type => Person, :position => 2}, |
199 | + CustomBlock6 => {:type => Person, :position => '2'}, | ||
200 | CustomBlock7 => {:type => Person, :position => [3]}, | 200 | CustomBlock7 => {:type => Person, :position => [3]}, |
201 | - CustomBlock8 => {:type => Enterprise, :position => 3}, | ||
202 | - CustomBlock9 => {:type => Community, :position => '3'}, | 201 | + CustomBlock8 => {:type => Person, :position => 3}, |
202 | + CustomBlock9 => {:type => Person, :position => '3'}, | ||
203 | } | 203 | } |
204 | end | 204 | end |
205 | end | 205 | end |
@@ -234,14 +234,14 @@ class ProfileDesignControllerTest < ActionController::TestCase | @@ -234,14 +234,14 @@ class ProfileDesignControllerTest < ActionController::TestCase | ||
234 | def self.extra_blocks | 234 | def self.extra_blocks |
235 | { | 235 | { |
236 | CustomBlock1 => {:type => Person, :position => [1]}, | 236 | CustomBlock1 => {:type => Person, :position => [1]}, |
237 | - CustomBlock2 => {:type => Enterprise, :position => 1}, | ||
238 | - CustomBlock3 => {:type => Community, :position => '1'}, | 237 | + CustomBlock2 => {:type => Person, :position => 1}, |
238 | + CustomBlock3 => {:type => Person, :position => '1'}, | ||
239 | CustomBlock4 => {:type => Person, :position => [2]}, | 239 | CustomBlock4 => {:type => Person, :position => [2]}, |
240 | - CustomBlock5 => {:type => Enterprise, :position => 2}, | ||
241 | - CustomBlock6 => {:type => Community, :position => '2'}, | 240 | + CustomBlock5 => {:type => Person, :position => 2}, |
241 | + CustomBlock6 => {:type => Person, :position => '2'}, | ||
242 | CustomBlock7 => {:type => Person, :position => [3]}, | 242 | CustomBlock7 => {:type => Person, :position => [3]}, |
243 | - CustomBlock8 => {:type => Enterprise, :position => 3}, | ||
244 | - CustomBlock9 => {:type => Community, :position => '3'}, | 243 | + CustomBlock8 => {:type => Person, :position => 3}, |
244 | + CustomBlock9 => {:type => Person, :position => '3'}, | ||
245 | } | 245 | } |
246 | end | 246 | end |
247 | end | 247 | end |
@@ -261,6 +261,44 @@ class ProfileDesignControllerTest < ActionController::TestCase | @@ -261,6 +261,44 @@ class ProfileDesignControllerTest < ActionController::TestCase | ||
261 | assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock9) | 261 | assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock9) |
262 | end | 262 | end |
263 | 263 | ||
264 | + should 'a block plugin cannot be listed for unspecified types' do | ||
265 | + class CustomBlock1 < Block; end; | ||
266 | + class CustomBlock2 < Block; end; | ||
267 | + class CustomBlock3 < Block; end; | ||
268 | + class CustomBlock4 < Block; end; | ||
269 | + class CustomBlock5 < Block; end; | ||
270 | + class CustomBlock6 < Block; end; | ||
271 | + class CustomBlock7 < Block; end; | ||
272 | + class CustomBlock8 < Block; end; | ||
273 | + | ||
274 | + class TestBlockPlugin < Noosfero::Plugin | ||
275 | + def self.extra_blocks | ||
276 | + { | ||
277 | + CustomBlock1 => {:type => Person, :position => 1}, | ||
278 | + CustomBlock2 => {:type => Community, :position => 1}, | ||
279 | + CustomBlock3 => {:type => Enterprise, :position => 1}, | ||
280 | + CustomBlock4 => {:type => Environment, :position => 1}, | ||
281 | + CustomBlock5 => {:type => Person, :position => 2}, | ||
282 | + CustomBlock6 => {:type => Community, :position => 3}, | ||
283 | + CustomBlock7 => {:type => Enterprise, :position => 2}, | ||
284 | + CustomBlock8 => {:type => Environment, :position => 3}, | ||
285 | + } | ||
286 | + end | ||
287 | + end | ||
288 | + | ||
289 | + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestBlockPlugin.new]) | ||
290 | + get :add_block, :profile => 'designtestuser' | ||
291 | + assert_response :success | ||
292 | + | ||
293 | + assert @controller.instance_variable_get('@center_block_types').include?(CustomBlock1) | ||
294 | + assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock2) | ||
295 | + assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock3) | ||
296 | + assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock4) | ||
297 | + assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock5) | ||
298 | + assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock6) | ||
299 | + assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock7) | ||
300 | + assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock8) | ||
301 | + end | ||
264 | 302 | ||
265 | ###################################################### | 303 | ###################################################### |
266 | # END - tests for BoxOrganizerController features | 304 | # END - tests for BoxOrganizerController features |