Commit 47bee664ac11084bce3a5b199099044e0d496591
1 parent
b4e68a4a
Exists in
staging
and in
42 other branches
container_block: destroy box after container is destroyed
Showing
3 changed files
with
13 additions
and
1 deletions
Show diff stats
plugins/container_block/controllers/container_block_plugin_controller.rb
plugins/container_block/lib/container_block_plugin/container_block.rb
@@ -2,6 +2,7 @@ class ContainerBlockPlugin::ContainerBlock < Block | @@ -2,6 +2,7 @@ class ContainerBlockPlugin::ContainerBlock < Block | ||
2 | 2 | ||
3 | after_create :create_box | 3 | after_create :create_box |
4 | after_destroy :destroy_children | 4 | after_destroy :destroy_children |
5 | + after_destroy :destroy_box | ||
5 | 6 | ||
6 | settings_items :container_box_id, :type => Integer, :default => nil | 7 | settings_items :container_box_id, :type => Integer, :default => nil |
7 | settings_items :children_settings, :type => Hash, :default => {} | 8 | settings_items :children_settings, :type => Hash, :default => {} |
@@ -28,6 +29,10 @@ class ContainerBlockPlugin::ContainerBlock < Block | @@ -28,6 +29,10 @@ class ContainerBlockPlugin::ContainerBlock < Block | ||
28 | save! | 29 | save! |
29 | end | 30 | end |
30 | 31 | ||
32 | + def destroy_box | ||
33 | + container_box.destroy | ||
34 | + end | ||
35 | + | ||
31 | def container_box | 36 | def container_box |
32 | Box.find(container_box_id) | 37 | Box.find(container_box_id) |
33 | end | 38 | end |
plugins/container_block/test/unit/container_block_plugin/container_block_test.rb
@@ -81,4 +81,11 @@ class ContainerBlockPlugin::ContainerBlockTest < ActiveSupport::TestCase | @@ -81,4 +81,11 @@ class ContainerBlockPlugin::ContainerBlockTest < ActiveSupport::TestCase | ||
81 | assert !Block.exists?(child.id) | 81 | assert !Block.exists?(child.id) |
82 | end | 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 | end | 91 | end |