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.
This commit is contained in:
@@ -83,5 +83,20 @@ describe Budget::Result do
|
|||||||
expect(heading.investments.winners.pluck(:ballot_lines_count)).to match_array([900, 800, 700])
|
expect(heading.investments.winners.pluck(:ballot_lines_count)).to match_array([900, 800, 700])
|
||||||
end
|
end
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -81,27 +81,6 @@ describe "Results" do
|
|||||||
expect(page).not_to have_content "€"
|
expect(page).not_to have_content "€"
|
||||||
end
|
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
|
scenario "Does not raise error if budget (slug or id) is not found" do
|
||||||
visit budget_results_path("wrong budget")
|
visit budget_results_path("wrong budget")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user