Manage the render of the price field on budgets results section

This commit is contained in:
decabeza
2022-02-03 10:48:50 +01:00
committed by taitus
parent 5d475e6401
commit 4c0499d53b
3 changed files with 61 additions and 18 deletions

View File

@@ -9,11 +9,15 @@ class Budget
def calculate_winners
reset_winners
if @budget.hide_money?
investments.compatible.update_all(winner: true)
else
investments.compatible.each do |investment|
@current_investment = investment
set_winner if inside_budget?
end
end
end
def investments
heading.investments.selected.sort_by_ballots

View File

@@ -13,6 +13,7 @@
<th scope="col" class="text-center">
<%= t("budgets.results.ballot_lines_count") %>
</th>
<% if @budget.show_money? %>
<th scope="col" class="text-center">
<%= t("budgets.results.price") %>
</th>
@@ -22,6 +23,7 @@
<%= @budget.formatted_amount(heading_price) %><br>
</th>
<% end %>
<% end %>
</tr>
</thead>
@@ -50,6 +52,7 @@
<td class="text-center">
<%= investment.ballot_lines_count %>
</td>
<% if @budget.show_money? %>
<td class="text-center">
<%= @budget.formatted_amount(investment.price) %>
</td>
@@ -60,6 +63,7 @@
<% amount_available -= investment.price if investment.winner? %>
</td>
<% end %>
<% end %>
</tr>
<% end %>
</tbody>

View File

@@ -67,6 +67,41 @@ describe "Results" do
end
end
scenario "Does not show price and available budget when hide money" do
budget.update!(voting_style: "approval", hide_money: true)
visit budget_path(budget)
click_link "See results"
expect(page).to have_content investment1.title
expect(page).to have_content investment2.title
expect(page).not_to have_content investment1.price
expect(page).not_to have_content investment2.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 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")