Commit 1668fe7d50803460a247eec5a2d068bb93c2eb08

Authored by Antonio Terceiro
1 parent 10218c1d

Avoid division by zero on ProfileListBlock

(ActionItem1682)
app/models/profile_list_block.rb
... ... @@ -21,7 +21,7 @@ class ProfileListBlock < Block
21 21 end
22 22  
23 23 def randomizer
24   - @randomizer ||= "(profiles.id % #{rand(profile_count)})"
  24 + @randomizer ||= "(profiles.id % #{rand(profile_count + 1)})"
25 25 end
26 26  
27 27 # the title of the block. Probably will be overriden in subclasses.
... ...
test/unit/profile_list_block_test.rb
... ... @@ -153,7 +153,7 @@ class ProfileListBlockTest < Test::Unit::TestCase
153 153 should 'randomize using modulo operator and random number' do
154 154 block = ProfileListBlock.new
155 155 block.expects(:profile_count).returns(10)
156   - block.expects(:rand).with(10).returns(5)
  156 + block.expects(:rand).with(11).returns(5)
157 157 assert_match /profiles.id % 5/, block.randomizer
158 158 end
159 159  
... ...