diff --git a/app/models/profile_list_block.rb b/app/models/profile_list_block.rb index 450d33b..92ebf07 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 + 1)})" + @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 9d50df8..a052085 100644 --- a/test/unit/profile_list_block_test.rb +++ b/test/unit/profile_list_block_test.rb @@ -153,8 +153,15 @@ 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(11).returns(5) - assert_match /profiles.id % 5/, block.randomizer + block.expects(:rand).with(10).returns(5) + assert_match /profiles.id % 6/, block.randomizer + end + + should 'not divide by zero' do + block = ProfileListBlock.new + block.stubs(:profile_count).returns(0) + block.expects(:rand).returns(0) + assert_no_match /profiles.id % 0/, block.randomizer end end -- libgit2 0.21.2