Commit 265fa7193873ffce78ae8f8679bc31783cfb6c39

Authored by Joenio Costa
Committed by Daniela Feitosa
1 parent 6697a453

Not try to load a removed blog on BlogArchivesBlock

(ActionItem1882)
app/models/blog_archives_block.rb
@@ -17,7 +17,7 @@ class BlogArchivesBlock < Block @@ -17,7 +17,7 @@ class BlogArchivesBlock < Block
17 settings_items :blog_id, Integer 17 settings_items :blog_id, Integer
18 18
19 def blog 19 def blog
20 - blog_id ? owner.blogs.find(blog_id) : owner.blog 20 + blog_id && owner.blogs.exists?(blog_id) ? owner.blogs.find(blog_id) : owner.blog
21 end 21 end
22 22
23 def content 23 def content
test/factories.rb
@@ -310,6 +310,8 @@ module Noosfero::Factory @@ -310,6 +310,8 @@ module Noosfero::Factory
310 { } 310 { }
311 end 311 end
312 312
  313 + alias :defaults_for_blog_archives_block :defaults_for_block
  314 +
313 ############################################### 315 ###############################################
314 # Task 316 # Task
315 ############################################### 317 ###############################################
test/unit/blog_archives_block_test.rb
@@ -134,4 +134,27 @@ class BlogArchivesBlockTest < ActiveSupport::TestCase @@ -134,4 +134,27 @@ class BlogArchivesBlockTest < ActiveSupport::TestCase
134 assert_tag_in_string block.content, :tag => 'a', :content => 'January (2)', :attributes => {:href => /^http:\/\/.*\/flatline\/blog-one\?month=01&year=2008$/ } 134 assert_tag_in_string block.content, :tag => 'a', :content => 'January (2)', :attributes => {:href => /^http:\/\/.*\/flatline\/blog-one\?month=01&year=2008$/ }
135 end 135 end
136 136
  137 + should 'not try to load a removed blog' do
  138 + block = fast_create(BlogArchivesBlock)
  139 + block.blog_id = profile.blog.id
  140 + block.save!
  141 + block.stubs(:owner).returns(profile)
  142 + profile.blog.destroy
  143 + assert_nothing_raised do
  144 + assert_nil block.blog
  145 + end
  146 + end
  147 +
  148 + should 'load next blog if configured blog was removed' do
  149 + other_blog = fast_create(Blog, :profile_id => profile.id)
  150 + block = fast_create(BlogArchivesBlock)
  151 + block.blog_id = profile.blog.id
  152 + block.save!
  153 + block.stubs(:owner).returns(profile)
  154 + profile.blog.destroy
  155 + assert_nothing_raised do
  156 + assert_equal other_blog, block.blog
  157 + end
  158 + end
  159 +
137 end 160 end