Use a float smaller than 1 as a random seed

By using a random seed value smaller than 1, we solve the previous
situation[1] in a simpler way

This test is now obsolete.
It’s hard to write a tests to verify that even with a big seed in
params, we will covert it to a float smaller than 1.

We should refactor these `set_random_seed` methods into a nice model or
controller concern and test it thoroughly

[1]
https://github.com/AyuntamientoMadrid/consul/commit/ba3bf11526fc6ce9c66f
647c414946c61ff945fe
This commit is contained in:
rgarcia
2018-03-01 22:20:07 +01:00
parent 3dcbb6b976
commit 65e2360650
2 changed files with 2 additions and 11 deletions

View File

@@ -111,8 +111,8 @@ module Budgets
def set_random_seed
if params[:order] == 'random' || params[:order].blank?
seed = params[:random_seed] || session[:random_seed] || rand(-100000..100000)
params[:random_seed] = Float(seed) / 1000000 rescue 0
seed = params[:random_seed] || session[:random_seed] || rand
params[:random_seed] = seed
session[:random_seed] = params[:random_seed]
else
params[:random_seed] = nil

View File

@@ -624,15 +624,6 @@ feature 'Budget Investments' do
end
expect(@first_user_investments_order).to eq(@second_user_investments_order)
scenario "Convert seed to a value small enough for the modulus function to return investments in random order", :focus do
12.times { |i| create(:budget_investment, heading: heading, id: i) }
visit budget_investments_path(budget, heading_id: heading.id, random_seed: '12')
order = investments_order
orderd_by_id = Budget::Investment.order(:id).limit(10).pluck(:title)
expect(order).to_not eq(orderd_by_id)
end
scenario "Set votes for investments randomized with a seed" do