diff --git a/app/controllers/box_organizer_controller.rb b/app/controllers/box_organizer_controller.rb index 73cb0a5..f98bc3a 100644 --- a/app/controllers/box_organizer_controller.rb +++ b/app/controllers/box_organizer_controller.rb @@ -7,7 +7,7 @@ class BoxOrganizerController < ApplicationController end def move_block - @block = boxes_holder.blocks.find(params[:id].gsub(/^block-/, '')) + @block = params[:id] ? boxes_holder.blocks.find(params[:id].gsub(/^block-/, '')) : nil target_position = nil @@ -19,7 +19,7 @@ class BoxOrganizerController < ApplicationController else (params[:target] =~ /end-of-box-([0-9]+)/) - @target_box = boxes_holder.boxes.find($1) + @target_box = boxes_holder.boxes.find_by_id($1) end @block = new_block(params[:type], @target_box) if @block.nil? diff --git a/app/controllers/my_profile/profile_design_controller.rb b/app/controllers/my_profile/profile_design_controller.rb index 37c55e2..09e0602 100644 --- a/app/controllers/my_profile/profile_design_controller.rb +++ b/app/controllers/my_profile/profile_design_controller.rb @@ -7,6 +7,7 @@ class ProfileDesignController < BoxOrganizerController before_filter :protect_fixed_block, :only => [:save, :move_block] def protect_fixed_block + return if params[:id].blank? block = boxes_holder.blocks.find(params[:id].gsub(/^block-/, '')) if block.present? && block.fixed && !current_person.is_admin? render_access_denied diff --git a/test/functional/environment_design_controller_test.rb b/test/functional/environment_design_controller_test.rb index 51dd1c8..ccf6b72 100644 --- a/test/functional/environment_design_controller_test.rb +++ b/test/functional/environment_design_controller_test.rb @@ -165,14 +165,6 @@ class EnvironmentDesignControllerTest < ActionController::TestCase assert_tag :tag => 'a', :attributes => {:href => '/admin'}, :child => {:tag => 'span', :content => "Back to control panel"} end - should 'render add a new block functionality' do - login_as(create_admin_user(Environment.default)) - get :add_block - - assert_response :success - assert_template 'add_block' - end - should 'a environment block plugin add new blocks for environments' do class CustomBlock1 < Block; end; @@ -212,7 +204,7 @@ class EnvironmentDesignControllerTest < ActionController::TestCase assert !@controller.available_blocks.include?(CustomBlock4) end - should 'a block plugin with center position add new blocks only in this position' do + should 'a block plugin add new blocks' do class CustomBlock1 < Block; end; class CustomBlock2 < Block; end; class CustomBlock3 < Block; end; @@ -241,61 +233,10 @@ class EnvironmentDesignControllerTest < ActionController::TestCase Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestBlockPlugin.new]) login_as(create_admin_user(Environment.default)) - get :add_block - - assert_response :success - assert @controller.instance_variable_get('@center_block_types').include?(CustomBlock1) - assert @controller.instance_variable_get('@center_block_types').include?(CustomBlock2) - assert @controller.instance_variable_get('@center_block_types').include?(CustomBlock3) - assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock4) - assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock5) - assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock6) - assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock7) - assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock8) - assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock9) - end - - should 'a block plugin with side position add new blocks only in this position' do - class CustomBlock1 < Block; end; - class CustomBlock2 < Block; end; - class CustomBlock3 < Block; end; - class CustomBlock4 < Block; end; - class CustomBlock5 < Block; end; - class CustomBlock6 < Block; end; - class CustomBlock7 < Block; end; - class CustomBlock8 < Block; end; - class CustomBlock9 < Block; end; - - class TestBlockPlugin < Noosfero::Plugin - def self.extra_blocks - { - CustomBlock1 => {:type => Environment, :position => [1]}, - CustomBlock2 => {:type => Environment, :position => 1}, - CustomBlock3 => {:type => Environment, :position => '1'}, - CustomBlock4 => {:type => Environment, :position => [2]}, - CustomBlock5 => {:type => Environment, :position => 2}, - CustomBlock6 => {:type => Environment, :position => '2'}, - CustomBlock7 => {:type => Environment, :position => [3]}, - CustomBlock8 => {:type => Environment, :position => 3}, - CustomBlock9 => {:type => Environment, :position => '3'}, - } - end - end - - Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestBlockPlugin.new]) - login_as(create_admin_user(Environment.default)) - get :add_block + get :index assert_response :success - assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock1) - assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock2) - assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock3) - assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock4) - assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock5) - assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock6) - assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock7) - assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock8) - assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock9) + (1..9).each {|i| assert_tag :tag => 'div', :attributes => { 'data-block-type' => "EnvironmentDesignControllerTest::CustomBlock#{i}" }} end should 'a block plugin cannot be listed for unspecified types' do @@ -325,17 +266,11 @@ class EnvironmentDesignControllerTest < ActionController::TestCase Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestBlockPlugin.new]) login_as(create_admin_user(Environment.default)) - get :add_block + get :index assert_response :success - assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock1) - assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock2) - assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock3) - assert @controller.instance_variable_get('@center_block_types').include?(CustomBlock4) - assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock5) - assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock6) - assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock7) - assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock8) + [4, 8].each {|i| assert_tag :tag => 'div', :attributes => { 'data-block-type' => "EnvironmentDesignControllerTest::CustomBlock#{i}" }} + [1, 2, 3, 5, 6, 7].each {|i| assert_no_tag :tag => 'div', :attributes => { 'data-block-type' => "EnvironmentDesignControllerTest::CustomBlock#{i}" }} end should 'clone a block' do diff --git a/test/functional/profile_design_controller_test.rb b/test/functional/profile_design_controller_test.rb index b0dde3d..57f0f2b 100644 --- a/test/functional/profile_design_controller_test.rb +++ b/test/functional/profile_design_controller_test.rb @@ -169,7 +169,7 @@ class ProfileDesignControllerTest < ActionController::TestCase end end - should 'a block plugin with center position add new blocks only in this position' do + should 'a block plugin add new blocks' do class CustomBlock1 < Block; end; class CustomBlock2 < Block; end; class CustomBlock3 < Block; end; @@ -197,60 +197,10 @@ class ProfileDesignControllerTest < ActionController::TestCase end Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestBlockPlugin.new]) - get :add_block, :profile => 'designtestuser' - assert_response :success - - assert @controller.instance_variable_get('@center_block_types').include?(CustomBlock1) - assert @controller.instance_variable_get('@center_block_types').include?(CustomBlock2) - assert @controller.instance_variable_get('@center_block_types').include?(CustomBlock3) - assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock4) - assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock5) - assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock6) - assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock7) - assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock8) - assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock9) - end - - should 'a block plugin with side position add new blocks only in this position' do - class CustomBlock1 < Block; end; - class CustomBlock2 < Block; end; - class CustomBlock3 < Block; end; - class CustomBlock4 < Block; end; - class CustomBlock5 < Block; end; - class CustomBlock6 < Block; end; - class CustomBlock7 < Block; end; - class CustomBlock8 < Block; end; - class CustomBlock9 < Block; end; - - class TestBlockPlugin < Noosfero::Plugin - def self.extra_blocks - { - CustomBlock1 => {:type => Person, :position => [1]}, - CustomBlock2 => {:type => Person, :position => 1}, - CustomBlock3 => {:type => Person, :position => '1'}, - CustomBlock4 => {:type => Person, :position => [2]}, - CustomBlock5 => {:type => Person, :position => 2}, - CustomBlock6 => {:type => Person, :position => '2'}, - CustomBlock7 => {:type => Person, :position => [3]}, - CustomBlock8 => {:type => Person, :position => 3}, - CustomBlock9 => {:type => Person, :position => '3'}, - } - end - end - - Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestBlockPlugin.new]) - get :add_block, :profile => 'designtestuser' + get :index, :profile => 'designtestuser' assert_response :success - assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock1) - assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock2) - assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock3) - assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock4) - assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock5) - assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock6) - assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock7) - assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock8) - assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock9) + (1..9).each {|i| assert_tag :tag => 'div', :attributes => { 'data-block-type' => "ProfileDesignControllerTest::CustomBlock#{i}" } } end should 'a block plugin cannot be listed for unspecified types' do @@ -279,17 +229,11 @@ class ProfileDesignControllerTest < ActionController::TestCase end Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestBlockPlugin.new]) - get :add_block, :profile => 'designtestuser' + get :index, :profile => 'designtestuser' assert_response :success - assert @controller.instance_variable_get('@center_block_types').include?(CustomBlock1) - assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock2) - assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock3) - assert !@controller.instance_variable_get('@center_block_types').include?(CustomBlock4) - assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock5) - assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock6) - assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock7) - assert !@controller.instance_variable_get('@side_block_types').include?(CustomBlock8) + [1, 5].each {|i| assert_tag :tag => 'div', :attributes => { 'data-block-type' => "ProfileDesignControllerTest::CustomBlock#{i}" }} + [2, 3, 4, 6, 7, 8].each {|i| assert_no_tag :tag => 'div', :attributes => { 'data-block-type' => "ProfileDesignControllerTest::CustomBlock#{i}" }} end should 'not edit main block with never option' do @@ -339,15 +283,9 @@ class ProfileDesignControllerTest < ActionController::TestCase # BEGIN - tests for ProfileDesignController features ###################################################### - should 'display popup for adding a new block' do - get :add_block, :profile => 'designtestuser' - assert_response :success - assert_no_tag :tag => 'body' # e.g. no layout - end - should 'actually add a new block' do assert_difference 'Block.count' do - post :add_block, :profile => 'designtestuser', :box_id => @box1.id, :type => RecentDocumentsBlock.name + post :move_block, :profile => 'designtestuser', :target => "end-of-box-#{@box1.id}", :type => RecentDocumentsBlock.name assert_redirected_to :action => 'index' end end @@ -355,7 +293,7 @@ class ProfileDesignControllerTest < ActionController::TestCase should 'not allow to create unknown types' do assert_no_difference 'Block.count' do assert_raise ArgumentError do - post :add_block, :profile => 'designtestuser', :box_id => @box1.id, :type => "PleaseLetMeCrackYourSite" + post :move_block, :profile => 'designtestuser', :box_id => @box1.id, :type => "PleaseLetMeCrackYourSite" end end end @@ -432,9 +370,9 @@ class ProfileDesignControllerTest < ActionController::TestCase person = create_user_with_permission('test_user', 'edit_profile_design', ent) login_as(person.user.login) - get :add_block, :profile => 'test_ent' + get :index, :profile => 'test_ent' - assert_no_tag :tag => 'input', :attributes => {:type => 'radio', :value => 'ProductsBlock'} + assert_no_tag :tag => 'div', :attributes => { 'data-block-type' => 'ProductsBlock' } end should 'create back link to profile control panel' do @@ -448,18 +386,18 @@ class ProfileDesignControllerTest < ActionController::TestCase should 'offer to create blog archives block only if has blog' do holder.articles << Blog.new(:name => 'Blog test', :profile => holder) - get :add_block, :profile => 'designtestuser' - assert_tag :tag => 'input', :attributes => { :name => 'type', :value => 'BlogArchivesBlock' } + get :index, :profile => 'designtestuser' + assert_tag :tag => 'div', :attributes => { 'data-block-type' => 'BlogArchivesBlock' } end should 'not offer to create blog archives block if user dont have blog' do - get :add_block, :profile => 'designtestuser' - assert_no_tag :tag => 'input', :attributes => { :name => 'type', :value => 'BlogArchivesBlock' } + get :index, :profile => 'designtestuser' + assert_no_tag :tag => 'div', :attributes => { 'data-block-type' => 'BlogArchivesBlock' } end should 'offer to create feed reader block' do - get :add_block, :profile => 'designtestuser' - assert_tag :tag => 'input', :attributes => { :name => 'type', :value => 'FeedReaderBlock' } + get :index, :profile => 'designtestuser' + assert_tag :tag => 'div', :attributes => { 'data-block-type' => 'FeedReaderBlock' } end should 'be able to edit FeedReaderBlock' do @@ -569,17 +507,17 @@ class ProfileDesignControllerTest < ActionController::TestCase end should 'allow admins to add RawHTMLBlock' do - profile.stubs(:is_admin?).with(profile.environment).returns(true) + profile.stubs(:is_admin?).returns(true) @controller.stubs(:user).returns(profile) - get :add_block, :profile => 'designtestuser' - assert_tag :tag => 'input', :attributes => { :name => 'type', :value => 'RawHTMLBlock' } + get :index, :profile => 'designtestuser' + assert_tag :tag => 'div', :attributes => { 'data-block-type' => 'RawHTMLBlock' } end should 'not allow normal users to add RawHTMLBlock' do - profile.stubs(:is_admin?).with(profile.environment).returns(false) + profile.stubs(:is_admin?).returns(false) @controller.stubs(:user).returns(profile) - get :add_block, :profile => 'designtestuser' - assert_no_tag :tag => 'input', :attributes => { :name => 'type', :value => 'RawHTMLBlock' } + get :index, :profile => 'designtestuser' + assert_no_tag :tag => 'div', :attributes => { 'data-block-type' => 'RawHTMLBlock' } end should 'editing article block displays right selected article' do -- libgit2 0.21.2