Commit d76b9e3bfc2c63c829e4c2ee85d405f9918a74d1
1 parent
18a99bd2
Exists in
master
and in
28 other branches
Don't crash if referenced image gallery is deleted
(ActionItem1494)
Showing
2 changed files
with
5 additions
and
1 deletions
Show diff stats
app/models/slideshow_block.rb
@@ -10,7 +10,7 @@ class SlideshowBlock < Block | @@ -10,7 +10,7 @@ class SlideshowBlock < Block | ||
10 | end | 10 | end |
11 | 11 | ||
12 | def gallery | 12 | def gallery |
13 | - gallery_id ? Folder.find(gallery_id) : nil | 13 | + gallery_id ? Folder.find(:first, :conditions => { :id => gallery_id }) : nil |
14 | end | 14 | end |
15 | 15 | ||
16 | def block_images | 16 | def block_images |
test/unit/slideshow_block_test.rb
@@ -15,6 +15,10 @@ class SlideshowBlockTest < ActiveSupport::TestCase | @@ -15,6 +15,10 @@ class SlideshowBlockTest < ActiveSupport::TestCase | ||
15 | assert_equal gallery, slideshow_block.gallery | 15 | assert_equal gallery, slideshow_block.gallery |
16 | end | 16 | end |
17 | 17 | ||
18 | + should 'not crash if referencing unexisting folder' do | ||
19 | + assert_nil SlideshowBlock.new(:gallery_id => -999).gallery | ||
20 | + end | ||
21 | + | ||
18 | should 'default interval between transitions is 4 seconds' do | 22 | should 'default interval between transitions is 4 seconds' do |
19 | slideshow = SlideshowBlock.new | 23 | slideshow = SlideshowBlock.new |
20 | assert_equal 4, slideshow.interval | 24 | assert_equal 4, slideshow.interval |