Commit 1668fe7d50803460a247eec5a2d068bb93c2eb08
1 parent
10218c1d
Exists in
master
and in
29 other branches
Avoid division by zero on ProfileListBlock
(ActionItem1682)
Showing
2 changed files
with
2 additions
and
2 deletions
Show diff stats
app/models/profile_list_block.rb
@@ -21,7 +21,7 @@ class ProfileListBlock < Block | @@ -21,7 +21,7 @@ class ProfileListBlock < Block | ||
21 | end | 21 | end |
22 | 22 | ||
23 | def randomizer | 23 | def randomizer |
24 | - @randomizer ||= "(profiles.id % #{rand(profile_count)})" | 24 | + @randomizer ||= "(profiles.id % #{rand(profile_count + 1)})" |
25 | end | 25 | end |
26 | 26 | ||
27 | # the title of the block. Probably will be overriden in subclasses. | 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,7 +153,7 @@ class ProfileListBlockTest < Test::Unit::TestCase | ||
153 | should 'randomize using modulo operator and random number' do | 153 | should 'randomize using modulo operator and random number' do |
154 | block = ProfileListBlock.new | 154 | block = ProfileListBlock.new |
155 | block.expects(:profile_count).returns(10) | 155 | block.expects(:profile_count).returns(10) |
156 | - block.expects(:rand).with(10).returns(5) | 156 | + block.expects(:rand).with(11).returns(5) |
157 | assert_match /profiles.id % 5/, block.randomizer | 157 | assert_match /profiles.id % 5/, block.randomizer |
158 | end | 158 | end |
159 | 159 |