Manage the render of the price field on admin budget headings

Avoid displaying the price in admin budget headings section
and avoid fill the field 'price' in admin budget headings form
when the budget has been checked with hide_money field.
This commit is contained in:
decabeza
2022-02-02 13:19:08 +01:00
committed by taitus
parent 80e64590b7
commit 9fb5019f0f
6 changed files with 38 additions and 3 deletions

View File

@@ -4,7 +4,9 @@
<thead> <thead>
<tr> <tr>
<th><%= Budget::Heading.human_attribute_name(:name) %></th> <th><%= Budget::Heading.human_attribute_name(:name) %></th>
<th><%= Budget::Heading.human_attribute_name(:price) %></th> <% if budget.show_money? %>
<th class="text-center"><%= Budget::Heading.human_attribute_name(:price) %></th>
<% end %>
<% if budget.approval_voting? %> <% if budget.approval_voting? %>
<th><%= Budget::Heading.human_attribute_name(:max_ballot_lines) %></th> <th><%= Budget::Heading.human_attribute_name(:max_ballot_lines) %></th>
<% end %> <% end %>
@@ -15,7 +17,9 @@
<% headings.each do |heading| %> <% headings.each do |heading| %>
<tr id="<%= dom_id(heading) %>" class="heading"> <tr id="<%= dom_id(heading) %>" class="heading">
<td><%= heading.name %></td> <td><%= heading.name %></td>
<% if budget.show_money? %>
<td><%= budget.formatted_heading_price(heading) %></td> <td><%= budget.formatted_heading_price(heading) %></td>
<% end %>
<% if budget.approval_voting? %> <% if budget.approval_voting? %>
<td><%= heading.max_ballot_lines %></td> <td><%= heading.max_ballot_lines %></td>
<% end %> <% end %>

View File

@@ -230,6 +230,10 @@ class Budget < ApplicationRecord
voting_style == "approval" voting_style == "approval"
end end
def show_money?
!hide_money?
end
private private
def generate_phases def generate_phases

View File

@@ -12,7 +12,11 @@
<% end %> <% end %>
<div class="small-12 medium-6"> <div class="small-12 medium-6">
<% if @budget.show_money? %>
<%= f.text_field :price, maxlength: 8 %> <%= f.text_field :price, maxlength: 8 %>
<% else %>
<%= f.hidden_field :price, value: 0 %>
<% end %>
<% if heading.budget.approval_voting? %> <% if heading.budget.approval_voting? %>
<%= f.number_field :max_ballot_lines, <%= f.number_field :max_ballot_lines,

View File

@@ -333,6 +333,12 @@ describe Budget::Heading do
end end
end end
describe "price" do
it "can't be blank" do
expect(build(:budget_heading, group: group, price: nil)).not_to be_valid
end
end
describe "#name_scoped_by_group" do describe "#name_scoped_by_group" do
it "returns heading name in budgets with a single heading" do it "returns heading name in budgets with a single heading" do
heading = create(:budget_heading, group: group, name: "One and only") heading = create(:budget_heading, group: group, name: "One and only")

View File

@@ -123,6 +123,19 @@ describe "Admin budget headings", :admin do
expect(page).to have_content "can't be blank" expect(page).to have_content "can't be blank"
end end
scenario "Heading money field is hidden if hide money is true" do
budget_hide_money = create(:budget, :hide_money)
group = create(:budget_group, budget: budget_hide_money)
visit new_admin_budget_group_heading_path(budget_hide_money, group)
fill_in "Heading name", with: "Heading without money"
click_button "Create new heading"
expect(page).to have_content "Heading created successfully!"
expect(page).not_to have_content "Money amount"
end
describe "Max votes is optional" do describe "Max votes is optional" do
scenario "do no show max_ballot_lines field for knapsack budgets" do scenario "do no show max_ballot_lines field for knapsack budgets" do
visit new_admin_budget_group_heading_path(budget, group) visit new_admin_budget_group_heading_path(budget, group)

View File

@@ -161,6 +161,8 @@ describe "Admin budgets", :admin do
expect(page).to have_content "All city" expect(page).to have_content "All city"
expect(page).to have_link "Continue to phases" expect(page).to have_link "Continue to phases"
expect(page).not_to have_content "There are no headings." expect(page).not_to have_content "There are no headings."
expect(page).not_to have_content "Money amount"
expect(page).not_to have_content ""
end end
end end
@@ -341,6 +343,8 @@ describe "Admin budgets", :admin do
expect(page).to have_content heading.name expect(page).to have_content heading.name
expect(page).to have_content heading_2.name expect(page).to have_content heading_2.name
expect(page).not_to have_content "Money amount"
expect(page).not_to have_content ""
visit edit_admin_budget_path(budget_hide_money) visit edit_admin_budget_path(budget_hide_money)