[Git][noosfero/noosfero][master] 2 commits: Improvements on template mirror blocks behaviour

Rodrigo Souto gitlab at mg.gitlab.com
Mon Jun 12 17:43:57 BRT 2017


Rodrigo Souto pushed to branch master at Noosfero / noosfero


Commits:
b85b28e3 by Tallys Martins at 2017-06-12T12:51:08-03:00
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 at yahoo.com.br>

- - - - -
7f85ba0c by Rodrigo Souto at 2017-06-12T20:43:30+00:00
Merge branch 'mirror-block-cascade-remove' into 'master'

Improvements on template mirror blocks behaviour

See merge request !1236
- - - - -


2 changed files:

- app/models/block.rb
- test/unit/block_test.rb


Changes:

=====================================
app/models/block.rb
=====================================
--- a/app/models/block.rb
+++ b/app/models/block.rb
@@ -38,6 +38,14 @@ class Block < ApplicationRecord
     end
   end
 
+  after_destroy do |block|
+    if block.owner.kind_of?(Profile) && block.owner.is_template? && block.mirror?
+      block.observers.each do |observer|
+        observer.destroy
+      end
+    end
+  end
+
   def embedable?
     false
   end


=====================================
test/unit/block_test.rb
=====================================
--- a/test/unit/block_test.rb
+++ b/test/unit/block_test.rb
@@ -503,4 +503,19 @@ class BlockTest < ActiveSupport::TestCase
     }])
     assert_equal 'shoes.png', block.reload.images.first.filename
   end
+
+  should 'destroy mirrored block when deleted from template' do
+    profile_template = create_user('test_template').person
+    profile_template.is_template = true
+    profile_template.save!
+
+    template_block = create(RecentDocumentsBlock, :mirror => true, :title => 'template block')
+    mirrored_block = create(RecentDocumentsBlock, :mirror => false, :mirror_block_id => template_block, :title => 'mirrored block')
+    template_block.observers << mirrored_block
+
+    template_block.stubs(:owner).returns(profile_template)
+    template_block.destroy!
+
+    assert_nil RecentDocumentsBlock.find_by_id mirrored_block.id
+  end
 end



View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/47984c09c44cb8dac4d4f148f2ca368e75a919b5...7f85ba0cd0e613e45434d8af3fa09f643681502d

---
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/47984c09c44cb8dac4d4f148f2ca368e75a919b5...7f85ba0cd0e613e45434d8af3fa09f643681502d
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20170612/7b3e4cbb/attachment-0001.html>


More information about the Noosfero-dev mailing list