Commit 47bee664ac11084bce3a5b199099044e0d496591

Authored by Rodrigo Souto
1 parent b4e68a4a

container_block: destroy box after container is destroyed

plugins/container_block/controllers/container_block_plugin_controller.rb
1 1 module ContainerBlockPluginController
2   -
  2 +
3 3 def saveWidths
4 4 container = boxes_holder.blocks.find(params[:id])
5 5 pairs = params[:widths].split('|')
... ...
plugins/container_block/lib/container_block_plugin/container_block.rb
... ... @@ -2,6 +2,7 @@ class ContainerBlockPlugin::ContainerBlock < Block
2 2  
3 3 after_create :create_box
4 4 after_destroy :destroy_children
  5 + after_destroy :destroy_box
5 6  
6 7 settings_items :container_box_id, :type => Integer, :default => nil
7 8 settings_items :children_settings, :type => Hash, :default => {}
... ... @@ -28,6 +29,10 @@ class ContainerBlockPlugin::ContainerBlock < Block
28 29 save!
29 30 end
30 31  
  32 + def destroy_box
  33 + container_box.destroy
  34 + end
  35 +
31 36 def container_box
32 37 Box.find(container_box_id)
33 38 end
... ...
plugins/container_block/test/unit/container_block_plugin/container_block_test.rb
... ... @@ -81,4 +81,11 @@ class ContainerBlockPlugin::ContainerBlockTest < ActiveSupport::TestCase
81 81 assert !Block.exists?(child.id)
82 82 end
83 83  
  84 + should 'destroy box when container is removed' do
  85 + @block.save!
  86 + assert_difference Box, :count, -1 do
  87 + @block.destroy
  88 + end
  89 + end
  90 +
84 91 end
... ...