[Git][noosfero/noosfero][master] avoid exception in recent content block used in environment without portal community defined

Leandro Nunes gitlab at mg.gitlab.com
Fri May 13 20:57:12 BRT 2016


Leandro Nunes pushed to branch master at Noosfero / noosfero


Commits:
51676464 by Leandro Nunes dos Santos at 2016-05-13T20:56:51-03:00
avoid exception in recent content block used in environment without portal community defined

- - - - -


2 changed files:

- plugins/recent_content/lib/recent_content_block.rb
- plugins/recent_content/test/unit/recent_content_block_test.rb


Changes:

=====================================
plugins/recent_content/lib/recent_content_block.rb
=====================================
--- a/plugins/recent_content/lib/recent_content_block.rb
+++ b/plugins/recent_content/lib/recent_content_block.rb
@@ -33,7 +33,7 @@ class RecentContentBlock < Block
   end
 
   def parents
-    self.holder.articles.where(type: 'Blog')
+    self.holder.nil? ? [] : self.holder.articles.where(type: 'Blog')
   end
 
   def root


=====================================
plugins/recent_content/test/unit/recent_content_block_test.rb
=====================================
--- a/plugins/recent_content/test/unit/recent_content_block_test.rb
+++ b/plugins/recent_content/test/unit/recent_content_block_test.rb
@@ -156,4 +156,15 @@ class RecentContentBlockViewTest < ActionView::TestCase
     assert_equal [article.id], block.api_content['articles'].map {|a| a[:id]}
   end
 
+  should 'parents return an empty array for environment without portal community' do
+    environment = fast_create(Environment)
+    block = RecentContentBlock.new
+    box = mock()
+    block.stubs(:box).returns(box)
+    box.stubs(:owner).returns(environment)
+
+    assert_nil environment.portal_community
+    assert_equal [], block.parents
+  end
+
 end



View it on GitLab: https://gitlab.com/noosfero/noosfero/commit/5167646409d9f13eafacc8494aa7ea79149bf564
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20160513/74b5f70c/attachment-0001.html>


More information about the Noosfero-dev mailing list