From ef30dc1efe6c7a2c31a502edbb0fcef508ffea96 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Thu, 1 Mar 2018 22:52:37 +0100 Subject: [PATCH] Add defensive test to display correctly a user's votes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a defensive test, just in case we decide to go back to using `setseed` instead of the `modulus`[1] approach to display investments in random order The reason for this test is that `setseed` only ~works in the next `select` statement. And as when loading a user’s votes for investments we do a second `select` it does not work as expected 😌 To solve this… we could call `set_random_seed` before loading a user’s votes for an investment[2] [1] https://github.com/consul/consul/pull/2131 [2] https://github.com/AyuntamientoMadrid/consul/blob/master/app/controllers /budgets/investments_controller.rb#L37 --- spec/features/budgets/investments_spec.rb | 24 +++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/spec/features/budgets/investments_spec.rb b/spec/features/budgets/investments_spec.rb index f5a650c18..280b2fc6b 100644 --- a/spec/features/budgets/investments_spec.rb +++ b/spec/features/budgets/investments_spec.rb @@ -621,6 +621,30 @@ feature 'Budget Investments' do expect(order).to_not eq(orderd_by_id) end + scenario "Set votes for investments randomized with a seed" do + voter = create(:user, :level_two) + login_as(voter) + + 10.times { create(:budget_investment, heading: heading) } + + voted_investments = [] + 10.times do + investment = create(:budget_investment, heading: heading) + create(:vote, votable: investment, voter: voter) + voted_investments << investment + end + + visit budget_investments_path(budget, heading_id: heading.id) + + voted_investments.each do |investment| + if page.has_link?(investment.title) + within("#budget_investment_#{investment.id}") do + expect(page).to have_content "You have already supported this investment" + end + end + end + end + def investments_order all(".budget-investment h3").collect {|i| i.text } end