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:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user