Commit 5167646409d9f13eafacc8494aa7ea79149bf564

Authored by Leandro Santos
1 parent 13239c9a

avoid exception in recent content block used in environment without portal community defined

plugins/recent_content/lib/recent_content_block.rb
@@ -33,7 +33,7 @@ class RecentContentBlock < Block @@ -33,7 +33,7 @@ class RecentContentBlock < Block
33 end 33 end
34 34
35 def parents 35 def parents
36 - self.holder.articles.where(type: 'Blog') 36 + self.holder.nil? ? [] : self.holder.articles.where(type: 'Blog')
37 end 37 end
38 38
39 def root 39 def root
plugins/recent_content/test/unit/recent_content_block_test.rb
@@ -156,4 +156,15 @@ class RecentContentBlockViewTest < ActionView::TestCase @@ -156,4 +156,15 @@ class RecentContentBlockViewTest < ActionView::TestCase
156 assert_equal [article.id], block.api_content['articles'].map {|a| a[:id]} 156 assert_equal [article.id], block.api_content['articles'].map {|a| a[:id]}
157 end 157 end
158 158
  159 + should 'parents return an empty array for environment without portal community' do
  160 + environment = fast_create(Environment)
  161 + block = RecentContentBlock.new
  162 + box = mock()
  163 + block.stubs(:box).returns(box)
  164 + box.stubs(:owner).returns(environment)
  165 +
  166 + assert_nil environment.portal_community
  167 + assert_equal [], block.parents
  168 + end
  169 +
159 end 170 end