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
|
def calculate_winners
|
||||||
reset_winners
|
reset_winners
|
||||||
investments.compatible.each do |investment|
|
if @budget.hide_money?
|
||||||
@current_investment = investment
|
investments.compatible.update_all(winner: true)
|
||||||
set_winner if inside_budget?
|
else
|
||||||
|
investments.compatible.each do |investment|
|
||||||
|
@current_investment = investment
|
||||||
|
set_winner if inside_budget?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -13,14 +13,16 @@
|
|||||||
<th scope="col" class="text-center">
|
<th scope="col" class="text-center">
|
||||||
<%= t("budgets.results.ballot_lines_count") %>
|
<%= t("budgets.results.ballot_lines_count") %>
|
||||||
</th>
|
</th>
|
||||||
<th scope="col" class="text-center">
|
<% if @budget.show_money? %>
|
||||||
<%= t("budgets.results.price") %>
|
<th scope="col" class="text-center">
|
||||||
</th>
|
<%= t("budgets.results.price") %>
|
||||||
<% 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>
|
</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 %>
|
<% end %>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@@ -50,15 +52,17 @@
|
|||||||
<td class="text-center">
|
<td class="text-center">
|
||||||
<%= investment.ballot_lines_count %>
|
<%= investment.ballot_lines_count %>
|
||||||
</td>
|
</td>
|
||||||
<td class="text-center">
|
<% if @budget.show_money? %>
|
||||||
<%= @budget.formatted_amount(investment.price) %>
|
<td class="text-center">
|
||||||
</td>
|
<%= @budget.formatted_amount(investment.price) %>
|
||||||
<% 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>
|
</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 %>
|
<% end %>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -67,6 +67,41 @@ describe "Results" do
|
|||||||
end
|
end
|
||||||
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
|
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