From 969e0014e53ec8fc17607ffebf9c33b437072010 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 24 Aug 2022 17:54:47 +0200 Subject: [PATCH] Move budget result test to the model We were testing that the `calculate_winners` method does not take the price into account; we can do the same in a model test. We already have a different system test to check that the price isn't displayed in the view. --- spec/models/budget/result_spec.rb | 15 +++++++++++++++ spec/system/budgets/results_spec.rb | 21 --------------------- 2 files changed, 15 insertions(+), 21 deletions(-) diff --git a/spec/models/budget/result_spec.rb b/spec/models/budget/result_spec.rb index 7a02ede50..ade4de5e9 100644 --- a/spec/models/budget/result_spec.rb +++ b/spec/models/budget/result_spec.rb @@ -83,5 +83,20 @@ describe Budget::Result do expect(heading.investments.winners.pluck(:ballot_lines_count)).to match_array([900, 800, 700]) end end + + context "budget with the hide money option" do + before { budget.update!(voting_style: "approval", hide_money: true) } + + it "does not take the price into account" do + create(:budget_investment, :selected, heading: heading, price: 100, ballot_lines_count: 500) + create(:budget_investment, :incompatible, heading: heading, price: 300, ballot_lines_count: 800) + create(:budget_investment, :selected, heading: heading, price: 800, ballot_lines_count: 700) + create(:budget_investment, :selected, heading: heading, price: 500, ballot_lines_count: 600) + + Budget::Result.new(budget, heading).calculate_winners + + expect(heading.investments.winners.pluck(:ballot_lines_count)).to match_array([700, 600, 500]) + end + end end end diff --git a/spec/system/budgets/results_spec.rb b/spec/system/budgets/results_spec.rb index e20654ab7..3cf54a777 100644 --- a/spec/system/budgets/results_spec.rb +++ b/spec/system/budgets/results_spec.rb @@ -81,27 +81,6 @@ describe "Results" do expect(page).not_to have_content "€" end - scenario "Does not have in account the price on hide money budgets" do - budget.update!(voting_style: "approval", hide_money: true) - heading.update!(price: 0) - - inv1 = create(:budget_investment, :selected, heading: heading, price: 2000, ballot_lines_count: 1000) - inv2 = create(:budget_investment, :selected, heading: heading, price: 5000, ballot_lines_count: 1000) - - Budget::Result.new(budget, heading).calculate_winners - - visit budget_path(budget) - click_link "See results" - - expect(page).to have_content inv1.title - expect(page).to have_content inv2.title - expect(page).not_to have_content inv1.price - expect(page).not_to have_content inv2.price - expect(page).not_to have_content "Price" - expect(page).not_to have_content "Available budget" - expect(page).not_to have_content "€" - end - scenario "Does not raise error if budget (slug or id) is not found" do visit budget_results_path("wrong budget")