Commit 26d1c265de82811b5a958c53f6b392f6f7caad8e
1 parent
109fffc3
Exists in
master
and in
22 other branches
[postgres-tests] Fixing features products block offset logic
Also fixing a test that was sort dependent.
Showing
2 changed files
with
8 additions
and
3 deletions
Show diff stats
app/models/featured_products_block.rb
| @@ -7,8 +7,9 @@ class FeaturedProductsBlock < Block | @@ -7,8 +7,9 @@ class FeaturedProductsBlock < Block | ||
| 7 | 7 | ||
| 8 | before_save do |block| | 8 | before_save do |block| |
| 9 | if block.owner.kind_of?(Environment) && block.product_ids.blank? | 9 | if block.owner.kind_of?(Environment) && block.product_ids.blank? |
| 10 | - seed = block.owner.products.count | ||
| 11 | - block.product_ids = block.owner.highlighted_products_with_image(:offset => (rand(seed) % (seed - block.groups_of * 3)), :limit => block.groups_of * 3).map(&:id) | 10 | + total = block.owner.products.count |
| 11 | + offset = rand([(total - block.groups_of * 3) + 1, 1].max) | ||
| 12 | + block.product_ids = block.owner.highlighted_products_with_image(:offset => offset, :limit => block.groups_of * 3).map(&:id) | ||
| 12 | end | 13 | end |
| 13 | block.groups_of = block.groups_of.to_i | 14 | block.groups_of = block.groups_of.to_i |
| 14 | end | 15 | end |
test/unit/featured_products_block_test.rb
| @@ -129,7 +129,11 @@ class FeaturedProductsBlockTest < ActiveSupport::TestCase | @@ -129,7 +129,11 @@ class FeaturedProductsBlockTest < ActiveSupport::TestCase | ||
| 129 | }) | 129 | }) |
| 130 | @environment.boxes.first.blocks<< block | 130 | @environment.boxes.first.blocks<< block |
| 131 | 131 | ||
| 132 | - assert_equal products, block.products_for_selection | 132 | + products_for_selection = block.products_for_selection |
| 133 | + | ||
| 134 | + products.each do |product| | ||
| 135 | + assert_includes products_for_selection, product | ||
| 136 | + end | ||
| 133 | end | 137 | end |
| 134 | 138 | ||
| 135 | end | 139 | end |