diff --git a/app/policies/casa_case_policy.rb b/app/policies/casa_case_policy.rb index 25e6e83800..9c831ded7e 100644 --- a/app/policies/casa_case_policy.rb +++ b/app/policies/casa_case_policy.rb @@ -9,12 +9,12 @@ def initialize(user, scope) def resolve case @user - when CasaAdmin, Supervisor - scope.by_organization(@user.casa_org) - when Volunteer - scope.actively_assigned_to(user) - else - raise "unrecognized user type #{@user.type}" + when CasaAdmin, Supervisor + scope.by_organization(@user.casa_org) + when Volunteer + scope.actively_assigned_to(user) + else + raise "unrecognized user type #{@user.type}" end end end @@ -43,11 +43,11 @@ def can_see_filters? alias_method :update_case_number?, :is_admin? alias_method :update_case_status?, :is_admin? - alias_method :update_court_date?, :admin_or_supervisor? - alias_method :update_hearing_type?, :admin_or_supervisor? - alias_method :update_judge?, :admin_or_supervisor? - alias_method :update_court_report_due_date?, :admin_or_supervisor? - alias_method :update_court_mandates?, :admin_or_supervisor? + alias_method :update_court_date?, :admin_or_supervisor_or_volunteer? + alias_method :update_hearing_type?, :admin_or_supervisor_or_volunteer? + alias_method :update_judge?, :admin_or_supervisor_or_volunteer? + alias_method :update_court_report_due_date?, :admin_or_supervisor_or_volunteer? + alias_method :update_court_mandates?, :admin_or_supervisor_or_volunteer? def permitted_attributes common_attrs = [ @@ -57,14 +57,14 @@ def permitted_attributes ] case @user - when CasaAdmin - common_attrs.concat(%i[case_number birth_month_year_youth court_date court_report_due_date hearing_type_id judge_id]) - common_attrs << case_court_mandates_attributes - when Supervisor - common_attrs.concat(%i[court_date court_report_due_date hearing_type_id judge_id]) - common_attrs << case_court_mandates_attributes - else - common_attrs + when CasaAdmin + common_attrs.concat(%i[case_number birth_month_year_youth court_date court_report_due_date hearing_type_id judge_id]) + common_attrs << case_court_mandates_attributes + when Supervisor, Volunteer + common_attrs.concat(%i[court_date court_report_due_date hearing_type_id judge_id]) + common_attrs << case_court_mandates_attributes + else + common_attrs end end diff --git a/spec/policies/casa_case_policy_spec.rb b/spec/policies/casa_case_policy_spec.rb index 3da5a57f08..e342b2c4e9 100644 --- a/spec/policies/casa_case_policy_spec.rb +++ b/spec/policies/casa_case_policy_spec.rb @@ -40,28 +40,28 @@ end context "when user is a volunteer" do - it "does not allow update" do - is_expected.not_to permit(volunteer, casa_case) + it "allows to update" do + is_expected.to permit(volunteer, casa_case) end end end - permissions :update_birth_month_year_youth? do + permissions :update_hearing_type?, :update_judge?, :update_court_mandates? do context "when user is an admin" do - it "allow update" do + it "allows to update" do is_expected.to permit(casa_admin, casa_case) end end context "when user is a supervisor" do - it "does not allow update" do - is_expected.not_to permit(supervisor, casa_case) + it "allows to update" do + is_expected.to permit(supervisor, casa_case) end end context "when user is a volunteer" do - it "does not allow update" do - is_expected.not_to permit(volunteer, casa_case) + it "allows to update" do + is_expected.to permit(volunteer, casa_case) end end end diff --git a/spec/requests/casa_cases_spec.rb b/spec/requests/casa_cases_spec.rb index ca32f68220..c319793f23 100644 --- a/spec/requests/casa_cases_spec.rb +++ b/spec/requests/casa_cases_spec.rb @@ -387,9 +387,9 @@ # Not permitted expect(casa_case.case_number).to eq "111" - expect(casa_case.hearing_type).to_not eq hearing_type - expect(casa_case.judge).to_not eq judge - expect(casa_case.case_court_mandates.size).to be 0 + expect(casa_case.hearing_type).to eq hearing_type + expect(casa_case.judge).to eq judge + expect(casa_case.case_court_mandates.size).to be 2 end it "redirects to the casa_case" do diff --git a/spec/system/casa_cases/edit_spec.rb b/spec/system/casa_cases/edit_spec.rb index 40676de0c6..ca2a738242 100644 --- a/spec/system/casa_cases/edit_spec.rb +++ b/spec/system/casa_cases/edit_spec.rb @@ -518,12 +518,12 @@ def sign_in_and_assign_volunteer click_on "Update CASA Case" end - expect(page).not_to have_text("Day") - expect(page).not_to have_text("Month") - expect(page).not_to have_text("Year") + expect(page).to have_text("Day") + expect(page).to have_text("Month") + expect(page).to have_text("Year") expect(page).not_to have_text("Deactivate Case") - expect(page).not_to have_css("#add-mandate-button") + expect(page).to have_css("#add-mandate-button") visit casa_case_path(casa_case) expect(page).to have_text("Court Report Status: Submitted")