From 2c529e71cdadd5f87fde184ada3955fc720775ef Mon Sep 17 00:00:00 2001 From: Pedro Moreira Date: Sat, 7 Nov 2020 16:28:41 +0000 Subject: [PATCH] Only display judge names if Casa org has judges This ensures the "Select Judge" dropdown is not displayed when editing/creating cases belonging to a Casa org that has no Judges assigned. --- app/views/casa_cases/_form.html.erb | 24 ++++++++++++----------- spec/system/supervisor_edits_case_spec.rb | 20 +++++++++++++++++++ 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/app/views/casa_cases/_form.html.erb b/app/views/casa_cases/_form.html.erb index f545567e2d..b0d3e440d1 100644 --- a/app/views/casa_cases/_form.html.erb +++ b/app/views/casa_cases/_form.html.erb @@ -25,17 +25,19 @@ <% end %> - <% if policy(casa_case).update_judge? %> -
- <%= form.label :judge_id %> - <%= form.collection_select( - :judge_id, - Judge.for_organization(current_organization), - :id, :name, - { include_hidden: false, prompt: "-Select Judge-" }, - { class: "form-control" } - ) %> -
+ <% if Judge.for_organization(current_organization).any? %> + <% if policy(casa_case).update_judge? %> +
+ <%= form.label :judge_id %> + <%= form.collection_select( + :judge_id, + Judge.for_organization(current_organization), + :id, :name, + { include_hidden: false, prompt: "-Select Judge-" }, + { class: "form-control" } + ) %> +
+ <% end %> <% end %>
diff --git a/spec/system/supervisor_edits_case_spec.rb b/spec/system/supervisor_edits_case_spec.rb index 12f82d5fd2..54c13cc605 100644 --- a/spec/system/supervisor_edits_case_spec.rb +++ b/spec/system/supervisor_edits_case_spec.rb @@ -96,4 +96,24 @@ expect(page).not_to have_text("Reactivate Case") expect(page).not_to have_text("Update Casa Case") end + + context "When a Casa instance has no judge names added" do + it "does not display judge names details" do + casa_case = create(:casa_case, casa_org: casa_org, judge: nil) + + visit edit_casa_case_path(casa_case) + + expect(page).not_to have_select("Judge") + end + end + + context "When an admin has added judge names to a Casa instance" do + it "displays judge details as select option" do + judge = create :judge, casa_org: casa_org + + visit edit_casa_case_path(casa_case) + + expect(page).to have_select("Judge") + end + end end