Commit 515e8ca82819ed85de1569799689b0a48a09c581
1 parent
8de4f2de
Exists in
mirror_block_improvements
Improvements on template mirror blocks behaviour
- When a mirrored block is deleted, all blocks that follows the template are also deleted Signed-off-by: Tallys Martins <tallysmartins@yahoo.com.br>
Showing
2 changed files
with
23 additions
and
0 deletions
Show diff stats
app/models/block.rb
@@ -32,6 +32,14 @@ class Block < ActiveRecord::Base | @@ -32,6 +32,14 @@ class Block < ActiveRecord::Base | ||
32 | end | 32 | end |
33 | end | 33 | end |
34 | 34 | ||
35 | + after_destroy do |block| | ||
36 | + if block.owner.kind_of?(Profile) && block.owner.is_template? && block.mirror? | ||
37 | + block.observers.each do |observer| | ||
38 | + observer.destroy | ||
39 | + end | ||
40 | + end | ||
41 | + end | ||
42 | + | ||
35 | def embedable? | 43 | def embedable? |
36 | false | 44 | false |
37 | end | 45 | end |
test/unit/block_test.rb
@@ -361,4 +361,19 @@ class BlockTest < ActiveSupport::TestCase | @@ -361,4 +361,19 @@ class BlockTest < ActiveSupport::TestCase | ||
361 | assert block.get_limit.is_a?(Fixnum) | 361 | assert block.get_limit.is_a?(Fixnum) |
362 | end | 362 | end |
363 | 363 | ||
364 | + should 'destroy mirrored block when deleted from template' do | ||
365 | + profile_template = create_user('test_template').person | ||
366 | + profile_template.is_template = true | ||
367 | + profile_template.save! | ||
368 | + | ||
369 | + template_block = create(RecentDocumentsBlock, :mirror => true, :title => 'template block') | ||
370 | + mirrored_block = create(RecentDocumentsBlock, :mirror => false, :mirror_block_id => template_block, :title => 'mirrored block') | ||
371 | + template_block.observers << mirrored_block | ||
372 | + | ||
373 | + template_block.stubs(:owner).returns(profile_template) | ||
374 | + template_block.destroy! | ||
375 | + | ||
376 | + assert_nil RecentDocumentsBlock.find_by_id mirrored_block.id | ||
377 | + end | ||
378 | + | ||
364 | end | 379 | end |