From 5424aa9adfaa02111f7df88ea87853854a869a2c Mon Sep 17 00:00:00 2001 From: Dalma Boros Date: Tue, 18 Jun 2024 20:23:41 -0500 Subject: [PATCH 01/11] Create Standard Court Order per organization basis [#5781] --- app/models/standard_court_order.rb | 24 +++++++++++++++++++ ...0619005250_create_standard_court_orders.rb | 10 ++++++++ db/schema.rb | 9 +++++++ spec/factories/standard_court_orders.rb | 6 +++++ spec/models/standard_court_order_spec.rb | 14 +++++++++++ 5 files changed, 63 insertions(+) create mode 100644 app/models/standard_court_order.rb create mode 100644 db/migrate/20240619005250_create_standard_court_orders.rb create mode 100644 spec/factories/standard_court_orders.rb create mode 100644 spec/models/standard_court_order_spec.rb diff --git a/app/models/standard_court_order.rb b/app/models/standard_court_order.rb new file mode 100644 index 0000000000..9233e7583f --- /dev/null +++ b/app/models/standard_court_order.rb @@ -0,0 +1,24 @@ +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) +# +# Foreign Keys +# +# fk_rails_... (casa_org_id => casa_orgs.id) +# 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..870d6b029a --- /dev/null +++ b/db/migrate/20240619005250_create_standard_court_orders.rb @@ -0,0 +1,10 @@ +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 + end +end diff --git a/db/schema.rb b/db/schema.rb index e4ba1f6685..fae40a5867 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -607,6 +607,14 @@ 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"], 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 +747,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/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/standard_court_order_spec.rb b/spec/models/standard_court_order_spec.rb new file mode 100644 index 0000000000..d6780b1a87 --- /dev/null +++ b/spec/models/standard_court_order_spec.rb @@ -0,0 +1,14 @@ +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 } + end +end From 002d7236133dd21587792140d0e22a171e9c945f Mon Sep 17 00:00:00 2001 From: Dalma Boros Date: Tue, 18 Jun 2024 20:56:34 -0500 Subject: [PATCH 02/11] Add standard court order policies --- app/policies/application_policy.rb | 2 +- app/policies/standard_court_order_policy.rb | 21 +++++++++ .../standard_court_order_policy_spec.rb | 46 +++++++++++++++++++ 3 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 app/policies/standard_court_order_policy.rb create mode 100644 spec/policies/standard_court_order_policy_spec.rb 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..c920f56677 --- /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 \ No newline at end of file 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..5a25343c8f --- /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 \ No newline at end of file From 1adef6229a90d565c2054b1a890e9061e2936f03 Mon Sep 17 00:00:00 2001 From: Dalma Boros Date: Tue, 25 Jun 2024 19:08:25 -0400 Subject: [PATCH 03/11] Add standard court order partials --- app/controllers/casa_org_controller.rb | 5 ++ .../standard_court_orders_controller.rb | 52 ++++++++++++++++ app/models/casa_org.rb | 1 + .../casa_org/_standard_court_orders.html.erb | 61 +++++++++++++++++++ app/views/casa_org/edit.html.erb | 14 +++++ .../standard_court_orders/_form.html.erb | 31 ++++++++++ app/views/standard_court_orders/edit.html.erb | 1 + app/views/standard_court_orders/new.html.erb | 1 + config/routes.rb | 2 + spec/models/casa_org_spec.rb | 1 + spec/views/casa_orgs/edit.html.erb_spec.rb | 17 ++++++ 11 files changed, 186 insertions(+) create mode 100644 app/controllers/standard_court_orders_controller.rb create mode 100644 app/views/casa_org/_standard_court_orders.html.erb create mode 100644 app/views/standard_court_orders/_form.html.erb create mode 100644 app/views/standard_court_orders/edit.html.erb create mode 100644 app/views/standard_court_orders/new.html.erb 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/views/casa_org/_standard_court_orders.html.erb b/app/views/casa_org/_standard_court_orders.html.erb new file mode 100644 index 0000000000..9a548007fe --- /dev/null +++ b/app/views/casa_org/_standard_court_orders.html.erb @@ -0,0 +1,61 @@ +
+
+
+
+
+

Standard Court Orders

+
+
+ +
+
+
+ + + + + + + + + <% @standard_court_orders.each do |standard_court_order| %> + <% id = "standard_court_order-#{standard_court_order.id}" %> + + + + + <%= render(Modal::GroupComponent.new(id: id)) do |component| %> + <% component.with_header(text: "Delete Standard Court Order?", id: id) %> + TODO: update confirmation text + <% component.with_body(text: [ + "This standard court order will be deleted and will no longer be presented while filling out case details.", + "This will not affect case contacts that have already been created."]) %> + <% 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 %> + +
ValueActions
+ <%= 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 %> +
    +
    +
    +
    +
    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/standard_court_orders/_form.html.erb b/app/views/standard_court_orders/_form.html.erb new file mode 100644 index 0000000000..7d64fcddbd --- /dev/null +++ b/app/views/standard_court_orders/_form.html.erb @@ -0,0 +1,31 @@ +
    +
    +
    +
    +

    + <%= title %> +

    +
    +
    +
    +
    + + +
    + <%= 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, "Value" %> + <%= 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/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/views/casa_orgs/edit.html.erb_spec.rb b/spec/views/casa_orgs/edit.html.erb_spec.rb index c0a64e1851..473de8140a 100644 --- a/spec/views/casa_orgs/edit.html.erb_spec.rb +++ b/spec/views/casa_orgs/edit.html.erb_spec.rb @@ -10,6 +10,7 @@ assign(:learning_hour_topics, []) assign(:sent_emails, []) assign(:contact_topics, []) + # assign(:standard_court_orders, []) sign_in build_stubbed(:casa_admin) end @@ -25,6 +26,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) From 31b4393e7ae2737fc1e333ea8076792121d913a7 Mon Sep 17 00:00:00 2001 From: Dalma Boros Date: Tue, 25 Jun 2024 19:10:02 -0400 Subject: [PATCH 04/11] Run bin/lint --- app/policies/standard_court_order_policy.rb | 2 +- spec/models/standard_court_order_spec.rb | 6 +++--- spec/policies/standard_court_order_policy_spec.rb | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/policies/standard_court_order_policy.rb b/app/policies/standard_court_order_policy.rb index c920f56677..4a98cf4e01 100644 --- a/app/policies/standard_court_order_policy.rb +++ b/app/policies/standard_court_order_policy.rb @@ -18,4 +18,4 @@ def edit? def destroy? is_admin_same_org? end -end \ No newline at end of file +end diff --git a/spec/models/standard_court_order_spec.rb b/spec/models/standard_court_order_spec.rb index d6780b1a87..1dcf4bd866 100644 --- a/spec/models/standard_court_order_spec.rb +++ b/spec/models/standard_court_order_spec.rb @@ -1,11 +1,11 @@ -require 'rails_helper' +require "rails_helper" RSpec.describe StandardCourtOrder, type: :model do - describe 'associations' do + describe "associations" do it { is_expected.to belong_to(:casa_org) } end - describe 'validations' do + describe "validations" do subject { FactoryBot.build(:standard_court_order) } it { is_expected.to validate_presence_of(:value) } diff --git a/spec/policies/standard_court_order_policy_spec.rb b/spec/policies/standard_court_order_policy_spec.rb index 5a25343c8f..3c06f527ce 100644 --- a/spec/policies/standard_court_order_policy_spec.rb +++ b/spec/policies/standard_court_order_policy_spec.rb @@ -43,4 +43,4 @@ end end end -end \ No newline at end of file +end From 9f39c08e48edd735d6d826cd2b19dc07d868adb4 Mon Sep 17 00:00:00 2001 From: Dalma Boros Date: Sat, 6 Jul 2024 21:13:20 -0500 Subject: [PATCH 05/11] Request specs, database index --- app/models/standard_court_order.rb | 3 +- ...0619005250_create_standard_court_orders.rb | 2 + db/schema.rb | 1 + spec/models/standard_court_order_spec.rb | 8 + spec/requests/standard_court_orders_spec.rb | 217 ++++++++++++++++++ 5 files changed, 230 insertions(+), 1 deletion(-) create mode 100644 spec/requests/standard_court_orders_spec.rb diff --git a/app/models/standard_court_order.rb b/app/models/standard_court_order.rb index 9233e7583f..d9bb8b3df1 100644 --- a/app/models/standard_court_order.rb +++ b/app/models/standard_court_order.rb @@ -16,7 +16,8 @@ class StandardCourtOrder < ApplicationRecord # # Indexes # -# index_standard_court_orders_on_casa_org_id (casa_org_id) +# 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 # diff --git a/db/migrate/20240619005250_create_standard_court_orders.rb b/db/migrate/20240619005250_create_standard_court_orders.rb index 870d6b029a..5ae87acef8 100644 --- a/db/migrate/20240619005250_create_standard_court_orders.rb +++ b/db/migrate/20240619005250_create_standard_court_orders.rb @@ -6,5 +6,7 @@ def change 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 fae40a5867..429ac9b613 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -612,6 +612,7 @@ 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 diff --git a/spec/models/standard_court_order_spec.rb b/spec/models/standard_court_order_spec.rb index 1dcf4bd866..dba734ed2e 100644 --- a/spec/models/standard_court_order_spec.rb +++ b/spec/models/standard_court_order_spec.rb @@ -10,5 +10,13 @@ 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/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 From f125b16870a9330d6a7a74af7a6e3ad7346ec628 Mon Sep 17 00:00:00 2001 From: Dalma Boros Date: Sun, 7 Jul 2024 19:56:40 -0500 Subject: [PATCH 06/11] System specs, changed labels on standard court order form and table --- .../casa_org/_standard_court_orders.html.erb | 10 ++--- .../standard_court_orders/_form.html.erb | 2 +- .../standard_court_orders_spec.rb | 43 +++++++++++++++++++ 3 files changed, 47 insertions(+), 8 deletions(-) create mode 100644 spec/system/standard_court_orders/standard_court_orders_spec.rb diff --git a/app/views/casa_org/_standard_court_orders.html.erb b/app/views/casa_org/_standard_court_orders.html.erb index 9a548007fe..966bb84d67 100644 --- a/app/views/casa_org/_standard_court_orders.html.erb +++ b/app/views/casa_org/_standard_court_orders.html.erb @@ -20,8 +20,8 @@ - - + + @@ -31,7 +31,7 @@ - <%= render(Modal::GroupComponent.new(id: id)) do |component| %> <% component.with_header(text: "Delete Standard Court Order?", id: id) %> - TODO: update confirmation text - <% component.with_body(text: [ - "This standard court order will be deleted and will no longer be presented while filling out case details.", - "This will not affect case contacts that have already been created."]) %> <% 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 %> diff --git a/app/views/standard_court_orders/_form.html.erb b/app/views/standard_court_orders/_form.html.erb index 7d64fcddbd..7681d04235 100644 --- a/app/views/standard_court_orders/_form.html.erb +++ b/app/views/standard_court_orders/_form.html.erb @@ -18,7 +18,7 @@ <%= render "/shared/error_messages", resource: standard_court_order %>
    - <%= form.label :value, "Value" %> + <%= form.label :value, "Standard Court Order" %> <%= form.text_field :value, class: "form-control", required: true %>
    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..f8a6b88ab6 --- /dev/null +++ b/spec/system/standard_court_orders/standard_court_orders_spec.rb @@ -0,0 +1,43 @@ +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) } + + 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 + + it "allows a volunteer to select a standard court order" do + # + end +end \ No newline at end of file From e904d70db76681f92cb5dc388ff6e7208ee55eae Mon Sep 17 00:00:00 2001 From: elasticspoon Date: Sun, 7 Jul 2024 21:32:15 -0400 Subject: [PATCH 07/11] feat: implement custom court orders Add selection casa_org set court order on casa cases and court dates. --- app/views/shared/_court_order_list.erb | 2 +- spec/system/casa_cases/edit_spec.rb | 8 ++++++-- spec/system/court_dates/edit_spec.rb | 7 +++++-- .../standard_court_orders_spec.rb | 16 ++++++++++++---- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/app/views/shared/_court_order_list.erb b/app/views/shared/_court_order_list.erb index be6c26de9a..a7fae60096 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(casa_case.casa_org.standard_court_orders.map(&:value)), { include_blank: "Create custom court order", data: {court_order_form_target: "selectedCourtOrder"} } %>
    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..a24247795e 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,12 @@ 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 index f8a6b88ab6..285442f1ae 100644 --- a/spec/system/standard_court_orders/standard_court_orders_spec.rb +++ b/spec/system/standard_court_orders/standard_court_orders_spec.rb @@ -4,6 +4,7 @@ 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 @@ -37,7 +38,14 @@ expect(page).to_not have_css("tr", text: "Substance Abuse Treatment (child, mother, father, other guardian)") end - it "allows a volunteer to select a standard court order" do - # - end -end \ No newline at end of file + # it "allows a volunteer to select a standard court order" do + # sign_in volunteer + # + # create(:standard_court_order, value: "Substance Abuse Treatment (child, mother, father, other guardian)") + # + # visit edit_casa_case_path(casa_case) + # select("Substance Abuse Treatment (child, mother, father, other guardian)", from: "Court Order Type") + # click_button("Add a court order") + # + # end +end From b98bde372a01cd5d46dbe1608d8eb9612d7a6b46 Mon Sep 17 00:00:00 2001 From: Dalma Boros Date: Sun, 7 Jul 2024 21:02:44 -0500 Subject: [PATCH 08/11] Create deployment task to populate default standard court orders --- app/models/case_court_order.rb | 26 +--------- ..._create_default_standard_court_orders.rake | 49 +++++++++++++++++++ 2 files changed, 50 insertions(+), 25 deletions(-) create mode 100644 lib/tasks/deployment/20240708014020_create_default_standard_court_orders.rake diff --git a/app/models/case_court_order.rb b/app/models/case_court_order.rb index 7e41ee9cdc..54fcd3ce6c 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,6 +8,7 @@ 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 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..5b5b65ec89 --- /dev/null +++ b/lib/tasks/deployment/20240708014020_create_default_standard_court_orders.rake @@ -0,0 +1,49 @@ +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. + 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 + + # 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 From c258e8c53c2ea48bfcb0fae2d22705cc171db097 Mon Sep 17 00:00:00 2001 From: Dalma Boros Date: Sun, 14 Jul 2024 20:29:12 -0500 Subject: [PATCH 09/11] 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 From 63622dc2606db09e818b9098ab83a16e37b9890d Mon Sep 17 00:00:00 2001 From: Dalma Boros Date: Sun, 14 Jul 2024 20:36:22 -0500 Subject: [PATCH 10/11] Linting --- ...e_default_standard_court_orders_service.rb | 50 +++++++++---------- ..._create_default_standard_court_orders.rake | 2 +- ...ault_standard_court_orders_service_spec.rb | 6 +-- spec/system/court_dates/edit_spec.rb | 1 - .../standard_court_orders_spec.rb | 13 +---- spec/views/casa_orgs/edit.html.erb_spec.rb | 1 - 6 files changed, 30 insertions(+), 43 deletions(-) diff --git a/app/services/deployment/create_default_standard_court_orders_service.rb b/app/services/deployment/create_default_standard_court_orders_service.rb index 45ff525579..545c4c03a2 100644 --- a/app/services/deployment/create_default_standard_court_orders_service.rb +++ b/app/services/deployment/create_default_standard_court_orders_service.rb @@ -1,30 +1,30 @@ 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 + "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| @@ -34,4 +34,4 @@ def create_defaults end end end -end \ No newline at end of file +end 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 18b11f30bf..36b3d75f01 100644 --- a/lib/tasks/deployment/20240708014020_create_default_standard_court_orders.rake +++ b/lib/tasks/deployment/20240708014020_create_default_standard_court_orders.rake @@ -1,5 +1,5 @@ namespace :after_party do - desc 'Deployment task: Create default standard court orders for every CASA org' + 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'" 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 index 375d7b219f..ef8785104f 100644 --- a/spec/services/deployment/create_default_standard_court_orders_service_spec.rb +++ b/spec/services/deployment/create_default_standard_court_orders_service_spec.rb @@ -5,8 +5,8 @@ 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", + 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 @@ -16,4 +16,4 @@ expect(casa_org_2.standard_court_orders.map(&:value)).to eq(["Default 1", "Default 2"]) end end -end \ No newline at end of file +end diff --git a/spec/system/court_dates/edit_spec.rb b/spec/system/court_dates/edit_spec.rb index a24247795e..bec2f939ef 100644 --- a/spec/system/court_dates/edit_spec.rb +++ b/spec/system/court_dates/edit_spec.rb @@ -35,7 +35,6 @@ end it "adds a standard court order", js: true do - select("Some Totally New Value", from: "Court Order Type") click_button("Add a court order") diff --git a/spec/system/standard_court_orders/standard_court_orders_spec.rb b/spec/system/standard_court_orders/standard_court_orders_spec.rb index 285442f1ae..cf1b4140bb 100644 --- a/spec/system/standard_court_orders/standard_court_orders_spec.rb +++ b/spec/system/standard_court_orders/standard_court_orders_spec.rb @@ -25,7 +25,7 @@ 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" @@ -37,15 +37,4 @@ 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 - - # it "allows a volunteer to select a standard court order" do - # sign_in volunteer - # - # create(:standard_court_order, value: "Substance Abuse Treatment (child, mother, father, other guardian)") - # - # visit edit_casa_case_path(casa_case) - # select("Substance Abuse Treatment (child, mother, father, other guardian)", from: "Court Order Type") - # click_button("Add a court order") - # - # 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 473de8140a..105443203b 100644 --- a/spec/views/casa_orgs/edit.html.erb_spec.rb +++ b/spec/views/casa_orgs/edit.html.erb_spec.rb @@ -10,7 +10,6 @@ assign(:learning_hour_topics, []) assign(:sent_emails, []) assign(:contact_topics, []) - # assign(:standard_court_orders, []) sign_in build_stubbed(:casa_admin) end From b5b04fc7143c605affd3623093b2ba232a0a3caa Mon Sep 17 00:00:00 2001 From: elasticspoon Date: Sat, 10 Aug 2024 17:17:37 -0400 Subject: [PATCH 11/11] fix: failing specs --- app/views/casa_org/_standard_court_orders.html.erb | 2 +- app/views/shared/_court_order_list.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/casa_org/_standard_court_orders.html.erb b/app/views/casa_org/_standard_court_orders.html.erb index 966bb84d67..305110959f 100644 --- a/app/views/casa_org/_standard_court_orders.html.erb +++ b/app/views/casa_org/_standard_court_orders.html.erb @@ -25,7 +25,7 @@
    - <% @standard_court_orders.each do |standard_court_order| %> + <% @standard_court_orders&.each do |standard_court_order| %> <% id = "standard_court_order-#{standard_court_order.id}" %>
    ValueActionsStandard Court OrderActions
    <%= 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")) %>
  • @@ -40,10 +40,6 @@
    diff --git a/app/views/shared/_court_order_list.erb b/app/views/shared/_court_order_list.erb index a7fae60096..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(casa_case.casa_org.standard_court_orders.map(&:value)), + options_for_select(current_organization.standard_court_orders.map(&:value)), { include_blank: "Create custom court order", data: {court_order_form_target: "selectedCourtOrder"} } %>