Manage the render of the price field on budgets results section
This commit is contained in:
@@ -9,11 +9,15 @@ class Budget
|
|||||||
|
|
||||||
def calculate_winners
|
def calculate_winners
|
||||||
reset_winners
|
reset_winners
|
||||||
|
if @budget.hide_money?
|
||||||
|
investments.compatible.update_all(winner: true)
|
||||||
|
else
|
||||||
investments.compatible.each do |investment|
|
investments.compatible.each do |investment|
|
||||||
@current_investment = investment
|
@current_investment = investment
|
||||||
set_winner if inside_budget?
|
set_winner if inside_budget?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def investments
|
def investments
|
||||||
heading.investments.selected.sort_by_ballots
|
heading.investments.selected.sort_by_ballots
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
<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>
|
||||||
|
<% if @budget.show_money? %>
|
||||||
<th scope="col" class="text-center">
|
<th scope="col" class="text-center">
|
||||||
<%= t("budgets.results.price") %>
|
<%= t("budgets.results.price") %>
|
||||||
</th>
|
</th>
|
||||||
@@ -22,6 +23,7 @@
|
|||||||
<%= @budget.formatted_amount(heading_price) %><br>
|
<%= @budget.formatted_amount(heading_price) %><br>
|
||||||
</th>
|
</th>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
<% end %>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
|
||||||
@@ -50,6 +52,7 @@
|
|||||||
<td class="text-center">
|
<td class="text-center">
|
||||||
<%= investment.ballot_lines_count %>
|
<%= investment.ballot_lines_count %>
|
||||||
</td>
|
</td>
|
||||||
|
<% if @budget.show_money? %>
|
||||||
<td class="text-center">
|
<td class="text-center">
|
||||||
<%= @budget.formatted_amount(investment.price) %>
|
<%= @budget.formatted_amount(investment.price) %>
|
||||||
</td>
|
</td>
|
||||||
@@ -60,6 +63,7 @@
|
|||||||
<% amount_available -= investment.price if investment.winner? %>
|
<% amount_available -= investment.price if investment.winner? %>
|
||||||
</td>
|
</td>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
<% end %>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
@@ -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