Commit 7e6b77ee21a7fbe9d9c43ce17f07b4a9902fc869
1 parent
cc2e277c
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
Fix box organizer tests
Showing
4 changed files
with
31 additions
and
157 deletions
Show diff stats
app/controllers/box_organizer_controller.rb
| ... | ... | @@ -7,7 +7,7 @@ class BoxOrganizerController < ApplicationController |
| 7 | 7 | end |
| 8 | 8 | |
| 9 | 9 | def move_block |
| 10 | - @block = boxes_holder.blocks.find(params[:id].gsub(/^block-/, '')) | |
| 10 | + @block = params[:id] ? boxes_holder.blocks.find(params[:id].gsub(/^block-/, '')) : nil | |
| 11 | 11 | |
| 12 | 12 | target_position = nil |
| 13 | 13 | |
| ... | ... | @@ -19,7 +19,7 @@ class BoxOrganizerController < ApplicationController |
| 19 | 19 | else |
| 20 | 20 | (params[:target] =~ /end-of-box-([0-9]+)/) |
| 21 | 21 | |
| 22 | - @target_box = boxes_holder.boxes.find($1) | |
| 22 | + @target_box = boxes_holder.boxes.find_by_id($1) | |
| 23 | 23 | end |
| 24 | 24 | |
| 25 | 25 | @block = new_block(params[:type], @target_box) if @block.nil? | ... | ... |
app/controllers/my_profile/profile_design_controller.rb
| ... | ... | @@ -7,6 +7,7 @@ class ProfileDesignController < BoxOrganizerController |
| 7 | 7 | before_filter :protect_fixed_block, :only => [:save, :move_block] |
| 8 | 8 | |
| 9 | 9 | def protect_fixed_block |
| 10 | + return if params[:id].blank? | |
| 10 | 11 | block = boxes_holder.blocks.find(params[:id].gsub(/^block-/, '')) |
| 11 | 12 | if block.present? && block.fixed && !current_person.is_admin? |
| 12 | 13 | render_access_denied | ... | ... |
test/functional/environment_design_controller_test.rb
| ... | ... | @@ -165,14 +165,6 @@ class EnvironmentDesignControllerTest < ActionController::TestCase |
| 165 | 165 | assert_tag :tag => 'a', :attributes => {:href => '/admin'}, :child => {:tag => 'span', :content => "Back to control panel"} |
| 166 | 166 | end |
| 167 | 167 | |
| 168 | - should 'render add a new block functionality' do | |
| 169 | - login_as(create_admin_user(Environment.default)) | |
| 170 | - get :add_block | |
| 171 | - | |
| 172 | - assert_response :success | |
| 173 | - assert_template 'add_block' | |
| 174 | - end | |
| 175 | - | |
| 176 | 168 | should 'a environment block plugin add new blocks for environments' do |
| 177 | 169 | class CustomBlock1 < Block; end; |
| 178 | 170 | |
| ... | ... | @@ -212,7 +204,7 @@ class EnvironmentDesignControllerTest < ActionController::TestCase |
| 212 | 204 | assert !@controller.available_blocks.include?(CustomBlock4) |
| 213 | 205 | end |
| 214 | 206 | |
| 215 | - should 'a block plugin with center position add new blocks only in this position' do | |
| 207 | + should 'a block plugin add new blocks' do | |
| 216 | 208 | class CustomBlock1 < Block; end; |
| 217 | 209 | class CustomBlock2 < Block; end; |
| 218 | 210 | class CustomBlock3 < Block; end; |
| ... | ... | @@ -241,61 +233,10 @@ class EnvironmentDesignControllerTest < ActionController::TestCase |
| 241 | 233 | |
| 242 | 234 | Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestBlockPlugin.new]) |
| 243 | 235 | login_as(create_admin_user(Environment.default)) |
| 244 | - get :add_block | |
| 245 | - | |
| 246 | - assert_response :success | |
| 247 | - assert @controller.instance_variable_get('@center_block_types').include?(CustomBlock1) | |
| 248 | - assert @controller.instance_variable_get('@center_block_types').include?(CustomBlock2) | |
| 249 | - assert @controller.instance_variable_get('@center_block_types').include?(CustomBlock3) | |
| 250 | - assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock4) | |
| 251 | - assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock5) | |
| 252 | - assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock6) | |
| 253 | - assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock7) | |
| 254 | - assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock8) | |
| 255 | - assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock9) | |
| 256 | - end | |
| 257 | - | |
| 258 | - should 'a block plugin with side position add new blocks only in this position' do | |
| 259 | - class CustomBlock1 < Block; end; | |
| 260 | - class CustomBlock2 < Block; end; | |
| 261 | - class CustomBlock3 < Block; end; | |
| 262 | - class CustomBlock4 < Block; end; | |
| 263 | - class CustomBlock5 < Block; end; | |
| 264 | - class CustomBlock6 < Block; end; | |
| 265 | - class CustomBlock7 < Block; end; | |
| 266 | - class CustomBlock8 < Block; end; | |
| 267 | - class CustomBlock9 < Block; end; | |
| 268 | - | |
| 269 | - class TestBlockPlugin < Noosfero::Plugin | |
| 270 | - def self.extra_blocks | |
| 271 | - { | |
| 272 | - CustomBlock1 => {:type => Environment, :position => [1]}, | |
| 273 | - CustomBlock2 => {:type => Environment, :position => 1}, | |
| 274 | - CustomBlock3 => {:type => Environment, :position => '1'}, | |
| 275 | - CustomBlock4 => {:type => Environment, :position => [2]}, | |
| 276 | - CustomBlock5 => {:type => Environment, :position => 2}, | |
| 277 | - CustomBlock6 => {:type => Environment, :position => '2'}, | |
| 278 | - CustomBlock7 => {:type => Environment, :position => [3]}, | |
| 279 | - CustomBlock8 => {:type => Environment, :position => 3}, | |
| 280 | - CustomBlock9 => {:type => Environment, :position => '3'}, | |
| 281 | - } | |
| 282 | - end | |
| 283 | - end | |
| 284 | - | |
| 285 | - Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestBlockPlugin.new]) | |
| 286 | - login_as(create_admin_user(Environment.default)) | |
| 287 | - get :add_block | |
| 236 | + get :index | |
| 288 | 237 | assert_response :success |
| 289 | 238 | |
| 290 | - assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock1) | |
| 291 | - assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock2) | |
| 292 | - assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock3) | |
| 293 | - assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock4) | |
| 294 | - assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock5) | |
| 295 | - assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock6) | |
| 296 | - assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock7) | |
| 297 | - assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock8) | |
| 298 | - assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock9) | |
| 239 | + (1..9).each {|i| assert_tag :tag => 'div', :attributes => { 'data-block-type' => "EnvironmentDesignControllerTest::CustomBlock#{i}" }} | |
| 299 | 240 | end |
| 300 | 241 | |
| 301 | 242 | should 'a block plugin cannot be listed for unspecified types' do |
| ... | ... | @@ -325,17 +266,11 @@ class EnvironmentDesignControllerTest < ActionController::TestCase |
| 325 | 266 | |
| 326 | 267 | Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestBlockPlugin.new]) |
| 327 | 268 | login_as(create_admin_user(Environment.default)) |
| 328 | - get :add_block | |
| 269 | + get :index | |
| 329 | 270 | assert_response :success |
| 330 | 271 | |
| 331 | - assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock1) | |
| 332 | - assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock2) | |
| 333 | - assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock3) | |
| 334 | - assert @controller.instance_variable_get('@center_block_types').include?(CustomBlock4) | |
| 335 | - assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock5) | |
| 336 | - assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock6) | |
| 337 | - assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock7) | |
| 338 | - assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock8) | |
| 272 | + [4, 8].each {|i| assert_tag :tag => 'div', :attributes => { 'data-block-type' => "EnvironmentDesignControllerTest::CustomBlock#{i}" }} | |
| 273 | + [1, 2, 3, 5, 6, 7].each {|i| assert_no_tag :tag => 'div', :attributes => { 'data-block-type' => "EnvironmentDesignControllerTest::CustomBlock#{i}" }} | |
| 339 | 274 | end |
| 340 | 275 | |
| 341 | 276 | should 'clone a block' do | ... | ... |
test/functional/profile_design_controller_test.rb
| ... | ... | @@ -169,7 +169,7 @@ class ProfileDesignControllerTest < ActionController::TestCase |
| 169 | 169 | end |
| 170 | 170 | end |
| 171 | 171 | |
| 172 | - should 'a block plugin with center position add new blocks only in this position' do | |
| 172 | + should 'a block plugin add new blocks' do | |
| 173 | 173 | class CustomBlock1 < Block; end; |
| 174 | 174 | class CustomBlock2 < Block; end; |
| 175 | 175 | class CustomBlock3 < Block; end; |
| ... | ... | @@ -197,60 +197,10 @@ class ProfileDesignControllerTest < ActionController::TestCase |
| 197 | 197 | end |
| 198 | 198 | |
| 199 | 199 | Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestBlockPlugin.new]) |
| 200 | - get :add_block, :profile => 'designtestuser' | |
| 201 | - assert_response :success | |
| 202 | - | |
| 203 | - assert @controller.instance_variable_get('@center_block_types').include?(CustomBlock1) | |
| 204 | - assert @controller.instance_variable_get('@center_block_types').include?(CustomBlock2) | |
| 205 | - assert @controller.instance_variable_get('@center_block_types').include?(CustomBlock3) | |
| 206 | - assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock4) | |
| 207 | - assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock5) | |
| 208 | - assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock6) | |
| 209 | - assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock7) | |
| 210 | - assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock8) | |
| 211 | - assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock9) | |
| 212 | - end | |
| 213 | - | |
| 214 | - should 'a block plugin with side position add new blocks only in this position' do | |
| 215 | - class CustomBlock1 < Block; end; | |
| 216 | - class CustomBlock2 < Block; end; | |
| 217 | - class CustomBlock3 < Block; end; | |
| 218 | - class CustomBlock4 < Block; end; | |
| 219 | - class CustomBlock5 < Block; end; | |
| 220 | - class CustomBlock6 < Block; end; | |
| 221 | - class CustomBlock7 < Block; end; | |
| 222 | - class CustomBlock8 < Block; end; | |
| 223 | - class CustomBlock9 < Block; end; | |
| 224 | - | |
| 225 | - class TestBlockPlugin < Noosfero::Plugin | |
| 226 | - def self.extra_blocks | |
| 227 | - { | |
| 228 | - CustomBlock1 => {:type => Person, :position => [1]}, | |
| 229 | - CustomBlock2 => {:type => Person, :position => 1}, | |
| 230 | - CustomBlock3 => {:type => Person, :position => '1'}, | |
| 231 | - CustomBlock4 => {:type => Person, :position => [2]}, | |
| 232 | - CustomBlock5 => {:type => Person, :position => 2}, | |
| 233 | - CustomBlock6 => {:type => Person, :position => '2'}, | |
| 234 | - CustomBlock7 => {:type => Person, :position => [3]}, | |
| 235 | - CustomBlock8 => {:type => Person, :position => 3}, | |
| 236 | - CustomBlock9 => {:type => Person, :position => '3'}, | |
| 237 | - } | |
| 238 | - end | |
| 239 | - end | |
| 240 | - | |
| 241 | - Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestBlockPlugin.new]) | |
| 242 | - get :add_block, :profile => 'designtestuser' | |
| 200 | + get :index, :profile => 'designtestuser' | |
| 243 | 201 | assert_response :success |
| 244 | 202 | |
| 245 | - assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock1) | |
| 246 | - assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock2) | |
| 247 | - assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock3) | |
| 248 | - assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock4) | |
| 249 | - assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock5) | |
| 250 | - assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock6) | |
| 251 | - assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock7) | |
| 252 | - assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock8) | |
| 253 | - assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock9) | |
| 203 | + (1..9).each {|i| assert_tag :tag => 'div', :attributes => { 'data-block-type' => "ProfileDesignControllerTest::CustomBlock#{i}" } } | |
| 254 | 204 | end |
| 255 | 205 | |
| 256 | 206 | should 'a block plugin cannot be listed for unspecified types' do |
| ... | ... | @@ -279,17 +229,11 @@ class ProfileDesignControllerTest < ActionController::TestCase |
| 279 | 229 | end |
| 280 | 230 | |
| 281 | 231 | Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestBlockPlugin.new]) |
| 282 | - get :add_block, :profile => 'designtestuser' | |
| 232 | + get :index, :profile => 'designtestuser' | |
| 283 | 233 | assert_response :success |
| 284 | 234 | |
| 285 | - assert @controller.instance_variable_get('@center_block_types').include?(CustomBlock1) | |
| 286 | - assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock2) | |
| 287 | - assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock3) | |
| 288 | - assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock4) | |
| 289 | - assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock5) | |
| 290 | - assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock6) | |
| 291 | - assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock7) | |
| 292 | - assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock8) | |
| 235 | + [1, 5].each {|i| assert_tag :tag => 'div', :attributes => { 'data-block-type' => "ProfileDesignControllerTest::CustomBlock#{i}" }} | |
| 236 | + [2, 3, 4, 6, 7, 8].each {|i| assert_no_tag :tag => 'div', :attributes => { 'data-block-type' => "ProfileDesignControllerTest::CustomBlock#{i}" }} | |
| 293 | 237 | end |
| 294 | 238 | |
| 295 | 239 | should 'not edit main block with never option' do |
| ... | ... | @@ -339,15 +283,9 @@ class ProfileDesignControllerTest < ActionController::TestCase |
| 339 | 283 | # BEGIN - tests for ProfileDesignController features |
| 340 | 284 | ###################################################### |
| 341 | 285 | |
| 342 | - should 'display popup for adding a new block' do | |
| 343 | - get :add_block, :profile => 'designtestuser' | |
| 344 | - assert_response :success | |
| 345 | - assert_no_tag :tag => 'body' # e.g. no layout | |
| 346 | - end | |
| 347 | - | |
| 348 | 286 | should 'actually add a new block' do |
| 349 | 287 | assert_difference 'Block.count' do |
| 350 | - post :add_block, :profile => 'designtestuser', :box_id => @box1.id, :type => RecentDocumentsBlock.name | |
| 288 | + post :move_block, :profile => 'designtestuser', :target => "end-of-box-#{@box1.id}", :type => RecentDocumentsBlock.name | |
| 351 | 289 | assert_redirected_to :action => 'index' |
| 352 | 290 | end |
| 353 | 291 | end |
| ... | ... | @@ -355,7 +293,7 @@ class ProfileDesignControllerTest < ActionController::TestCase |
| 355 | 293 | should 'not allow to create unknown types' do |
| 356 | 294 | assert_no_difference 'Block.count' do |
| 357 | 295 | assert_raise ArgumentError do |
| 358 | - post :add_block, :profile => 'designtestuser', :box_id => @box1.id, :type => "PleaseLetMeCrackYourSite" | |
| 296 | + post :move_block, :profile => 'designtestuser', :box_id => @box1.id, :type => "PleaseLetMeCrackYourSite" | |
| 359 | 297 | end |
| 360 | 298 | end |
| 361 | 299 | end |
| ... | ... | @@ -432,9 +370,9 @@ class ProfileDesignControllerTest < ActionController::TestCase |
| 432 | 370 | person = create_user_with_permission('test_user', 'edit_profile_design', ent) |
| 433 | 371 | login_as(person.user.login) |
| 434 | 372 | |
| 435 | - get :add_block, :profile => 'test_ent' | |
| 373 | + get :index, :profile => 'test_ent' | |
| 436 | 374 | |
| 437 | - assert_no_tag :tag => 'input', :attributes => {:type => 'radio', :value => 'ProductsBlock'} | |
| 375 | + assert_no_tag :tag => 'div', :attributes => { 'data-block-type' => 'ProductsBlock' } | |
| 438 | 376 | end |
| 439 | 377 | |
| 440 | 378 | should 'create back link to profile control panel' do |
| ... | ... | @@ -448,18 +386,18 @@ class ProfileDesignControllerTest < ActionController::TestCase |
| 448 | 386 | |
| 449 | 387 | should 'offer to create blog archives block only if has blog' do |
| 450 | 388 | holder.articles << Blog.new(:name => 'Blog test', :profile => holder) |
| 451 | - get :add_block, :profile => 'designtestuser' | |
| 452 | - assert_tag :tag => 'input', :attributes => { :name => 'type', :value => 'BlogArchivesBlock' } | |
| 389 | + get :index, :profile => 'designtestuser' | |
| 390 | + assert_tag :tag => 'div', :attributes => { 'data-block-type' => 'BlogArchivesBlock' } | |
| 453 | 391 | end |
| 454 | 392 | |
| 455 | 393 | should 'not offer to create blog archives block if user dont have blog' do |
| 456 | - get :add_block, :profile => 'designtestuser' | |
| 457 | - assert_no_tag :tag => 'input', :attributes => { :name => 'type', :value => 'BlogArchivesBlock' } | |
| 394 | + get :index, :profile => 'designtestuser' | |
| 395 | + assert_no_tag :tag => 'div', :attributes => { 'data-block-type' => 'BlogArchivesBlock' } | |
| 458 | 396 | end |
| 459 | 397 | |
| 460 | 398 | should 'offer to create feed reader block' do |
| 461 | - get :add_block, :profile => 'designtestuser' | |
| 462 | - assert_tag :tag => 'input', :attributes => { :name => 'type', :value => 'FeedReaderBlock' } | |
| 399 | + get :index, :profile => 'designtestuser' | |
| 400 | + assert_tag :tag => 'div', :attributes => { 'data-block-type' => 'FeedReaderBlock' } | |
| 463 | 401 | end |
| 464 | 402 | |
| 465 | 403 | should 'be able to edit FeedReaderBlock' do |
| ... | ... | @@ -569,17 +507,17 @@ class ProfileDesignControllerTest < ActionController::TestCase |
| 569 | 507 | end |
| 570 | 508 | |
| 571 | 509 | should 'allow admins to add RawHTMLBlock' do |
| 572 | - profile.stubs(:is_admin?).with(profile.environment).returns(true) | |
| 510 | + profile.stubs(:is_admin?).returns(true) | |
| 573 | 511 | @controller.stubs(:user).returns(profile) |
| 574 | - get :add_block, :profile => 'designtestuser' | |
| 575 | - assert_tag :tag => 'input', :attributes => { :name => 'type', :value => 'RawHTMLBlock' } | |
| 512 | + get :index, :profile => 'designtestuser' | |
| 513 | + assert_tag :tag => 'div', :attributes => { 'data-block-type' => 'RawHTMLBlock' } | |
| 576 | 514 | end |
| 577 | 515 | |
| 578 | 516 | should 'not allow normal users to add RawHTMLBlock' do |
| 579 | - profile.stubs(:is_admin?).with(profile.environment).returns(false) | |
| 517 | + profile.stubs(:is_admin?).returns(false) | |
| 580 | 518 | @controller.stubs(:user).returns(profile) |
| 581 | - get :add_block, :profile => 'designtestuser' | |
| 582 | - assert_no_tag :tag => 'input', :attributes => { :name => 'type', :value => 'RawHTMLBlock' } | |
| 519 | + get :index, :profile => 'designtestuser' | |
| 520 | + assert_no_tag :tag => 'div', :attributes => { 'data-block-type' => 'RawHTMLBlock' } | |
| 583 | 521 | end |
| 584 | 522 | |
| 585 | 523 | should 'editing article block displays right selected article' do | ... | ... |