Manage the render of the price field on budgets results section
This commit is contained in:
@@ -9,9 +9,13 @@ class Budget
|
||||
|
||||
def calculate_winners
|
||||
reset_winners
|
||||
investments.compatible.each do |investment|
|
||||
@current_investment = investment
|
||||
set_winner if inside_budget?
|
||||
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
|
||||
|
||||
|
||||
@@ -13,14 +13,16 @@
|
||||
<th scope="col" class="text-center">
|
||||
<%= t("budgets.results.ballot_lines_count") %>
|
||||
</th>
|
||||
<th scope="col" class="text-center">
|
||||
<%= t("budgets.results.price") %>
|
||||
</th>
|
||||
<% if results_type == :compatible %>
|
||||
<th scope="col" class="text-right">
|
||||
<small><%= t("budgets.results.amount_available") %></small><br>
|
||||
<%= @budget.formatted_amount(heading_price) %><br>
|
||||
<% if @budget.show_money? %>
|
||||
<th scope="col" class="text-center">
|
||||
<%= t("budgets.results.price") %>
|
||||
</th>
|
||||
<% if results_type == :compatible %>
|
||||
<th scope="col" class="text-right">
|
||||
<small><%= t("budgets.results.amount_available") %></small><br>
|
||||
<%= @budget.formatted_amount(heading_price) %><br>
|
||||
</th>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</tr>
|
||||
</thead>
|
||||
@@ -50,15 +52,17 @@
|
||||
<td class="text-center">
|
||||
<%= investment.ballot_lines_count %>
|
||||
</td>
|
||||
<td class="text-center">
|
||||
<%= @budget.formatted_amount(investment.price) %>
|
||||
</td>
|
||||
<% if results_type == :compatible %>
|
||||
<td class="small text-right"
|
||||
title="<%= @budget.formatted_amount(amount_available) %> - <%= @budget.formatted_amount(investment.price) %>">
|
||||
<%= @budget.formatted_amount(amount_available - investment.price) %>
|
||||
<% amount_available -= investment.price if investment.winner? %>
|
||||
<% if @budget.show_money? %>
|
||||
<td class="text-center">
|
||||
<%= @budget.formatted_amount(investment.price) %>
|
||||
</td>
|
||||
<% if results_type == :compatible %>
|
||||
<td class="small text-right"
|
||||
title="<%= @budget.formatted_amount(amount_available) %> - <%= @budget.formatted_amount(investment.price) %>">
|
||||
<%= @budget.formatted_amount(amount_available - investment.price) %>
|
||||
<% amount_available -= investment.price if investment.winner? %>
|
||||
</td>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</tr>
|
||||
<% end %>
|
||||
|
||||
@@ -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")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user