From c8827f5c7f147d71148af3a160a3bf55c97e09e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Mon, 23 Aug 2021 22:30:45 +0200 Subject: [PATCH] Hide max votable field on single heading budgets IMHO selecting in how many headings it's possible to support investments isn't necessary when there's only one option to choose from. It's obvious that if there's only one heading, it will be impossible to select investments from more than one heading. --- app/models/budget/group.rb | 4 ++++ app/views/admin/budget_groups/_form.html.erb | 2 +- spec/system/admin/budget_groups_spec.rb | 15 ++++++++++++--- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/app/models/budget/group.rb b/app/models/budget/group.rb index 22138b04a..9ca141725 100644 --- a/app/models/budget/group.rb +++ b/app/models/budget/group.rb @@ -30,6 +30,10 @@ class Budget all.sort_by(&:name) end + def multiple_headings? + headings.size > 1 + end + private def generate_slug? diff --git a/app/views/admin/budget_groups/_form.html.erb b/app/views/admin/budget_groups/_form.html.erb index 1f8031df9..8c18c9999 100644 --- a/app/views/admin/budget_groups/_form.html.erb +++ b/app/views/admin/budget_groups/_form.html.erb @@ -11,7 +11,7 @@ <% end %> - <% if group.persisted? && group.headings.any? %> + <% if group.multiple_headings? %>
<%= f.select :max_votable_headings, (1..group.headings.count), diff --git a/spec/system/admin/budget_groups_spec.rb b/spec/system/admin/budget_groups_spec.rb index d70d2d1ee..ac0010afa 100644 --- a/spec/system/admin/budget_groups_spec.rb +++ b/spec/system/admin/budget_groups_spec.rb @@ -129,14 +129,23 @@ describe "Admin budget groups", :admin do expect(page).to have_field "Maximum number of headings in which a user can select projects", with: "2" end - describe "Select for maxium number of headings to select projects" do - scenario "is present if there are headings in the group" do + describe "Select for maximum number of headings to select projects" do + scenario "is present if there are several headings in the group" do + group = create(:budget_group, budget: budget) + 2.times { create(:budget_heading, group: group) } + + visit edit_admin_budget_group_path(budget, group) + + expect(page).to have_field "Maximum number of headings in which a user can select projects" + end + + scenario "is not present if there's only one heading in the group" do group = create(:budget_group, budget: budget) create(:budget_heading, group: group) visit edit_admin_budget_group_path(budget, group) - expect(page).to have_field "Maximum number of headings in which a user can select projects" + expect(page).not_to have_field "Maximum number of headings in which a user can select projects" end scenario "is not present if there are no headings in the group" do