From 1668fe7d50803460a247eec5a2d068bb93c2eb08 Mon Sep 17 00:00:00 2001 From: Antonio Terceiro Date: Thu, 16 Dec 2010 15:56:24 -0300 Subject: [PATCH] Avoid division by zero on ProfileListBlock --- app/models/profile_list_block.rb | 2 +- test/unit/profile_list_block_test.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/profile_list_block.rb b/app/models/profile_list_block.rb index a2224db..450d33b 100644 --- a/app/models/profile_list_block.rb +++ b/app/models/profile_list_block.rb @@ -21,7 +21,7 @@ class ProfileListBlock < Block end def randomizer - @randomizer ||= "(profiles.id % #{rand(profile_count)})" + @randomizer ||= "(profiles.id % #{rand(profile_count + 1)})" end # the title of the block. Probably will be overriden in subclasses. diff --git a/test/unit/profile_list_block_test.rb b/test/unit/profile_list_block_test.rb index 1eb8a39..9d50df8 100644 --- a/test/unit/profile_list_block_test.rb +++ b/test/unit/profile_list_block_test.rb @@ -153,7 +153,7 @@ class ProfileListBlockTest < Test::Unit::TestCase should 'randomize using modulo operator and random number' do block = ProfileListBlock.new block.expects(:profile_count).returns(10) - block.expects(:rand).with(10).returns(5) + block.expects(:rand).with(11).returns(5) assert_match /profiles.id % 5/, block.randomizer end -- libgit2 0.21.2