diff --git a/app/controllers/casa_org_controller.rb b/app/controllers/casa_org_controller.rb
index 16bc3d7701..a94445659e 100644
--- a/app/controllers/casa_org_controller.rb
+++ b/app/controllers/casa_org_controller.rb
@@ -7,6 +7,7 @@ class CasaOrgController < ApplicationController
before_action :set_learning_hour_topics, only: %i[edit update]
before_action :set_sent_emails, only: %i[edit update]
before_action :set_contact_topics, only: %i[edit update]
+ before_action :set_standard_court_orders, only: %i[edit update]
before_action :require_organization!
after_action :verify_authorized
before_action :set_active_storage_url_options, only: %i[edit update]
@@ -90,6 +91,10 @@ def set_contact_topics
@contact_topics = @casa_org.contact_topics.where(soft_delete: false)
end
+ def set_standard_court_orders
+ @standard_court_orders = @casa_org.standard_court_orders
+ end
+
def set_active_storage_url_options
ActiveStorage::Current.url_options = {host: request.base_url}
end
diff --git a/app/controllers/standard_court_orders_controller.rb b/app/controllers/standard_court_orders_controller.rb
new file mode 100644
index 0000000000..bf31789711
--- /dev/null
+++ b/app/controllers/standard_court_orders_controller.rb
@@ -0,0 +1,52 @@
+class StandardCourtOrdersController < ApplicationController
+ before_action :set_standard_court_order, only: %i[edit update destroy]
+ after_action :verify_authorized
+
+ def new
+ authorize StandardCourtOrder
+ standard_court_order = StandardCourtOrder.new(casa_org_id: current_user.casa_org_id)
+ @standard_court_order = standard_court_order
+ end
+
+ def edit
+ authorize @standard_court_order
+ end
+
+ def create
+ authorize StandardCourtOrder
+ @standard_court_order = StandardCourtOrder.new(standard_court_order_params)
+
+ if @standard_court_order.save
+ redirect_to edit_casa_org_path(current_organization), notice: "Standard court order was successfully created."
+ else
+ render :new, status: :unprocessable_entity
+ end
+ end
+
+ def update
+ authorize @standard_court_order
+
+ if @standard_court_order.update(standard_court_order_params)
+ redirect_to edit_casa_org_path(current_organization), notice: "Standard court order was successfully updated."
+ else
+ render :edit, status: :unprocessable_entity
+ end
+ end
+
+ def destroy
+ authorize @standard_court_order
+
+ @standard_court_order.destroy
+ redirect_to edit_casa_org_path(current_organization), notice: "Standard court order was successfully deleted."
+ end
+
+ private
+
+ def set_standard_court_order
+ @standard_court_order = StandardCourtOrder.find(params[:id])
+ end
+
+ def standard_court_order_params
+ params.require(:standard_court_order).permit(:casa_org_id, :value)
+ end
+end
diff --git a/app/models/casa_org.rb b/app/models/casa_org.rb
index b5b9c7461c..ab13d35c2e 100644
--- a/app/models/casa_org.rb
+++ b/app/models/casa_org.rb
@@ -26,6 +26,7 @@ class CasaOrg < ApplicationRecord
has_many :learning_hour_topics, dependent: :destroy
has_many :case_groups, dependent: :destroy
has_many :contact_topics
+ has_many :standard_court_orders, dependent: :destroy
has_one_attached :logo
has_one_attached :court_report_template
diff --git a/app/models/case_court_order.rb b/app/models/case_court_order.rb
index 7e41ee9cdc..df83780eeb 100644
--- a/app/models/case_court_order.rb
+++ b/app/models/case_court_order.rb
@@ -1,30 +1,5 @@
class CaseCourtOrder < ApplicationRecord
IMPLEMENTATION_STATUSES = {unimplemented: 1, partially_implemented: 2, implemented: 3}
- 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
belongs_to :casa_case
belongs_to :court_date, optional: true
@@ -33,10 +8,6 @@ class CaseCourtOrder < ApplicationRecord
enum implementation_status: IMPLEMENTATION_STATUSES
- 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/models/standard_court_order.rb b/app/models/standard_court_order.rb
new file mode 100644
index 0000000000..d9bb8b3df1
--- /dev/null
+++ b/app/models/standard_court_order.rb
@@ -0,0 +1,25 @@
+class StandardCourtOrder < ApplicationRecord
+ belongs_to :casa_org
+
+ validates :value, uniqueness: {scope: :casa_org_id, case_sensitive: false}, presence: true
+end
+
+# == Schema Information
+#
+# Table name: standard_court_orders
+#
+# id :bigint not null, primary key
+# value :string
+# created_at :datetime not null
+# updated_at :datetime not null
+# casa_org_id :bigint not null
+#
+# Indexes
+#
+# index_standard_court_orders_on_casa_org_id (casa_org_id)
+# index_standard_court_orders_on_casa_org_id_and_value (casa_org_id,value) UNIQUE
+#
+# Foreign Keys
+#
+# fk_rails_... (casa_org_id => casa_orgs.id)
+#
diff --git a/app/policies/application_policy.rb b/app/policies/application_policy.rb
index 84b43ef090..085e4731a0 100644
--- a/app/policies/application_policy.rb
+++ b/app/policies/application_policy.rb
@@ -55,7 +55,7 @@ def same_org?
case record
when CasaOrg
user.casa_org == record
- when CasaAdmin, CasaCase, Volunteer, Supervisor, HearingType, ContactTypeGroup, ContactTopic
+ when CasaAdmin, CasaCase, Volunteer, Supervisor, HearingType, ContactTypeGroup, ContactTopic, StandardCourtOrder
user.casa_org == record.casa_org
when CourtDate, CaseContact, CaseAssignment
user.casa_org == record&.casa_case&.casa_org
diff --git a/app/policies/standard_court_order_policy.rb b/app/policies/standard_court_order_policy.rb
new file mode 100644
index 0000000000..4a98cf4e01
--- /dev/null
+++ b/app/policies/standard_court_order_policy.rb
@@ -0,0 +1,21 @@
+class StandardCourtOrderPolicy < ApplicationPolicy
+ def create?
+ is_admin_same_org?
+ end
+
+ def new?
+ is_admin_same_org?
+ end
+
+ def update?
+ is_admin_same_org?
+ end
+
+ def edit?
+ is_admin_same_org?
+ end
+
+ def destroy?
+ is_admin_same_org?
+ end
+end
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..545c4c03a2
--- /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
diff --git a/app/views/casa_org/_standard_court_orders.html.erb b/app/views/casa_org/_standard_court_orders.html.erb
new file mode 100644
index 0000000000..305110959f
--- /dev/null
+++ b/app/views/casa_org/_standard_court_orders.html.erb
@@ -0,0 +1,57 @@
+
+
+
+
+
+
Standard Court Orders
+
+
+
+
+ <%= link_to new_standard_court_order_path, class: "btn-sm main-btn primary-btn btn-hover" do %>
+
+ New Standard Court Order
+ <% end %>
+
+
+
+
+
+
+
+
+ Standard Court Order |
+ Actions |
+
+
+
+ <% @standard_court_orders&.each do |standard_court_order| %>
+ <% id = "standard_court_order-#{standard_court_order.id}" %>
+
+
+ <%= standard_court_order.value %>
+ |
+
+ <%= render(DropdownMenuComponent.new(menu_title: "Actions Menu", hide_label: true)) do %>
+ <%= link_to "Edit", edit_standard_court_order_path(standard_court_order), class: "dropdown-item" %>
+ <%= render(Modal::OpenLinkComponent.new(text: "Delete", target: id, klass: "dropdown-item")) %>
+ <% end %>
+ |
+
+ <%= render(Modal::GroupComponent.new(id: id)) do |component| %>
+ <% component.with_header(text: "Delete Standard Court Order?", id: id) %>
+ <% component.with_footer do %>
+ <%= link_to standard_court_order_path(standard_court_order), method: :delete,
+ class: "btn-sm main-btn danger-btn btn-hover ms-auto" do %>
+
+ Delete Standard Court Order
+ <% end %>
+ <% end %>
+ <% end %>
+ <% end %>
+
+
+
+
+
+
diff --git a/app/views/casa_org/edit.html.erb b/app/views/casa_org/edit.html.erb
index d5327109bb..98f6053bbd 100644
--- a/app/views/casa_org/edit.html.erb
+++ b/app/views/casa_org/edit.html.erb
@@ -163,3 +163,17 @@
<%= render "contact_topics" %>
+
+
+
+
+
+ Manage Standard Court Orders
+
+
+
+
+
+
+ <%= render "standard_court_orders" %>
+
diff --git a/app/views/shared/_court_order_list.erb b/app/views/shared/_court_order_list.erb
index be6c26de9a..601c51b700 100644
--- a/app/views/shared/_court_order_list.erb
+++ b/app/views/shared/_court_order_list.erb
@@ -33,7 +33,7 @@
<%= label_tag :selectedCourtOrder, "Court Order Type" %>
<%= select_tag :selectedCourtOrder,
- options_for_select(CaseCourtOrder.court_order_options),
+ options_for_select(current_organization.standard_court_orders.map(&:value)),
{ include_blank: "Create custom court order", data: {court_order_form_target: "selectedCourtOrder"} }
%>
diff --git a/app/views/standard_court_orders/_form.html.erb b/app/views/standard_court_orders/_form.html.erb
new file mode 100644
index 0000000000..7681d04235
--- /dev/null
+++ b/app/views/standard_court_orders/_form.html.erb
@@ -0,0 +1,31 @@
+
+
+
+
+ <%= form_with(model: standard_court_order, local: true) do |form| %>
+ <%= form.hidden_field :casa_org_id %>
+
+ <%= render "/shared/error_messages", resource: standard_court_order %>
+
+
+ <%= form.label :value, "Standard Court Order" %>
+ <%= form.text_field :value, class: "form-control", required: true %>
+
+
+ <%= button_tag(type: "submit", class: "btn-sm main-btn primary-btn btn-hover") do %>
+ Submit
+ <% end %>
+
+ <% end %>
+
+
diff --git a/app/views/standard_court_orders/edit.html.erb b/app/views/standard_court_orders/edit.html.erb
new file mode 100644
index 0000000000..18396f8fa4
--- /dev/null
+++ b/app/views/standard_court_orders/edit.html.erb
@@ -0,0 +1 @@
+<%= render partial: "form", locals: {title: "Standard Court Order", standard_court_order: @standard_court_order} %>
diff --git a/app/views/standard_court_orders/new.html.erb b/app/views/standard_court_orders/new.html.erb
new file mode 100644
index 0000000000..843b1332f0
--- /dev/null
+++ b/app/views/standard_court_orders/new.html.erb
@@ -0,0 +1 @@
+<%= render partial: "form", locals: {title: "New Standard Court Order", standard_court_order: @standard_court_order} %>
diff --git a/config/routes.rb b/config/routes.rb
index 84dcdb1c51..2ed2ee3071 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -138,6 +138,8 @@
delete "soft_delete", on: :member
end
+ resources :standard_court_orders, except: %i[index show]
+
resources :followup_reports, only: :index
resources :placement_reports, only: :index
resources :banners, except: %i[show] do
diff --git a/db/migrate/20240619005250_create_standard_court_orders.rb b/db/migrate/20240619005250_create_standard_court_orders.rb
new file mode 100644
index 0000000000..5ae87acef8
--- /dev/null
+++ b/db/migrate/20240619005250_create_standard_court_orders.rb
@@ -0,0 +1,12 @@
+class CreateStandardCourtOrders < ActiveRecord::Migration[7.1]
+ def change
+ create_table :standard_court_orders do |t|
+ t.string :value
+ t.references :casa_org, null: false, foreign_key: true
+
+ t.timestamps
+ end
+
+ add_index :standard_court_orders, [:casa_org_id, :value], unique: true
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index e4ba1f6685..429ac9b613 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -607,6 +607,15 @@
t.datetime "updated_at", null: false
end
+ create_table "standard_court_orders", force: :cascade do |t|
+ t.string "value"
+ t.bigint "casa_org_id", null: false
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.index ["casa_org_id", "value"], name: "index_standard_court_orders_on_casa_org_id_and_value", unique: true
+ t.index ["casa_org_id"], name: "index_standard_court_orders_on_casa_org_id"
+ end
+
create_table "supervisor_volunteers", force: :cascade do |t|
t.bigint "supervisor_id", null: false
t.bigint "volunteer_id", null: false
@@ -739,6 +748,7 @@
add_foreign_key "preference_sets", "users"
add_foreign_key "sent_emails", "casa_orgs"
add_foreign_key "sent_emails", "users"
+ add_foreign_key "standard_court_orders", "casa_orgs"
add_foreign_key "supervisor_volunteers", "users", column: "supervisor_id"
add_foreign_key "supervisor_volunteers", "users", column: "volunteer_id"
add_foreign_key "user_reminder_times", "users"
diff --git a/lib/tasks/deployment/20240708014020_create_default_standard_court_orders.rake b/lib/tasks/deployment/20240708014020_create_default_standard_court_orders.rake
new file mode 100644
index 0000000000..36b3d75f01
--- /dev/null
+++ b/lib/tasks/deployment/20240708014020_create_default_standard_court_orders.rake
@@ -0,0 +1,14 @@
+namespace :after_party do
+ desc "Deployment task: Create default standard court orders for every CASA org"
+ task create_default_standard_court_orders: :environment do
+ puts "Running deploy task 'create_default_standard_court_orders'"
+
+ # Put your task implementation HERE.
+ 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
+end
diff --git a/spec/factories/standard_court_orders.rb b/spec/factories/standard_court_orders.rb
new file mode 100644
index 0000000000..f30869ded2
--- /dev/null
+++ b/spec/factories/standard_court_orders.rb
@@ -0,0 +1,6 @@
+FactoryBot.define do
+ factory :standard_court_order do
+ value { "Some standard court order" }
+ casa_org { CasaOrg.first || create(:casa_org) }
+ end
+end
diff --git a/spec/models/casa_org_spec.rb b/spec/models/casa_org_spec.rb
index b9edef03e5..9e2cdbdbb0 100644
--- a/spec/models/casa_org_spec.rb
+++ b/spec/models/casa_org_spec.rb
@@ -12,6 +12,7 @@
it { is_expected.to have_one_attached(:logo) }
it { is_expected.to have_one_attached(:court_report_template) }
it { is_expected.to have_many(:contact_topics) }
+ it { is_expected.to have_many(:standard_court_orders).dependent(:destroy) }
it "has unique name" do
org = create(:casa_org)
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/models/standard_court_order_spec.rb b/spec/models/standard_court_order_spec.rb
new file mode 100644
index 0000000000..dba734ed2e
--- /dev/null
+++ b/spec/models/standard_court_order_spec.rb
@@ -0,0 +1,22 @@
+require "rails_helper"
+
+RSpec.describe StandardCourtOrder, type: :model do
+ describe "associations" do
+ it { is_expected.to belong_to(:casa_org) }
+ end
+
+ describe "validations" do
+ subject { FactoryBot.build(:standard_court_order) }
+
+ it { is_expected.to validate_presence_of(:value) }
+ it { is_expected.to validate_uniqueness_of(:value).scoped_to(:casa_org_id).case_insensitive }
+
+ it "enforces uniqueness via database" do
+ casa_org = create(:casa_org)
+
+ StandardCourtOrder.create(value: "test value", casa_org: casa_org)
+
+ expect { StandardCourtOrder.new(value: "test value", casa_org: casa_org).save!(validates: false) }.to raise_error(ActiveRecord::RecordInvalid)
+ end
+ end
+end
diff --git a/spec/policies/standard_court_order_policy_spec.rb b/spec/policies/standard_court_order_policy_spec.rb
new file mode 100644
index 0000000000..3c06f527ce
--- /dev/null
+++ b/spec/policies/standard_court_order_policy_spec.rb
@@ -0,0 +1,46 @@
+require "rails_helper"
+
+RSpec.describe StandardCourtOrderPolicy do
+ subject { described_class }
+ let(:standard_court_order) { build(:standard_court_order, casa_org: organization) }
+
+ let(:organization) { build(:casa_org) }
+ let(:different_organization) { create(:casa_org) }
+
+ let(:casa_admin) { build(:casa_admin, casa_org: organization) }
+ let(:other_org_casa_admin) { build(:casa_admin, casa_org: different_organization) }
+ let(:volunteer) { build(:volunteer, casa_org: organization) }
+ let(:other_org_volunteer) { build(:volunteer, casa_org: different_organization) }
+ let(:supervisor) { build(:supervisor, casa_org: organization) }
+ let(:other_org_supervisor) { build(:supervisor, casa_org: different_organization) }
+
+ permissions :update?, :create?, :destroy?, :edit?, :new? do
+ context "when part of the same organization" do
+ context "an admin user" do
+ it { is_expected.to permit(casa_admin, standard_court_order) }
+ end
+
+ context "a supervisor" do
+ it { is_expected.to_not permit(supervisor, standard_court_order) }
+ end
+
+ context "a volunteer" do
+ it { is_expected.to_not permit(volunteer, standard_court_order) }
+ end
+ end
+
+ context "when not part of the same organization" do
+ context "an admin user" do
+ it { is_expected.to_not permit(other_org_casa_admin, standard_court_order) }
+ end
+
+ context "a supervisor" do
+ it { is_expected.to_not permit(other_org_supervisor, standard_court_order) }
+ end
+
+ context "a volunteer" do
+ it { is_expected.to_not permit(other_org_volunteer, standard_court_order) }
+ end
+ end
+ end
+end
diff --git a/spec/requests/standard_court_orders_spec.rb b/spec/requests/standard_court_orders_spec.rb
new file mode 100644
index 0000000000..79bc7dff5d
--- /dev/null
+++ b/spec/requests/standard_court_orders_spec.rb
@@ -0,0 +1,217 @@
+require "rails_helper"
+
+RSpec.describe "StandardCourtOrders", type: :request do
+ let(:casa_org) { create(:casa_org) }
+ let(:standard_court_order) { create(:standard_court_order, casa_org:) }
+ let(:attributes) { {casa_org_id: casa_org.id} }
+ let(:admin) { create(:casa_admin, casa_org: casa_org) }
+ let(:supervisor) { create(:supervisor, casa_org: casa_org) }
+ let(:volunteer) { create(:volunteer, casa_org: casa_org) }
+
+ before { sign_in user }
+
+ describe "GET /new" do
+ context "when the user is an admin" do
+ let(:user) { admin }
+
+ it "renders a successful response" do
+ get new_standard_court_order_url
+ expect(response).to be_successful
+ end
+ end
+
+ context "when the user is a supervisor" do
+ let(:user) { supervisor }
+
+ it "redirects to the root path" do
+ get new_standard_court_order_url
+ expect(response).to redirect_to(root_path)
+ expect(flash[:notice]).to eq("Sorry, you are not authorized to perform this action.")
+ end
+ end
+
+ context "when the user is a volunteer" do
+ let(:user) { volunteer }
+
+ it "redirects to the root path" do
+ get new_standard_court_order_url
+ expect(response).to be_redirect
+ expect(flash[:notice]).to eq("Sorry, you are not authorized to perform this action.")
+ end
+ end
+ end
+
+ describe "GET /edit" do
+ context "when the user is an admin" do
+ let(:user) { admin }
+
+ it "renders a successful response" do
+ get edit_standard_court_order_url(standard_court_order)
+ expect(response).to be_successful
+ expect(response.body).to include(standard_court_order.value)
+ end
+ end
+
+ context "when the user is a supervisor" do
+ let(:user) { supervisor }
+
+ it "redirects to the root path" do
+ get edit_standard_court_order_url(standard_court_order)
+ expect(response).to redirect_to(root_path)
+ expect(flash[:notice]).to eq("Sorry, you are not authorized to perform this action.")
+ end
+ end
+
+ context "when the user is a volunteer" do
+ let(:user) { volunteer }
+
+ it "redirects to the root path" do
+ get edit_standard_court_order_url(standard_court_order)
+ expect(response).to be_redirect
+ expect(flash[:notice]).to eq("Sorry, you are not authorized to perform this action.")
+ end
+ end
+ end
+
+ describe "POST /create" do
+ context "when the user is an admin" do
+ let(:user) { admin }
+
+ context "with valid parameters" do
+ let(:attributes) do
+ {
+ casa_org_id: casa_org.id,
+ value: "test value"
+ }
+ end
+
+ it "redirects to the edit casa_org" do
+ post standard_court_orders_url, params: {standard_court_order: attributes}
+ expect(response).to redirect_to(edit_casa_org_path(casa_org))
+ expect(flash[:notice]).to eq("Standard court order was successfully created.")
+ end
+ end
+
+ context "with invalid parameters" do
+ let(:attributes) { {casa_org_id: 0} }
+
+ it "does not create a new StandardCourtOrder" do
+ expect do
+ post standard_court_orders_url, params: {standard_court_order: attributes}
+ end.to change(StandardCourtOrder, :count).by(0)
+ end
+
+ it "renders a response with 422 status (i.e. to display the 'new' template)" do
+ post standard_court_orders_url, params: {standard_court_order: attributes}
+ expect(response).to have_http_status(:unprocessable_entity)
+ end
+ end
+ end
+
+ context "when the user is a supervisor" do
+ let(:user) { supervisor }
+
+ it "redirects to the root path" do
+ post standard_court_orders_url
+ expect(response).to redirect_to(root_path)
+ expect(flash[:notice]).to eq("Sorry, you are not authorized to perform this action.")
+ end
+ end
+
+ context "when the user is a volunteer" do
+ let(:user) { volunteer }
+
+ it "redirects to the root path" do
+ post standard_court_orders_url
+ expect(response).to be_redirect
+ expect(flash[:notice]).to eq("Sorry, you are not authorized to perform this action.")
+ end
+ end
+ end
+
+ describe "PATCH /update" do
+ context "when the user is an admin" do
+ let(:user) { admin }
+
+ context "with valid parameters" do
+ let!(:standard_court_order) { create(:standard_court_order, casa_org:) }
+
+ let(:new_attributes) do
+ {
+ casa_org_id: casa_org.id,
+ value: "test value"
+ }
+ end
+
+ it "redirects to the casa_org edit" do
+ patch standard_court_order_url(standard_court_order), params: {standard_court_order: new_attributes}
+ expect(response).to redirect_to(edit_casa_org_path(casa_org))
+ expect(flash[:notice]).to eq("Standard court order was successfully updated.")
+ end
+ end
+
+ context "with invalid parameters" do
+ let(:attributes) { {casa_org_id: 0} }
+
+ it "renders a response with 422 status (i.e. to display the 'edit' template)" do
+ patch standard_court_order_url(standard_court_order), params: {standard_court_order: attributes}
+ expect(response).to have_http_status(:unprocessable_entity)
+ end
+ end
+ end
+
+ context "when the user is a supervisor" do
+ let(:user) { supervisor }
+
+ it "redirects to the root path" do
+ patch standard_court_order_url(standard_court_order)
+ expect(response).to redirect_to(root_path)
+ expect(flash[:notice]).to eq("Sorry, you are not authorized to perform this action.")
+ end
+ end
+
+ context "when the user is a volunteer" do
+ let(:user) { volunteer }
+
+ it "redirects to the root path" do
+ patch standard_court_order_url(standard_court_order)
+ expect(response).to be_redirect
+ expect(flash[:notice]).to eq("Sorry, you are not authorized to perform this action.")
+ end
+ end
+ end
+
+ describe "DELETE /destroy" do
+ let!(:standard_court_order) { create(:standard_court_order, casa_org: casa_org) }
+
+ context "when the user is an admin" do
+ let(:user) { admin }
+
+ it "redirects to edit casa_org" do
+ delete standard_court_order_url(standard_court_order)
+ expect(response).to redirect_to(edit_casa_org_path(casa_org))
+ expect(flash[:notice]).to eq("Standard court order was successfully deleted.")
+ end
+ end
+
+ context "when the user is a supervisor" do
+ let(:user) { supervisor }
+
+ it "redirects to the root path" do
+ delete standard_court_order_url(standard_court_order)
+ expect(response).to redirect_to(root_path)
+ expect(flash[:notice]).to eq("Sorry, you are not authorized to perform this action.")
+ end
+ end
+
+ context "when the user is a volunteer" do
+ let(:user) { volunteer }
+
+ it "redirects to the root path" do
+ delete standard_court_order_url(standard_court_order)
+ expect(response).to be_redirect
+ expect(flash[:notice]).to eq("Sorry, you are not authorized to perform this action.")
+ end
+ 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..ef8785104f
--- /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
diff --git a/spec/system/casa_cases/edit_spec.rb b/spec/system/casa_cases/edit_spec.rb
index 0f1461473c..7674bf1613 100644
--- a/spec/system/casa_cases/edit_spec.rb
+++ b/spec/system/casa_cases/edit_spec.rb
@@ -527,12 +527,16 @@ def sign_in_and_assign_volunteer
end
it "adds a standard court order", js: true do
+ create(:standard_court_order,
+ value: "Some Totally New Value",
+ casa_org: volunteer.casa_org)
+
visit edit_casa_case_path(casa_case)
- select("Family therapy", from: "Court Order Type")
+ select("Some Totally New Value", from: "Court Order Type")
click_button("Add a court order")
textarea = all("textarea.court-order-text-entry").last
- expect(textarea.value).to eq("Family therapy")
+ expect(textarea.value).to eq("Some Totally New Value")
end
it "adds a custom court order", js: true do
diff --git a/spec/system/court_dates/edit_spec.rb b/spec/system/court_dates/edit_spec.rb
index 9568ad09fa..bec2f939ef 100644
--- a/spec/system/court_dates/edit_spec.rb
+++ b/spec/system/court_dates/edit_spec.rb
@@ -19,6 +19,8 @@
context "as an admin" do
before do
+ create(:standard_court_order, value: "Some Totally New Value", casa_org: volunteer.casa_org)
+
sign_in admin
visit casa_case_path(casa_case)
click_on court_date.date.strftime("%B %-d, %Y")
@@ -33,11 +35,11 @@
end
it "adds a standard court order", js: true do
- select("Family therapy", from: "Court Order Type")
+ select("Some Totally New Value", from: "Court Order Type")
click_button("Add a court order")
textarea = all("textarea.court-order-text-entry").last
- expect(textarea.value).to eq("Family therapy")
+ expect(textarea.value).to eq("Some Totally New Value")
end
it "adds a custom court order", js: true do
diff --git a/spec/system/standard_court_orders/standard_court_orders_spec.rb b/spec/system/standard_court_orders/standard_court_orders_spec.rb
new file mode 100644
index 0000000000..cf1b4140bb
--- /dev/null
+++ b/spec/system/standard_court_orders/standard_court_orders_spec.rb
@@ -0,0 +1,40 @@
+require "rails_helper"
+
+RSpec.describe "Standard Court Orders", type: :system, js: true do
+ let(:casa_org) { create(:casa_org) }
+ let(:admin) { create(:casa_admin, casa_org: casa_org) }
+ let(:volunteer) { create(:volunteer, casa_org: casa_org) }
+ let(:casa_case) { create(:casa_case, :with_one_court_order, casa_org: volunteer.casa_org) }
+
+ it "allows an admin to create a standard court order" do
+ sign_in admin
+
+ visit edit_casa_org_path(casa_org)
+ click_link "New Standard Court Order"
+ fill_in "Standard Court Order", with: "Substance Abuse Treatment (child, mother, father, other guardian)"
+ click_button "Submit"
+
+ expect(page).to have_css("h1", text: "Editing CASA Organization")
+ expect(page).to have_css("div.alert", text: "Standard court order was successfully created.")
+ expect(page).to have_css("tr", text: "Substance Abuse Treatment (child, mother, father, other guardian)")
+ end
+
+ it "allows an admin to delete a standard court order" do
+ sign_in admin
+
+ create(:standard_court_order, value: "Substance Abuse Treatment (child, mother, father, other guardian)")
+
+ visit edit_casa_org_path(casa_org)
+
+ within("#standard-court-orders") do
+ click_button "Actions Menu"
+ click_link "Delete"
+ end
+
+ click_link "Delete Standard Court Order"
+
+ expect(page).to have_css("h1", text: "Editing CASA Organization")
+ expect(page).to have_css("div.alert", text: "Standard court order was successfully deleted.")
+ expect(page).to_not have_css("tr", text: "Substance Abuse Treatment (child, mother, father, other guardian)")
+ end
+end
diff --git a/spec/views/casa_orgs/edit.html.erb_spec.rb b/spec/views/casa_orgs/edit.html.erb_spec.rb
index c0a64e1851..105443203b 100644
--- a/spec/views/casa_orgs/edit.html.erb_spec.rb
+++ b/spec/views/casa_orgs/edit.html.erb_spec.rb
@@ -25,6 +25,22 @@
expect(rendered).to have_selector("input[required=required]", id: "casa_org_name")
end
+ it "has standard court order content" do
+ organization = build_stubbed(:casa_org)
+ allow(view).to receive(:current_organization).and_return(organization)
+ standard_court_order = build_stubbed(:standard_court_order, value: "Standard court order value")
+ assign(:standard_court_orders, [standard_court_order])
+
+ render template: "casa_org/edit"
+
+ expect(rendered).to have_text("Standard Court Orders")
+ expect(rendered).to have_table("standard-court-orders",
+ with_rows:
+ [
+ ["Standard court order value", "Edit"]
+ ])
+ end
+
it "has contact topic content" do
organization = build_stubbed(:casa_org)
allow(view).to receive(:current_organization).and_return(organization)