diff --git a/plugins/container_block/lib/container_block_plugin/container_block.rb b/plugins/container_block/lib/container_block_plugin/container_block.rb index 87b4007..5948ecf 100644 --- a/plugins/container_block/lib/container_block_plugin/container_block.rb +++ b/plugins/container_block/lib/container_block_plugin/container_block.rb @@ -38,7 +38,7 @@ class ContainerBlockPlugin::ContainerBlock < Block end def block_classes=(classes) - classes.each { |c| block = c.constantize.create!(:box => container_box) } if classes + classes.each { |c| block = c.constantize.create!(:box_id => container_box.id) } if classes end def blocks @@ -51,8 +51,8 @@ class ContainerBlockPlugin::ContainerBlock < Block def content(args={}) block = self - lambda do - render :file => 'blocks/container.rhtml', :locals => {:block => block} + proc do + render :file => 'blocks/container', :locals => {:block => block} end end diff --git a/plugins/container_block/test/functional/container_block_environment_design_controller_test.rb b/plugins/container_block/test/functional/container_block_environment_design_controller_test.rb index 3dec77d..ce16a9f 100644 --- a/plugins/container_block/test/functional/container_block_environment_design_controller_test.rb +++ b/plugins/container_block/test/functional/container_block_environment_design_controller_test.rb @@ -20,7 +20,7 @@ class EnvironmentDesignControllerTest < ActionController::TestCase @environment.add_admin(user.person) login_as(user.login) - @block = ContainerBlockPlugin::ContainerBlock.create!(:box => @environment.boxes.first) + @block = create(ContainerBlockPlugin::ContainerBlock, :box => @environment.boxes.first) end should 'be able to edit ContainerBlock' do @@ -36,46 +36,46 @@ class EnvironmentDesignControllerTest < ActionController::TestCase end should 'display container children' do - c1 = RawHTMLBlock.create!(:box => @block.container_box, :html => 'child1 content') + c1 = RawHTMLBlock.create!(:box_id => @block.container_box.id, :html => 'child1 content') get :index assert_tag :div, :attributes => { :id => "block-#{c1.id}" } end should 'display hidden children of container block' do - c1 = RawHTMLBlock.create!(:box => @block.container_box, :html => 'child1 content', :display => 'never') + c1 = RawHTMLBlock.create!(:box_id => @block.container_box.id, :html => 'child1 content', :display => 'never') get :index assert_tag :div, :attributes => { :id => "block-#{c1.id}", :class => 'block raw-html-block invisible-block' } end should 'display button to save widths of container children' do - c1 = RawHTMLBlock.create!(:box => @block.container_box, :html => 'child1 content') + c1 = RawHTMLBlock.create!(:box_id => @block.container_box.id, :html => 'child1 content') get :index assert_tag :a, :attributes => { :class => "button icon-save container_block_save" } end should 'move child of container block to another box' do - c1 = RawHTMLBlock.create!(:box => @block.container_box, :html => 'child1 content') + c1 = RawHTMLBlock.create!(:box_id => @block.container_box.id, :html => 'child1 content') get :move_block, :id => c1.id, :target => "end-of-box-#{@environment.boxes.last.id}" assert_equal @environment.boxes.last, c1.reload.box end should 'move block to inside of a container block' do - c1 = RawHTMLBlock.create!(:box => @block.container_box, :html => 'child1 content') - c2 = RawHTMLBlock.create!(:box => @environment.boxes.last, :html => 'child2 content') + c1 = RawHTMLBlock.create!(:box_id => @block.container_box.id, :html => 'child1 content') + c2 = RawHTMLBlock.create!(:box_id => @environment.boxes.last.id, :html => 'child2 content') get :move_block, :id => c2.id, :target => "before-block-#{c1.id}" assert_equal @block.container_box, c2.reload.box end should 'move down a container block child' do - c1 = RawHTMLBlock.create!(:box => @block.container_box, :html => 'child1 content') - c2 = RawHTMLBlock.create!(:box => @block.container_box, :html => 'child2 content') + c1 = RawHTMLBlock.create!(:box_id => @block.container_box.id, :html => 'child1 content') + c2 = RawHTMLBlock.create!(:box_id => @block.container_box.id, :html => 'child2 content') get :move_block_down, :id => c1.id assert_equal [c2, c1], @block.blocks end should 'move up a container block child' do - c1 = RawHTMLBlock.create!(:box => @block.container_box, :html => 'child1 content') - c2 = RawHTMLBlock.create!(:box => @block.container_box, :html => 'child2 content') + c1 = RawHTMLBlock.create!(:box_id => @block.container_box.id, :html => 'child1 content') + c2 = RawHTMLBlock.create!(:box_id => @block.container_box.id, :html => 'child2 content') get :move_block_up, :id => c2.id assert_equal [c2, c1], @block.blocks end diff --git a/plugins/container_block/test/functional/container_block_home_controller_test.rb b/plugins/container_block/test/functional/container_block_home_controller_test.rb index 29d0836..b43cc40 100644 --- a/plugins/container_block/test/functional/container_block_home_controller_test.rb +++ b/plugins/container_block/test/functional/container_block_home_controller_test.rb @@ -20,8 +20,8 @@ class HomeControllerTest < ActionController::TestCase @environment.add_admin(user.person) login_as(user.login) - box = Box.create!(:owner => @environment) - @block = ContainerBlockPlugin::ContainerBlock.create!(:box => box) + box = create(Box, :owner => @environment) + @block = create(ContainerBlockPlugin::ContainerBlock, :box => box) @environment.boxes = [box] end @@ -32,15 +32,15 @@ class HomeControllerTest < ActionController::TestCase end should 'display container children' do - c1 = RawHTMLBlock.create!(:box => @block.container_box, :html => 'child1 content') - c2 = RawHTMLBlock.create!(:box => @block.container_box, :html => 'child2 content') + c1 = RawHTMLBlock.create!(:box_id => @block.container_box.id, :html => 'child1 content') + c2 = RawHTMLBlock.create!(:box_id => @block.container_box.id, :html => 'child2 content') get :index assert_tag :div, :attributes => { :id => "block-#{c1.id}" } assert_tag :div, :attributes => { :id => "block-#{c2.id}" } end should 'display style tags for container children' do - c1 = RawHTMLBlock.create!(:box => @block.container_box, :html => 'child1 content') + c1 = RawHTMLBlock.create!(:box_id => @block.container_box.id, :html => 'child1 content') @block.children_settings = { c1.id => {:width => "123"} } @block.save! get :index @@ -48,7 +48,7 @@ class HomeControllerTest < ActionController::TestCase end should 'do not display hidden children of container' do - c1 = RawHTMLBlock.create!(:box => @block.container_box, :html => 'child1 content', :display => 'never') + c1 = RawHTMLBlock.create!(:box_id => @block.container_box.id, :html => 'child1 content', :display => 'never') get :index assert_no_tag :div, :attributes => { :id => "block-#{c1.id}" } end diff --git a/plugins/container_block/test/functional/container_block_plugin_admin_controller_test.rb b/plugins/container_block/test/functional/container_block_plugin_admin_controller_test.rb index 86e7786..b77d65f 100644 --- a/plugins/container_block/test/functional/container_block_plugin_admin_controller_test.rb +++ b/plugins/container_block/test/functional/container_block_plugin_admin_controller_test.rb @@ -12,9 +12,9 @@ class ContainerBlockPluginAdminControllerTest < ActionController::TestCase @environment.add_admin(user.person) login_as(user.login) - @block = ContainerBlockPlugin::ContainerBlock.create!(:box => @environment.boxes.first) - @child1 = Block.create!(:box => @block.container_box) - @child2 = Block.create!(:box => @block.container_box) + @block = ContainerBlockPlugin::ContainerBlock.create!(:box_id => @environment.boxes.first.id) + @child1 = Block.create!(:box_id => @block.container_box.id) + @child2 = Block.create!(:box_id => @block.container_box.id) end should 'save widths of container block children' do diff --git a/plugins/container_block/test/functional/container_block_plugin_controller_test.rb b/plugins/container_block/test/functional/container_block_plugin_controller_test.rb index 5c2cecf..12512fe 100644 --- a/plugins/container_block/test/functional/container_block_plugin_controller_test.rb +++ b/plugins/container_block/test/functional/container_block_plugin_controller_test.rb @@ -14,9 +14,9 @@ class ContainerBlockPluginControllerTest < ActionController::TestCase @environment.add_admin(user.person) login_as(user.login) - @block = ContainerBlockPlugin::ContainerBlock.create!(:box => @environment.boxes.first) - @child1 = Block.create!(:box => @block.container_box) - @child2 = Block.create!(:box => @block.container_box) + @block = ContainerBlockPlugin::ContainerBlock.create!(:box_id => @environment.boxes.first.id) + @child1 = Block.create!(:box_id => @block.container_box.id) + @child2 = Block.create!(:box_id => @block.container_box.id) @environment = Environment.find(@environment.id) stubs(:boxes_holder).returns(@environment) @params = {} diff --git a/plugins/container_block/test/functional/container_block_plugin_myprofile_controller_test.rb b/plugins/container_block/test/functional/container_block_plugin_myprofile_controller_test.rb index d5e342e..ee85b7a 100644 --- a/plugins/container_block/test/functional/container_block_plugin_myprofile_controller_test.rb +++ b/plugins/container_block/test/functional/container_block_plugin_myprofile_controller_test.rb @@ -8,11 +8,11 @@ class ContainerBlockPluginMyprofileControllerTest < ActionController::TestCase @profile = fast_create(Community) @profile.add_admin(user.person) - @box = Box.new(:owner => @profile) + @box = Box.create!(:owner => @profile) - @block = ContainerBlockPlugin::ContainerBlock.create!(:box => @box) - @child1 = Block.create!(:box => @block.container_box) - @child2 = Block.create!(:box => @block.container_box) + @block = ContainerBlockPlugin::ContainerBlock.create!(:box_id => @box.id) + @child1 = Block.create!(:box_id => @block.container_box.id) + @child2 = Block.create!(:box_id => @block.container_box.id) end should 'save widths of container block children' do diff --git a/plugins/container_block/test/unit/block_test.rb b/plugins/container_block/test/unit/block_test.rb index 7b5ccd3..75301fa 100644 --- a/plugins/container_block/test/unit/block_test.rb +++ b/plugins/container_block/test/unit/block_test.rb @@ -5,26 +5,26 @@ class BlockTest < ActiveSupport::TestCase def setup @environment = fast_create(Environment) @box = Box.create!(:owner => @environment) - @container = ContainerBlockPlugin::ContainerBlock.create!(:box => @box) + @container = ContainerBlockPlugin::ContainerBlock.create!(:box_id => @box.id) end should 'return environment box if block owner is not a ContainerBlock' do - block = Block.create!(:box => @box) + block = Block.create!(:box_id => @box.id) assert_equal @box, block.box end should 'return container box if block owner is a ContainerBlock' do - block = Block.create!(:box => @container.container_box) + block = Block.create!(:box_id => @container.container_box.id) assert_equal @container.container_box, block.box end should 'return block owner if block onwer is not a ContainerBlock' do - block = Block.create!(:box => @box) + block = Block.create!(:box_id => @box.id) assert_equal @environment, block.owner end should 'return environment as owner if block onwer is a ContainerBlock' do - block = Block.create!(:box => @container.container_box) + block = Block.create!(:box_id => @container.container_box.id) assert_equal @environment, block.owner end diff --git a/plugins/container_block/test/unit/container_block_plugin/container_block_test.rb b/plugins/container_block/test/unit/container_block_plugin/container_block_test.rb index 62e1fa3..9aad7f7 100644 --- a/plugins/container_block/test/unit/container_block_plugin/container_block_test.rb +++ b/plugins/container_block/test/unit/container_block_plugin/container_block_test.rb @@ -27,7 +27,7 @@ class ContainerBlockPlugin::ContainerBlockTest < ActiveSupport::TestCase should 'create new blocks when receive block classes' do @block.save! - assert_difference Block, :count, 1 do + assert_difference 'Block.count', 1 do @block.block_classes = ['Block'] end assert_equal Block, Block.last.class @@ -35,14 +35,14 @@ class ContainerBlockPlugin::ContainerBlockTest < ActiveSupport::TestCase should 'do not create blocks when nothing is passed as block classes' do @block.save! - assert_no_difference Block, :count do + assert_no_difference 'Block.count' do @block.block_classes = [] end end should 'do not create blocks when nil is passed as block classes' do @block.save! - assert_no_difference Block, :count do + assert_no_difference 'Block.count' do @block.block_classes = nil end end @@ -84,7 +84,7 @@ class ContainerBlockPlugin::ContainerBlockTest < ActiveSupport::TestCase should 'destroy box when container is removed' do @block.save! - assert_difference Box, :count, -1 do + assert_difference 'Box.count', -1 do @block.destroy end end diff --git a/plugins/container_block/test/unit/environment_test.rb b/plugins/container_block/test/unit/environment_test.rb index f9b5851..4368454 100644 --- a/plugins/container_block/test/unit/environment_test.rb +++ b/plugins/container_block/test/unit/environment_test.rb @@ -5,10 +5,10 @@ class EnvironmentTest < ActiveSupport::TestCase def setup @environment = fast_create(Environment) - @box = Box.create!(:owner => @environment) - @block = Block.create!(:box => @box) + @box = create(Box, :owner => @environment) + @block = create(Block, :box => @box) - @container = ContainerBlockPlugin::ContainerBlock.create!(:box => @box) + @container = create(ContainerBlockPlugin::ContainerBlock, :box => @box) end should 'return blocks as usual' do @@ -16,7 +16,7 @@ class EnvironmentTest < ActiveSupport::TestCase end should 'return blocks with container children' do - child = Block.create!(:box => @container.container_box) + child = Block.create!(:box_id => @container.container_box.id) assert_equal [@block, @container, child], @environment.blocks end @@ -25,7 +25,7 @@ class EnvironmentTest < ActiveSupport::TestCase end should 'return child block with id at find method' do - child = Block.create!(:box => @container.container_box) + child = Block.create!(:box_id => @container.container_box.id) assert_equal child, @environment.blocks.find(child.id) end diff --git a/plugins/container_block/test/unit/profile_test.rb b/plugins/container_block/test/unit/profile_test.rb index 362a0d6..4caac2d 100644 --- a/plugins/container_block/test/unit/profile_test.rb +++ b/plugins/container_block/test/unit/profile_test.rb @@ -5,10 +5,10 @@ class ProfileTest < ActiveSupport::TestCase def setup @profile = fast_create(Profile) - @box = Box.create!(:owner => @profile) - @block = Block.create!(:box => @box) + @box = create(Box, :owner => @profile) + @block = create(Block, :box => @box) - @container = ContainerBlockPlugin::ContainerBlock.create!(:box => @box) + @container = create(ContainerBlockPlugin::ContainerBlock, :box => @box) end should 'return blocks as usual' do @@ -16,7 +16,7 @@ class ProfileTest < ActiveSupport::TestCase end should 'return blocks with container children' do - child = Block.create!(:box => @container.container_box) + child = Block.create!(:box_id => @container.container_box.id) assert_equal [@block, @container, child], @profile.blocks end @@ -25,7 +25,7 @@ class ProfileTest < ActiveSupport::TestCase end should 'return child block with id at find method' do - child = Block.create!(:box => @container.container_box) + child = Block.create!(:box_id => @container.container_box.id) assert_equal child, @profile.blocks.find(child.id) end diff --git a/plugins/container_block/views/blocks/container.html.erb b/plugins/container_block/views/blocks/container.html.erb new file mode 100644 index 0000000..87f907c --- /dev/null +++ b/plugins/container_block/views/blocks/container.html.erb @@ -0,0 +1,60 @@ +<% edit_mode = controller.send(:boxes_editor?) && controller.send(:uses_design_blocks?) %> +<% box_decorator = edit_mode ? self : BoxesHelper::DontMoveBlocks %> + + +
+ <%= display_box_content(block.container_box, nil) %> +
+
+
+ + + +<% if edit_mode %> +
+ > + <%= link_to_remote '', :url => { :controller => controller.boxes_holder.kind_of?(Environment) ? 'container_block_plugin_admin' : 'container_block_plugin_myprofile', :action => 'saveWidths', :id => block.id }, + :with => "containerChildrenWidth(#{block.id}, #{block.container_box.id})", + :html => {:class => "button icon-save container_block_save", :id => "container_block_save_#{block.id}", :title => _('Save') }, + :loading => "open_loading(DEFAULT_LOADING_MESSAGE);", + :loaded => "close_loading();", + :complete => "display_notice(request.responseText);"%> +
+ + +<% end %> diff --git a/plugins/container_block/views/blocks/container.rhtml b/plugins/container_block/views/blocks/container.rhtml deleted file mode 100644 index 79e6fc4..0000000 --- a/plugins/container_block/views/blocks/container.rhtml +++ /dev/null @@ -1,60 +0,0 @@ -<% edit_mode = @controller.send(:boxes_editor?) && @controller.send(:uses_design_blocks?) %> -<% box_decorator = edit_mode ? self : BoxesHelper::DontMoveBlocks %> - - -
- <%= display_box_content(block.container_box, nil) %> -
-
-
- - - -<% if edit_mode %> -
- > - <%= link_to_remote '', :url => { :controller => @controller.boxes_holder.kind_of?(Environment) ? 'container_block_plugin_admin' : 'container_block_plugin_myprofile', :action => 'saveWidths', :id => block.id }, - :with => "containerChildrenWidth(#{block.id}, #{block.container_box.id})", - :html => {:class => "button icon-save container_block_save", :id => "container_block_save_#{block.id}", :title => _('Save') }, - :loading => "open_loading(DEFAULT_LOADING_MESSAGE);", - :loaded => "close_loading();", - :complete => "display_notice(request.responseText);"%> -
- - -<% end %> -- libgit2 0.21.2