Commit 265fa7193873ffce78ae8f8679bc31783cfb6c39
Committed by
Daniela Feitosa
1 parent
6697a453
Exists in
master
and in
29 other branches
Not try to load a removed blog on BlogArchivesBlock
(ActionItem1882)
Showing
3 changed files
with
26 additions
and
1 deletions
Show diff stats
app/models/blog_archives_block.rb
... | ... | @@ -17,7 +17,7 @@ class BlogArchivesBlock < Block |
17 | 17 | settings_items :blog_id, Integer |
18 | 18 | |
19 | 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 | 21 | end |
22 | 22 | |
23 | 23 | def content | ... | ... |
test/factories.rb
test/unit/blog_archives_block_test.rb
... | ... | @@ -134,4 +134,27 @@ class BlogArchivesBlockTest < ActiveSupport::TestCase |
134 | 134 | assert_tag_in_string block.content, :tag => 'a', :content => 'January (2)', :attributes => {:href => /^http:\/\/.*\/flatline\/blog-one\?month=01&year=2008$/ } |
135 | 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 | 160 | end | ... | ... |