From cf5681588eca3836a2ad91d4ca449c86f476cbbc Mon Sep 17 00:00:00 2001 From: Dalma Boros Date: Sun, 14 Jul 2024 20:29:12 -0500 Subject: [PATCH] Create create_default_standard_court_orders_service.rb --- app/models/case_court_order.rb | 5 --- ...e_default_standard_court_orders_service.rb | 37 +++++++++++++++++++ ..._create_default_standard_court_orders.rake | 37 +------------------ spec/models/case_court_order_spec.rb | 8 ---- ...ault_standard_court_orders_service_spec.rb | 19 ++++++++++ 5 files changed, 57 insertions(+), 49 deletions(-) create mode 100644 app/services/deployment/create_default_standard_court_orders_service.rb create mode 100644 spec/services/deployment/create_default_standard_court_orders_service_spec.rb diff --git a/app/models/case_court_order.rb b/app/models/case_court_order.rb index 54fcd3ce6c..df83780eeb 100644 --- a/app/models/case_court_order.rb +++ b/app/models/case_court_order.rb @@ -8,11 +8,6 @@ class CaseCourtOrder < ApplicationRecord enum implementation_status: IMPLEMENTATION_STATUSES - # TODO: assess what we're doing with this method - def self.court_order_options - STANDARD_COURT_ORDERS.map { |o| [o, o] } - end - def implementation_status_symbol case implementation_status when "implemented" diff --git a/app/services/deployment/create_default_standard_court_orders_service.rb b/app/services/deployment/create_default_standard_court_orders_service.rb new file mode 100644 index 0000000000..45ff525579 --- /dev/null +++ b/app/services/deployment/create_default_standard_court_orders_service.rb @@ -0,0 +1,37 @@ +module Deployment + class CreateDefaultStandardCourtOrdersService + DEFAULT_STANDARD_COURT_ORDERS = [ + "Birth certificate for the Respondent’s", + "Domestic Violence Education/Group", + "Educational monitoring for the Respondent", + "Educational or Vocational referrals", + "Family therapy", + "Housing support for the [parent]", + "Independent living skills classes or workshops", + "Individual therapy for the [parent]", + "Individual therapy for the Respondent", + "Learners’ permit for the Respondent, drivers’ education and driving hours when needed", + "No contact with (mother, father, other guardian)", + "Parenting Classes (mother, father, other guardian)", + "Psychiatric Evaluation and follow all recommendations (child, mother, father, other guardian)", + "Substance abuse assessment for the [parent]", + "Substance Abuse Evaluation and follow all recommendations (child, mother, father, other guardian)", + "Substance Abuse Treatment (child, mother, father, other guardian)", + "Supervised visits", + "Supervised visits at DSS", + "Therapy (child, mother, father, other guardian)", + "Tutor for the Respondent", + "Urinalysis (child, mother, father, other guardian)", + "Virtual Visits", + "Visitation assistance for the Respondent to see [family]" + ].freeze + + def create_defaults + CasaOrg.all.each do |casa_org| + DEFAULT_STANDARD_COURT_ORDERS.each do |order| + StandardCourtOrder.create(value: order, casa_org: casa_org) + end + end + end + end +end \ No newline at end of file diff --git a/lib/tasks/deployment/20240708014020_create_default_standard_court_orders.rake b/lib/tasks/deployment/20240708014020_create_default_standard_court_orders.rake index 5b5b65ec89..18b11f30bf 100644 --- a/lib/tasks/deployment/20240708014020_create_default_standard_court_orders.rake +++ b/lib/tasks/deployment/20240708014020_create_default_standard_court_orders.rake @@ -4,46 +4,11 @@ namespace :after_party do puts "Running deploy task 'create_default_standard_court_orders'" # Put your task implementation HERE. - default_standard_court_orders = [ - "Birth certificate for the Respondent’s", - "Domestic Violence Education/Group", - "Educational monitoring for the Respondent", - "Educational or Vocational referrals", - "Family therapy", - "Housing support for the [parent]", - "Independent living skills classes or workshops", - "Individual therapy for the [parent]", - "Individual therapy for the Respondent", - "Learners’ permit for the Respondent, drivers’ education and driving hours when needed", - "No contact with (mother, father, other guardian)", - "Parenting Classes (mother, father, other guardian)", - "Psychiatric Evaluation and follow all recommendations (child, mother, father, other guardian)", - "Substance abuse assessment for the [parent]", - "Substance Abuse Evaluation and follow all recommendations (child, mother, father, other guardian)", - "Substance Abuse Treatment (child, mother, father, other guardian)", - "Supervised visits", - "Supervised visits at DSS", - "Therapy (child, mother, father, other guardian)", - "Tutor for the Respondent", - "Urinalysis (child, mother, father, other guardian)", - "Virtual Visits", - "Visitation assistance for the Respondent to see [family]" - ].freeze - - CasaOrg.all.each do |casa_org| - create_default_standard_court_orders(casa_org, default_standard_court_orders) - end + Deployment::CreateDefaultStandardCourtOrdersService.new.create_defaults # Update task as completed. If you remove the line below, the task will # run with every deploy (or every time you call after_party:run). AfterParty::TaskRecord .create version: AfterParty::TaskRecorder.new(__FILE__).timestamp end - - # TODO: tests!?! - def create_default_standard_court_orders(casa_org, default_standard_court_orders) - default_standard_court_orders.each do |order| - StandardCourtOrder.create(value: order, casa_org: casa_org) - end - end end diff --git a/spec/models/case_court_order_spec.rb b/spec/models/case_court_order_spec.rb index 0b5d1aea72..5a72db73a4 100644 --- a/spec/models/case_court_order_spec.rb +++ b/spec/models/case_court_order_spec.rb @@ -6,12 +6,4 @@ it { is_expected.to belong_to(:casa_case) } it { is_expected.to validate_presence_of(:text) } - - describe ".court_order_options" do - it "returns standard court order options" do - expect(described_class.court_order_options.count).to eq(23) - expect(described_class.court_order_options).to be_an(Array) - expect(described_class.court_order_options).to all be_an(Array) - end - end end diff --git a/spec/services/deployment/create_default_standard_court_orders_service_spec.rb b/spec/services/deployment/create_default_standard_court_orders_service_spec.rb new file mode 100644 index 0000000000..375d7b219f --- /dev/null +++ b/spec/services/deployment/create_default_standard_court_orders_service_spec.rb @@ -0,0 +1,19 @@ +require "rails_helper" + +RSpec.describe Deployment::CreateDefaultStandardCourtOrdersService do + describe "#create_defaults" do + let!(:casa_org_1) { create(:casa_org) } + let!(:casa_org_2) { create(:casa_org) } + + it 'creates StandardCourtOrders from DEFAULT_STANDARD_COURT_ORDERS for each org' do + stub_const("Deployment::CreateDefaultStandardCourtOrdersService::DEFAULT_STANDARD_COURT_ORDERS", + ["Default 1", "Default 2"]) + + described_class.new.create_defaults + + expect(StandardCourtOrder.count).to eq(4) + expect(casa_org_1.standard_court_orders.map(&:value)).to eq(["Default 1", "Default 2"]) + expect(casa_org_2.standard_court_orders.map(&:value)).to eq(["Default 1", "Default 2"]) + end + end +end \ No newline at end of file