From 077888b9d7d5a52c44f5a6802baa9c9f236492fa Mon Sep 17 00:00:00 2001 From: guswhitten Date: Mon, 12 Aug 2024 08:54:46 -0400 Subject: [PATCH 01/26] add crud methods for case-specific placements --- Gemfile.lock | 5 ++ app/assets/stylesheets/pages/casa_cases.scss | 7 ++ app/controllers/placements_controller.rb | 78 ++++++++++++++++++-- app/decorators/placement_decorator.rb | 2 +- app/models/placement_type.rb | 17 ++++- app/policies/casa_case_policy.rb | 2 + app/policies/placement_policy.rb | 20 +++++ app/views/casa_cases/_placements.html.erb | 38 +++++++--- app/views/placements/_fields.html.erb | 18 +++++ app/views/placements/_form.html.erb | 26 +++++++ app/views/placements/edit.html.erb | 11 +++ app/views/placements/edit_multiple.html.erb | 36 +++++++++ app/views/placements/index.html.erb | 38 ++++++++++ app/views/placements/new.html.erb | 11 +++ app/views/placements/show.html.erb | 2 +- config/environments/test.rb | 2 +- config/routes.rb | 7 +- 17 files changed, 297 insertions(+), 23 deletions(-) create mode 100644 app/policies/placement_policy.rb create mode 100644 app/views/placements/_fields.html.erb create mode 100644 app/views/placements/_form.html.erb create mode 100644 app/views/placements/edit.html.erb create mode 100644 app/views/placements/edit_multiple.html.erb create mode 100644 app/views/placements/index.html.erb create mode 100644 app/views/placements/new.html.erb diff --git a/Gemfile.lock b/Gemfile.lock index 4f4cf242a9..3348cdead1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -535,6 +535,10 @@ GEM timeout (0.4.1) traceroute (0.8.1) rails (>= 3.0.0) + turbo-rails (2.0.5) + actionpack (>= 6.0.0) + activejob (>= 6.0.0) + railties (>= 6.0.0) twilio-ruby (7.2.3) faraday (>= 0.9, < 3.0) jwt (>= 1.5, < 3.0) @@ -654,6 +658,7 @@ DEPENDENCIES stimulus-rails strong_migrations traceroute + turbo-rails twilio-ruby tzinfo-data view_component diff --git a/app/assets/stylesheets/pages/casa_cases.scss b/app/assets/stylesheets/pages/casa_cases.scss index 544409c430..0e30645519 100644 --- a/app/assets/stylesheets/pages/casa_cases.scss +++ b/app/assets/stylesheets/pages/casa_cases.scss @@ -170,3 +170,10 @@ body.casa_cases-show { gap: .2rem; } } + +.placement-dropdown { + .dropdown-toggle { + background: none; + border: none; + } +} \ No newline at end of file diff --git a/app/controllers/placements_controller.rb b/app/controllers/placements_controller.rb index fe24ffa4e4..6ba4afe5b1 100644 --- a/app/controllers/placements_controller.rb +++ b/app/controllers/placements_controller.rb @@ -5,25 +5,84 @@ class PlacementsController < ApplicationController rescue_from ActiveRecord::RecordNotFound, with: -> { head :not_found } - def show + def index authorize @casa_case + @placements = @casa_case.placements.includes(:placement_type).order(placement_started_at: :desc) end - def new - end + # def show + # authorize @casa_case + # end + # def new + # @placement = Placement.new(casa_case: @casa_case) + # authorize @placement + # end + # def edit + authorize @casa_case end - def create + def update + authorize @placement + if @placement.update(placement_params) + redirect_to casa_case_placements_path(@casa_case), notice: "Placement was successfully updated." + else + render :edit, status: :unprocessable_entity + end end - def update + def edit_multiple + authorize @casa_case + @placements = @casa_case.placements.includes(:placement_type) end - def destroy + def update_multiple + @casa_case = CasaCase.find(params[:casa_case_id]) + + Placement.transaction do + params[:placements].each do |id, placement_params| + placement = @casa_case.placements.find(id) + placement.update!(placement_params) + end + end + + redirect_to casa_case_placements_path(@casa_case), notice: 'Placements were successfully updated.' + rescue ActiveRecord::RecordInvalid + @placements = @casa_case.placements + flash.now[:alert] = 'There was an error updating the placements.' + render :edit_multiple end + # def create + # @placement = Placement.new(placement_params.merge(casa_case: @casa_case)) + # authorize @placement + # + # if @placement.save && @casa_case.save + # redirect_to casa_case_placement_path(@casa_case, @placement), notice: "Placement was successfully created." + # else + # render :new, status: :unprocessable_entity + # end + # end + # + # def update + # authorize @placement + # if @placement.update(placement_params) + # redirect_to casa_case_placement_path(@casa_case, @placement), notice: "Placement was successfully updated." + # else + # render :edit, status: :unprocessable_entity + # end + # end + + # def destroy + # authorize @placement + # if @placement.destroy + # redirect_to casa_case_path(@casa_case), notice: "Placement was successfully deleted." + # else + # render :edit, status: :unprocessable_entity + # end + # end + private def set_casa_case @@ -33,4 +92,11 @@ def set_casa_case def set_placement @placement = @casa_case.placements.find(params[:id]) end + + def placement_params + params.require(:placement).permit( + :placement_started_at, + :placement_type_id + ) + end end diff --git a/app/decorators/placement_decorator.rb b/app/decorators/placement_decorator.rb index 183e174a83..b5294c7a31 100644 --- a/app/decorators/placement_decorator.rb +++ b/app/decorators/placement_decorator.rb @@ -6,7 +6,7 @@ def formatted_date end def placement_info - ["Started At: #{formatted_date}", "Placement Type: #{placement_type&.name}"].compact.join(" - ") + [formatted_date, placement_type&.name&.to_s].compact.join(" - ") end def placement_started_at diff --git a/app/models/placement_type.rb b/app/models/placement_type.rb index 49ffd47054..52412ef347 100644 --- a/app/models/placement_type.rb +++ b/app/models/placement_type.rb @@ -1,6 +1,21 @@ class PlacementType < ApplicationRecord belongs_to :casa_org - validates :name, presence: true + + VALID_NAMES = [ + "Reunification", + "Custody/Guardianship by a relative", + "Custody/Guardianship by a non-relative", + "Adoption by relative", + "Adoption by a non-relative", + "APPLA" + ].freeze + + validates :name, presence: true, inclusion: { in: VALID_NAMES } + scope :for_organization, ->(org) { where(casa_org: org).order(:name) } + + def self.valid_names + VALID_NAMES + end end # == Schema Information diff --git a/app/policies/casa_case_policy.rb b/app/policies/casa_case_policy.rb index e8f644ea0f..036e0382a8 100644 --- a/app/policies/casa_case_policy.rb +++ b/app/policies/casa_case_policy.rb @@ -106,6 +106,8 @@ def index? alias_method :new?, :is_admin_same_org? alias_method :create?, :is_admin_same_org? alias_method :destroy?, :is_admin_same_org? + alias_method :update_multiple?, :edit? + alias_method :edit_multiple?, :edit? private diff --git a/app/policies/placement_policy.rb b/app/policies/placement_policy.rb new file mode 100644 index 0000000000..ea7449db53 --- /dev/null +++ b/app/policies/placement_policy.rb @@ -0,0 +1,20 @@ +class PlacementPolicy < ApplicationPolicy + def allowed_to_edit_casa_case? + casa_case_policy.edit? + end + + alias_method :update_multiple?, :allowed_to_edit_casa_case? + alias_method :edit_multiple?, :allowed_to_edit_casa_case? + alias_method :show?, :allowed_to_edit_casa_case? + alias_method :edit?, :allowed_to_edit_casa_case? + alias_method :update?, :allowed_to_edit_casa_case? + alias_method :new?, :allowed_to_edit_casa_case? + alias_method :create?, :allowed_to_edit_casa_case? + alias_method :destroy?, :admin_or_supervisor? + + private + + def casa_case_policy + CasaCasePolicy.new(user, record.casa_case) + end +end diff --git a/app/views/casa_cases/_placements.html.erb b/app/views/casa_cases/_placements.html.erb index ce7a5aa30d..0b26051318 100644 --- a/app/views/casa_cases/_placements.html.erb +++ b/app/views/casa_cases/_placements.html.erb @@ -1,13 +1,27 @@ -<% placements = casa_case.placements %> - -<% if placements.empty? %> - No Placements +<% placements = casa_case.placements.includes(:placement_type) %> +<% current_placement = placements.order(placement_started_at: :desc).first %> + +<% if current_placement %> + + + + + + + + + + + + + +
PlacementStart DateActions
<%= current_placement.placement_type.name %><%= current_placement.placement_started_at.strftime('%B %d, %Y') %> - Present + <%= render(DropdownMenuComponent.new(menu_title: "Actions Menu", hide_label: true, klass: "placement-dropdown")) do %> +
  • <%= link_to "Show All", casa_case_placements_path(casa_case), class: "dropdown-item" %>
  • + + + <% end %> +
    <% else %> - -<% end %> +

    No placements found.

    +<% end %> \ No newline at end of file diff --git a/app/views/placements/_fields.html.erb b/app/views/placements/_fields.html.erb new file mode 100644 index 0000000000..c33f80a62e --- /dev/null +++ b/app/views/placements/_fields.html.erb @@ -0,0 +1,18 @@ +
    + <%= form.label :placement_started_at, "Placement Started At" %> + <%= form.date_field :placement_started_at, + value: placement.placement_started_at&.to_date || Time.zone.now, + class: "form-control" %> +
    +
    + <%= form.label :placement_type_id, "Placement Type" %> +
    + <%= form.collection_select( + :placement_type_id, + PlacementType.for_organization(current_organization).where(name: PlacementType::VALID_NAMES), + :id, :name, + {include_hidden: false, include_blank: "-Select Placement Type-"}, + {class: "form-control"} + ) %> +
    +
    diff --git a/app/views/placements/_form.html.erb b/app/views/placements/_form.html.erb new file mode 100644 index 0000000000..9fbd70827c --- /dev/null +++ b/app/views/placements/_form.html.erb @@ -0,0 +1,26 @@ +
    + <%= form_with(model: placement, url: [casa_case, placement], local: true, + data: { controller: "placement-form", nested_form_wrapper_selector_value: ".nested-form-wrapper" }) do |form| %> +
    +
    +
    Case Number: <%= link_to casa_case.case_number, casa_case %>
    +
    +
    + +
    +
    +
    + <%= render 'placements/fields', placement: placement, form: form, casa_case: casa_case %> +
    + <% end %> +
    diff --git a/app/views/placements/edit.html.erb b/app/views/placements/edit.html.erb new file mode 100644 index 0000000000..1ac06ef77d --- /dev/null +++ b/app/views/placements/edit.html.erb @@ -0,0 +1,11 @@ +
    +
    +
    +
    +

    Editing Placement

    +
    +
    +
    +
    + +<%= render 'form', casa_case: @casa_case, placement: @placement %> diff --git a/app/views/placements/edit_multiple.html.erb b/app/views/placements/edit_multiple.html.erb new file mode 100644 index 0000000000..3378bd3965 --- /dev/null +++ b/app/views/placements/edit_multiple.html.erb @@ -0,0 +1,36 @@ +

    Edit Placements for <%= @casa_case.case_number %>

    + +<%= form_tag update_multiple_casa_case_placements_path(@casa_case), method: :patch do %> + + + + + + + + + + <% @placements.each do |placement| %> + + + + + + <% end %> + +
    Placement TypeStart DateActions
    +
    + <%= text_field_tag "placements[#{placement.id}][placement_type_name]", placement.placement_type.name %> +
    +
    +
    + <%= date_field_tag "placements[#{placement.id}][placement_started_at]", placement.placement_started_at %> +
    +
    + <%= link_to "Delete", edit_casa_case_path(@casa_case), class: 'text-danger' %> +
    + + <%= submit_tag "Update All Placements", class: 'btn btn-primary' %> +<% end %> + +<%= link_to "Cancel", casa_case_placements_path(@casa_case), class: 'btn btn-secondary' %> \ No newline at end of file diff --git a/app/views/placements/index.html.erb b/app/views/placements/index.html.erb new file mode 100644 index 0000000000..8a168ac6f4 --- /dev/null +++ b/app/views/placements/index.html.erb @@ -0,0 +1,38 @@ +
    +
    +
    +
    +

    Placements for + <%= @casa_case.case_number %> +

    +
    +
    +
    +
    +
    +
    + + + + + + + + + + + <% @placements.each_with_index do |placement, idx| %> + + + + + + + <% end %> + +
    Placement TypeStart Date
    <%= placement.placement_type.name %> + <%= placement.placement_started_at.strftime('%B %d, %Y') %> + <%= "- Present" if idx.zero? %> + <%= link_to "Edit", edit_casa_case_placement_path(@casa_case, placement), class: 'text-danger' %><%= link_to "Delete", edit_casa_case_path(@casa_case), class: 'text-danger' %>
    +
    +
    \ No newline at end of file diff --git a/app/views/placements/new.html.erb b/app/views/placements/new.html.erb new file mode 100644 index 0000000000..a66c469829 --- /dev/null +++ b/app/views/placements/new.html.erb @@ -0,0 +1,11 @@ +
    +
    +
    +
    +

    New Placement

    +
    +
    +
    +
    + +<%= render 'form', casa_case: @casa_case, placement: @placement %> diff --git a/app/views/placements/show.html.erb b/app/views/placements/show.html.erb index e8946ea04a..819f17a4d5 100644 --- a/app/views/placements/show.html.erb +++ b/app/views/placements/show.html.erb @@ -8,7 +8,7 @@
    @@ -15,7 +23,7 @@ Placement Type - Start Date + Date @@ -26,16 +34,29 @@ <%= placement.placement_type.name %> <%= placement.placement_started_at.strftime('%B %d, %Y') %> - <%= "- Present" if idx.zero? %> + - + <% if idx.zero? %> + Present + <% elsif @placements[idx - 1].placement_started_at %> + <%= (@placements[idx - 1].placement_started_at - 1.day).strftime('%B %d, %Y') %> + <% end %> - <%= link_to "Edit", edit_casa_case_placement_path(@casa_case, placement), class: 'text-danger' %> - - <%= link_to [@casa_case, @placement], method: :delete, data: { confirm: 'Are you sure?' },class: "btn-sm main-btn danger-btn-outline btn-hover ms-auto" do %> - - Delete + <%= link_to edit_casa_case_placement_path(@casa_case, placement), class: "btn-sm main-btn primary-btn-outline btn-hover ms-auto" do %> + + Edit <% end %> + <%= render(Modal::OpenLinkComponent.new(text: "Delete", target: placement.id, klass: "btn-sm main-btn danger-btn-outline btn-hover ms-auto")) %> + <%= render(Modal::GroupComponent.new(id: placement.id)) do |component| %> + <% component.with_header(text: "Delete Placement?", id: placement.id) %> + <% component.with_footer do %> + <%= link_to casa_case_placement_path(@casa_case, placement), method: :delete, class: "btn-sm main-btn danger-btn btn-hover ms-auto" do %> + + Delete Placement + <% end %> + <% end %> + <% end %> <% end %> From 89e38ffe5fe38a987f5ffcad33b9926867c969c0 Mon Sep 17 00:00:00 2001 From: guswhitten Date: Tue, 13 Aug 2024 06:28:49 -0400 Subject: [PATCH 04/26] cleanup unused things --- app/policies/casa_case_policy.rb | 2 -- app/policies/placement_policy.rb | 1 - app/views/placements/edit_multiple.html.erb | 36 --------------------- app/views/placements/show.html.erb | 32 ------------------ config/environments/test.rb | 2 +- config/routes.rb | 2 +- 6 files changed, 2 insertions(+), 73 deletions(-) delete mode 100644 app/views/placements/edit_multiple.html.erb delete mode 100644 app/views/placements/show.html.erb diff --git a/app/policies/casa_case_policy.rb b/app/policies/casa_case_policy.rb index 036e0382a8..e8f644ea0f 100644 --- a/app/policies/casa_case_policy.rb +++ b/app/policies/casa_case_policy.rb @@ -106,8 +106,6 @@ def index? alias_method :new?, :is_admin_same_org? alias_method :create?, :is_admin_same_org? alias_method :destroy?, :is_admin_same_org? - alias_method :update_multiple?, :edit? - alias_method :edit_multiple?, :edit? private diff --git a/app/policies/placement_policy.rb b/app/policies/placement_policy.rb index 8e174e64fb..d91eb9b174 100644 --- a/app/policies/placement_policy.rb +++ b/app/policies/placement_policy.rb @@ -3,7 +3,6 @@ def allowed_to_edit_casa_case? casa_case_policy.edit? end - alias_method :show?, :allowed_to_edit_casa_case? alias_method :edit?, :allowed_to_edit_casa_case? alias_method :update?, :allowed_to_edit_casa_case? alias_method :new?, :allowed_to_edit_casa_case? diff --git a/app/views/placements/edit_multiple.html.erb b/app/views/placements/edit_multiple.html.erb deleted file mode 100644 index 3378bd3965..0000000000 --- a/app/views/placements/edit_multiple.html.erb +++ /dev/null @@ -1,36 +0,0 @@ -

    Edit Placements for <%= @casa_case.case_number %>

    - -<%= form_tag update_multiple_casa_case_placements_path(@casa_case), method: :patch do %> - - - - - - - - - - <% @placements.each do |placement| %> - - - - - - <% end %> - -
    Placement TypeStart DateActions
    -
    - <%= text_field_tag "placements[#{placement.id}][placement_type_name]", placement.placement_type.name %> -
    -
    -
    - <%= date_field_tag "placements[#{placement.id}][placement_started_at]", placement.placement_started_at %> -
    -
    - <%= link_to "Delete", edit_casa_case_path(@casa_case), class: 'text-danger' %> -
    - - <%= submit_tag "Update All Placements", class: 'btn btn-primary' %> -<% end %> - -<%= link_to "Cancel", casa_case_placements_path(@casa_case), class: 'btn btn-secondary' %> \ No newline at end of file diff --git a/app/views/placements/show.html.erb b/app/views/placements/show.html.erb deleted file mode 100644 index 819f17a4d5..0000000000 --- a/app/views/placements/show.html.erb +++ /dev/null @@ -1,32 +0,0 @@ -
    -
    -
    -
    -

    Placement

    - -
    -
    -
    - -
    -
    -
    -
    -
    -
    -
    -
    Case Number:
    -
    -
    <%= link_to "#{@casa_case.case_number}", casa_case_path(@casa_case) %>
    -
    -
    Placement Type:
    -
    -
    <%= @placement.placement_type.name %>
    -
    -
    -
    diff --git a/config/environments/test.rb b/config/environments/test.rb index 73c0a71c7b..4cb00ebe24 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -9,7 +9,7 @@ # Settings specified here will take precedence over those in config/application.rb. config.action_mailer.default_url_options = {host: "localhost", port: 3000} # for devise authentication # While tests run files are not watched, reloading is not necessary. - config.enable_reloading = true + config.enable_reloading = false # Turn false under Spring and add config.action_view.cache_template_loading = true. config.action_view.cache_template_loading = true diff --git a/config/routes.rb b/config/routes.rb index f08b488782..4c8c023c58 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -65,7 +65,7 @@ resources :court_dates, only: %i[create edit new show update destroy] - resources :placements + resources :placements, only: %i[create edit new update destroy] member do patch :deactivate From 4f441f99b38b39216d9180c7f3d4207eac718406 Mon Sep 17 00:00:00 2001 From: guswhitten Date: Fri, 16 Aug 2024 16:52:15 -0400 Subject: [PATCH 05/26] write unit tests for added placement views --- Gemfile.lock | 105 ++++++++++--------- app/views/casa_cases/_placements.html.erb | 2 +- app/views/placements/index.html.erb | 2 +- config/routes.rb | 2 +- spec/factories/placements.rb | 2 +- spec/views/placements/edit.html.erb_spec.rb | 31 ++++++ spec/views/placements/index.html.erb_spec.rb | 66 ++++++++++++ spec/views/placements/new.html.erb_spec.rb | 20 ++++ 8 files changed, 177 insertions(+), 53 deletions(-) create mode 100644 spec/views/placements/edit.html.erb_spec.rb create mode 100644 spec/views/placements/index.html.erb_spec.rb create mode 100644 spec/views/placements/new.html.erb_spec.rb diff --git a/Gemfile.lock b/Gemfile.lock index 4f4cf242a9..4b7e540995 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -109,13 +109,13 @@ GEM smart_properties bigdecimal (3.1.8) bindex (0.8.1) - blueprinter (1.0.2) + blueprinter (1.1.0) brakeman (6.1.2) racc bugsnag (6.27.1) concurrent-ruby (~> 1.0) builder (3.3.0) - bullet (7.1.6) + bullet (7.2.0) activesupport (>= 3.0.0) uniform_notifier (~> 1.11) bundler-audit (0.9.1) @@ -142,16 +142,17 @@ GEM caxlsx_rails (0.6.4) actionpack (>= 3.1) caxlsx (>= 3.0) - childprocess (5.0.0) + childprocess (5.1.0) + logger (~> 1.5) cliver (0.3.2) coderay (1.1.3) - concurrent-ruby (1.3.3) + concurrent-ruby (1.3.4) connection_pool (2.4.1) crack (1.0.0) bigdecimal rexml crass (1.0.6) - cssbundling-rails (1.4.0) + cssbundling-rails (1.4.1) railties (>= 6.0.0) csv (3.3.0) database_cleaner-active_record (2.2.0) @@ -159,9 +160,9 @@ GEM database_cleaner-core (~> 2.0.0) database_cleaner-core (2.0.1) date (3.3.4) - delayed_job (4.1.11) + delayed_job (4.1.12) activesupport (>= 3.0, < 8.0) - delayed_job_active_record (4.1.8) + delayed_job_active_record (4.1.9) activerecord (>= 3.0, < 8.0) delayed_job (>= 3.0, < 5) devise (4.9.4) @@ -174,7 +175,7 @@ GEM actionmailer (>= 5.0) devise (>= 4.6) diff-lcs (1.5.1) - docile (1.4.0) + docile (1.4.1) docx (0.8.0) nokogiri (~> 1.13, >= 1.13.0) rubyzip (~> 2.0) @@ -202,7 +203,7 @@ GEM rubocop (>= 1) smart_properties erubi (1.13.0) - factory_bot (6.4.5) + factory_bot (6.4.6) activesupport (>= 5.0.0) factory_bot_rails (6.4.3) factory_bot (~> 6.4) @@ -227,14 +228,17 @@ GEM faraday-httpclient (1.0.1) faraday-multipart (1.0.4) multipart-post (~> 2) - faraday-net_http (1.0.1) + faraday-net_http (1.0.2) faraday-net_http_persistent (1.2.0) faraday-patron (1.0.0) faraday-rack (1.0.0) faraday-retry (1.0.3) faraday_middleware (1.2.0) faraday (~> 1.0) - ffi (1.16.3) + ffi (1.17.0) + ffi (1.17.0-arm64-darwin) + ffi (1.17.0-x86_64-darwin) + ffi (1.17.0-x86_64-linux-gnu) filterrific (5.2.5) flipper (1.3.0) concurrent-ruby (< 2) @@ -254,7 +258,7 @@ GEM activesupport (>= 6.1) groupdate (6.4.0) activesupport (>= 6.1) - hashdiff (1.1.0) + hashdiff (1.1.1) htmlentities (4.3.4) httparty (0.22.0) csv @@ -262,7 +266,7 @@ GEM multi_xml (>= 0.5.2) i18n (1.14.5) concurrent-ruby (~> 1.0) - image_processing (1.12.2) + image_processing (1.13.0) mini_magick (>= 4.9.5, < 5) ruby-vips (>= 2.0.17, < 3) io-console (0.7.2) @@ -272,10 +276,10 @@ GEM jbuilder (2.12.0) actionview (>= 5.0.0) activesupport (>= 5.0.0) - jsbundling-rails (1.3.0) + jsbundling-rails (1.3.1) railties (>= 6.0.0) json (2.7.2) - json-schema (4.1.1) + json-schema (4.3.1) addressable (>= 2.8) jwt (2.8.2) base64 @@ -303,15 +307,15 @@ GEM marcel (1.0.4) matrix (0.4.2) method_source (1.1.0) - mini_magick (4.11.0) + mini_magick (4.13.2) mini_mime (1.1.5) mini_portile2 (2.8.7) - minitest (5.24.1) + minitest (5.25.0) multi_xml (0.7.1) bigdecimal (~> 3.1) multipart-post (2.4.1) mutex_m (0.2.0) - net-http-persistent (4.0.1) + net-http-persistent (4.0.2) connection_pool (~> 2.2) net-imap (0.4.14) date @@ -334,15 +338,17 @@ GEM racc (~> 1.4) noticed (2.4.1) rails (>= 6.1.0) - oj (3.16.4) + oj (3.16.5) bigdecimal (>= 3.0) + ostruct (>= 0.2) orm_adapter (0.5.0) - parallel (1.25.1) + ostruct (0.6.0) + parallel (1.26.2) parallel_tests (4.7.1) parallel - paranoia (2.6.4) - activerecord (>= 5.1, < 7.2) - parser (3.3.4.0) + paranoia (3.0.0) + activerecord (>= 6, < 8.1) + parser (3.3.4.2) ast (~> 2.4.1) racc pdf-forms (1.5.1) @@ -366,21 +372,21 @@ GEM pundit (2.3.2) activesupport (>= 3.0.0) racc (1.8.1) - rack (2.2.9) + rack (3.1.7) rack-attack (6.7.0) rack (>= 1.0, < 4) - rack-cors (2.0.1) + rack-cors (2.0.2) rack (>= 2.0.0) - rack-protection (3.2.0) + rack-protection (4.0.0) base64 (>= 0.1.0) - rack (~> 2.2, >= 2.2.4) - rack-session (1.0.2) - rack (< 3) + rack (>= 3.0.0, < 4) + rack-session (2.0.0) + rack (>= 3.0.0) rack-test (2.1.0) rack (>= 1.3) - rackup (1.0.0) - rack (< 3) - webrick + rackup (2.1.0) + rack (>= 3) + webrick (~> 1.8) rails (7.1.3.4) actioncable (= 7.1.3.4) actionmailbox (= 7.1.3.4) @@ -426,7 +432,7 @@ GEM responders (3.1.1) actionpack (>= 5.2) railties (>= 5.2) - rexml (3.3.4) + rexml (3.3.5) strscan rspec-core (3.13.0) rspec-support (~> 3.13.0) @@ -436,7 +442,7 @@ GEM rspec-mocks (3.13.1) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.13.0) - rspec-rails (6.1.3) + rspec-rails (6.1.4) actionpack (>= 6.1) activesupport (>= 6.1) railties (>= 6.1) @@ -447,17 +453,17 @@ GEM rspec-support (3.13.1) rspec_junit_formatter (0.6.0) rspec-core (>= 2, < 4, != 2.12.0) - rswag-api (2.13.0) - activesupport (>= 3.1, < 7.2) - railties (>= 3.1, < 7.2) - rswag-specs (2.13.0) - activesupport (>= 3.1, < 7.2) + rswag-api (2.14.0) + activesupport (>= 5.2, < 8.0) + railties (>= 5.2, < 8.0) + rswag-specs (2.14.0) + activesupport (>= 5.2, < 8.0) json-schema (>= 2.2, < 5.0) - railties (>= 3.1, < 7.2) + railties (>= 5.2, < 8.0) rspec-core (>= 2.14) - rswag-ui (2.13.0) - actionpack (>= 3.1, < 7.2) - railties (>= 3.1, < 7.2) + rswag-ui (2.14.0) + actionpack (>= 5.2, < 8.0) + railties (>= 5.2, < 8.0) rubocop (1.64.1) json (~> 2.3) language_server-protocol (>= 3.17.0) @@ -475,15 +481,16 @@ GEM rubocop (>= 1.48.1, < 2.0) rubocop-ast (>= 1.31.1, < 2.0) ruby-progressbar (1.13.0) - ruby-vips (2.1.4) + ruby-vips (2.2.2) ffi (~> 1.12) + logger ruby2_keywords (0.0.5) rubyzip (2.3.2) - sablon (0.3.2) + sablon (0.4.1) nokogiri (>= 1.8.5) - rubyzip (>= 1.1.1) + rubyzip (>= 1.3.0) safe_shell (1.1.0) - sanitize (6.1.1) + sanitize (6.1.3) crass (~> 1.0.2) nokogiri (>= 1.12.0) scout_apm (5.3.8) @@ -494,7 +501,7 @@ GEM rexml (~> 3.2, >= 3.2.5) rubyzip (>= 1.2.2, < 3.0) websocket (~> 1.0) - shoulda-matchers (6.2.0) + shoulda-matchers (6.3.1) activesupport (>= 5.2.0) simplecov (0.22.0) docile (~> 1.1) @@ -543,7 +550,7 @@ GEM concurrent-ruby (~> 1.0) unicode-display_width (2.5.0) uniform_notifier (1.16.0) - view_component (3.12.1) + view_component (3.13.0) activesupport (>= 5.2.0, < 8.0) concurrent-ruby (~> 1.0) method_source (~> 1.0) diff --git a/app/views/casa_cases/_placements.html.erb b/app/views/casa_cases/_placements.html.erb index a14de4c000..b21abe492f 100644 --- a/app/views/casa_cases/_placements.html.erb +++ b/app/views/casa_cases/_placements.html.erb @@ -16,7 +16,7 @@ <%= render(DropdownMenuComponent.new(menu_title: "Actions Menu", hide_label: true, klass: "placement-dropdown")) do %>
  • <%= link_to "Show All", casa_case_placements_path(casa_case), class: "dropdown-item" %>
  • -
  • <%= link_to "New", new_casa_case_placement_path(casa_case), class: "dropdown-item" %>
  • +
  • <%= link_to "Edit", new_casa_case_placement_path(casa_case), class: "dropdown-item" %>
  • <%= render(Modal::OpenLinkComponent.new(text: "Delete", target: current_placement.id, klass: "dropdown-item")) %>
  • <% end %> diff --git a/app/views/placements/index.html.erb b/app/views/placements/index.html.erb index b92884ce6c..9386124cb8 100644 --- a/app/views/placements/index.html.erb +++ b/app/views/placements/index.html.erb @@ -9,7 +9,7 @@
    -
    \ No newline at end of file + diff --git a/spec/views/placements/edit.html.erb_spec.rb b/spec/views/placements/edit.html.erb_spec.rb index 1271c111b0..8e433c767d 100644 --- a/spec/views/placements/edit.html.erb_spec.rb +++ b/spec/views/placements/edit.html.erb_spec.rb @@ -5,9 +5,9 @@ let(:organization) { create(:casa_org) } let(:user) { build_stubbed(:casa_admin, casa_org: organization) } - let(:casa_case) { create(:casa_case, casa_org: organization, case_number: '123') } - let(:placement_type) { create(:placement_type, name: 'Reunification') } - let(:placement) { create(:placement, placement_started_at: '2024-08-15 12:39:00 UTC', placement_type:, casa_case:) } + let(:casa_case) { create(:casa_case, casa_org: organization, case_number: "123") } + let(:placement_type) { create(:placement_type, name: "Reunification") } + let(:placement) { create(:placement, placement_started_at: "2024-08-15 12:39:00 UTC", placement_type:, casa_case:) } before do assign :casa_case, casa_case diff --git a/spec/views/placements/index.html.erb_spec.rb b/spec/views/placements/index.html.erb_spec.rb index 480a927ed6..82f511c00a 100644 --- a/spec/views/placements/index.html.erb_spec.rb +++ b/spec/views/placements/index.html.erb_spec.rb @@ -1,18 +1,18 @@ -require 'rails_helper' +require "rails_helper" -RSpec.describe 'placements/index', type: :view do +RSpec.describe "placements/index", type: :view do subject { render template: "placements/edit" } - let(:casa_case) { create(:casa_case, case_number: 'CINA-12345') } - let(:placement_type_current) { create(:placement_type, name: 'Reunification') } - let(:placement_type_prev) { create(:placement_type, name: 'Custody/Guardianship by a relative') } - let(:placement_type_first) { create(:placement_type, name: 'APPLA') } + let(:casa_case) { create(:casa_case, case_number: "CINA-12345") } + let(:placement_type_current) { create(:placement_type, name: "Reunification") } + let(:placement_type_prev) { create(:placement_type, name: "Custody/Guardianship by a relative") } + let(:placement_type_first) { create(:placement_type, name: "APPLA") } let(:placements) do [ - create(:placement, placement_started_at: '2024-08-15 20:40:44 UTC', casa_case:, placement_type: placement_type_current), - create(:placement, placement_started_at: '2023-06-02 00:00:00 UTC', casa_case:, placement_type: placement_type_prev), - create(:placement, placement_started_at: '2021-12-25 10:10:10 UTC', casa_case:, placement_type: placement_type_first) + create(:placement, placement_started_at: "2024-08-15 20:40:44 UTC", casa_case:, placement_type: placement_type_current), + create(:placement, placement_started_at: "2023-06-02 00:00:00 UTC", casa_case:, placement_type: placement_type_prev), + create(:placement, placement_started_at: "2021-12-25 10:10:10 UTC", casa_case:, placement_type: placement_type_first) ] end @@ -23,44 +23,44 @@ render end - it 'displays the case number in the header' do - expect(rendered).to have_selector('h1', text: "CINA-12345") + it "displays the case number in the header" do + expect(rendered).to have_selector("h1", text: "CINA-12345") end - it 'has a link to create a new placement' do - expect(rendered).to have_link('New Placement', href: new_casa_case_placement_path(casa_case)) + it "has a link to create a new placement" do + expect(rendered).to have_link("New Placement", href: new_casa_case_placement_path(casa_case)) end - it 'displays placement information for each placement' do - expect(rendered).to have_content('Reunification') + it "displays placement information for each placement" do + expect(rendered).to have_content("Reunification") expect(rendered).to have_content(/August 15, 2024\s*-\s*Present/) - expect(rendered).to have_content('Custody/Guardianship by a relative') + expect(rendered).to have_content("Custody/Guardianship by a relative") expect(rendered).to have_content(/June 02, 2023\s*-\s*August 14, 2024/) - expect(rendered).to have_content('APPLA') + expect(rendered).to have_content("APPLA") expect(rendered).to have_content(/December 25, 2021\s*-\s*June 01, 2023/) end - it 'has edit links for each placement' do + it "has edit links for each placement" do placements.each do |placement| - expect(rendered).to have_link('Edit', href: edit_casa_case_placement_path(casa_case, placement)) + expect(rendered).to have_link("Edit", href: edit_casa_case_placement_path(casa_case, placement)) end end - it 'has delete buttons for each placement' do + it "has delete buttons for each placement" do placements.each do |placement| - expect(rendered).to have_selector("a[data-bs-target='##{placement.id}']", text: 'Delete') + expect(rendered).to have_selector("a[data-bs-target='##{placement.id}']", text: "Delete") end end - it 'renders delete confirmation modals for each placement' do + it "renders delete confirmation modals for each placement" do placements.each do |placement| expect(rendered).to have_selector("##{placement.id}.modal") within "##{placement.id}" do - expect(rendered).to have_content('Delete Placement?') - expect(rendered).to have_link('Delete Placement', href: casa_case_placement_path(casa_case, placement)) + expect(rendered).to have_content("Delete Placement?") + expect(rendered).to have_link("Delete Placement", href: casa_case_placement_path(casa_case, placement)) end end end -end \ No newline at end of file +end From 00d522d4b1efc0708a9e6aee12a5bb56d590f5ae Mon Sep 17 00:00:00 2001 From: guswhitten Date: Fri, 16 Aug 2024 17:55:00 -0400 Subject: [PATCH 07/26] ensure placement_types are not hardcoded but still org-specific --- app/controllers/placements_controller.rb | 24 ++++++++++---------- app/models/casa_org.rb | 1 + app/models/placement_type.rb | 15 +----------- app/views/casa_cases/_placements.html.erb | 2 +- app/views/placements/_fields.html.erb | 2 +- spec/factories/casa_orgs.rb | 10 ++++++++ spec/factories/placement_types.rb | 2 +- spec/views/placements/index.html.erb_spec.rb | 21 ++++++++--------- 8 files changed, 37 insertions(+), 40 deletions(-) diff --git a/app/controllers/placements_controller.rb b/app/controllers/placements_controller.rb index e77509f9a2..883d67d9f5 100644 --- a/app/controllers/placements_controller.rb +++ b/app/controllers/placements_controller.rb @@ -1,6 +1,6 @@ class PlacementsController < ApplicationController before_action :set_casa_case - before_action :set_placement, only: %i[edit update destroy] + before_action :set_placement, only: %i[edit show generate update destroy] before_action :require_organization! rescue_from ActiveRecord::RecordNotFound, with: -> { head :not_found } @@ -19,29 +19,29 @@ def edit authorize @casa_case end - def update + def create + @placement = Placement.new(placement_params) authorize @placement - if @placement.update(placement_params) - redirect_to casa_case_placements_path(@casa_case), notice: "Placement was successfully updated." + if @placement.save + redirect_to casa_case_placements_path(@casa_case), notice: "Placement was successfully created." else - render :edit, status: :unprocessable_entity + Rails.logger.error("Placement creation failed: #{@placement.errors.full_messages}") + flash.now[:alert] = "Failed to create placement: #{@placement.errors.full_messages.join(", ")}" + render :new, status: :unprocessable_entity end rescue Pundit::NotAuthorizedError => e Rails.logger.error("Authorization failed: #{e.message}") redirect_to casa_case_placements_path, alert: "You are not authorized to create a placement for this case." end - def create - @placement = Placement.new(placement_params) + def update authorize @placement - if @placement.save - redirect_to casa_case_placements_path(@casa_case), notice: "Placement was successfully created." + if @placement.update(placement_params) + redirect_to casa_case_placements_path(@casa_case), notice: "Placement was successfully updated." else - Rails.logger.error("Placement creation failed: #{@placement.errors.full_messages}") - flash.now[:alert] = "Failed to create placement: #{@placement.errors.full_messages.join(", ")}" - render :new, status: :unprocessable_entity + render :edit, status: :unprocessable_entity end rescue Pundit::NotAuthorizedError => e Rails.logger.error("Authorization failed: #{e.message}") diff --git a/app/models/casa_org.rb b/app/models/casa_org.rb index b5b9c7461c..7aed3f2ab1 100644 --- a/app/models/casa_org.rb +++ b/app/models/casa_org.rb @@ -28,6 +28,7 @@ class CasaOrg < ApplicationRecord has_many :contact_topics has_one_attached :logo has_one_attached :court_report_template + has_many :placement_types, dependent: :destroy def casa_admins CasaAdmin.in_organization(self) diff --git a/app/models/placement_type.rb b/app/models/placement_type.rb index 43edd1f42b..b76fa08f6f 100644 --- a/app/models/placement_type.rb +++ b/app/models/placement_type.rb @@ -1,21 +1,8 @@ class PlacementType < ApplicationRecord belongs_to :casa_org - VALID_NAMES = [ - "Reunification", - "Custody/Guardianship by a relative", - "Custody/Guardianship by a non-relative", - "Adoption by relative", - "Adoption by a non-relative", - "APPLA" - ].freeze - - validates :name, presence: true, inclusion: {in: VALID_NAMES} + validates :name, presence: true scope :for_organization, ->(org) { where(casa_org: org).order(:name) } - - def self.valid_names - VALID_NAMES - end end # == Schema Information diff --git a/app/views/casa_cases/_placements.html.erb b/app/views/casa_cases/_placements.html.erb index 43aea63e74..cd6917d06c 100644 --- a/app/views/casa_cases/_placements.html.erb +++ b/app/views/casa_cases/_placements.html.erb @@ -16,7 +16,7 @@ <%= render(DropdownMenuComponent.new(menu_title: "Actions Menu", hide_label: true, klass: "placement-dropdown")) do %>
  • <%= link_to "Show All", casa_case_placements_path(casa_case), class: "dropdown-item" %>
  • -
  • <%= link_to "Edit", new_casa_case_placement_path(casa_case), class: "dropdown-item" %>
  • +
  • <%= link_to "Edit", edit_casa_case_placement_path(casa_case, current_placement), class: "dropdown-item" %>
  • <%= render(Modal::OpenLinkComponent.new(text: "Delete", target: current_placement.id, klass: "dropdown-item")) %>
  • <% end %> diff --git a/app/views/placements/_fields.html.erb b/app/views/placements/_fields.html.erb index c33f80a62e..1e08f20116 100644 --- a/app/views/placements/_fields.html.erb +++ b/app/views/placements/_fields.html.erb @@ -9,7 +9,7 @@
    <%= form.collection_select( :placement_type_id, - PlacementType.for_organization(current_organization).where(name: PlacementType::VALID_NAMES), + PlacementType.for_organization(current_organization), :id, :name, {include_hidden: false, include_blank: "-Select Placement Type-"}, {class: "form-control"} diff --git a/spec/factories/casa_orgs.rb b/spec/factories/casa_orgs.rb index bfdcb99331..f06d845768 100644 --- a/spec/factories/casa_orgs.rb +++ b/spec/factories/casa_orgs.rb @@ -12,5 +12,15 @@ trait :with_logo do logo { Rack::Test::UploadedFile.new(Rails.root.join("spec", "fixtures", "org_logo.jpeg")) } end + + trait :with_placement_types do + transient { placement_types { ["Reunification", "Adoption", "Foster Care", "Kinship"] } } + + after(:create) do |org, evaluator| + evaluator.placement_types.each do |name| + org.placement_types.create!(name: name) + end + end + end end end diff --git a/spec/factories/placement_types.rb b/spec/factories/placement_types.rb index a85de92a1e..978098934d 100644 --- a/spec/factories/placement_types.rb +++ b/spec/factories/placement_types.rb @@ -1,6 +1,6 @@ FactoryBot.define do factory :placement_type do - sequence(:name) { |n| "Placement Type #{n}" } casa_org + sequence(:name) { |n| "Placement Type #{n}" } end end diff --git a/spec/views/placements/index.html.erb_spec.rb b/spec/views/placements/index.html.erb_spec.rb index 82f511c00a..f5113367a4 100644 --- a/spec/views/placements/index.html.erb_spec.rb +++ b/spec/views/placements/index.html.erb_spec.rb @@ -1,18 +1,17 @@ require "rails_helper" RSpec.describe "placements/index", type: :view do - subject { render template: "placements/edit" } - - let(:casa_case) { create(:casa_case, case_number: "CINA-12345") } - let(:placement_type_current) { create(:placement_type, name: "Reunification") } - let(:placement_type_prev) { create(:placement_type, name: "Custody/Guardianship by a relative") } - let(:placement_type_first) { create(:placement_type, name: "APPLA") } + let(:casa_org) { create(:casa_org, :with_placement_types) } + let(:casa_case) { create(:casa_case, casa_org:, case_number: "CINA-12345") } + let(:placement_current) { create(:placement_type, name: "Reunification", casa_org:) } + let(:placement_prev) { create(:placement_type, name: "Kinship", casa_org:) } + let(:placement_first) { create(:placement_type, name: "Adoption", casa_org:) } let(:placements) do [ - create(:placement, placement_started_at: "2024-08-15 20:40:44 UTC", casa_case:, placement_type: placement_type_current), - create(:placement, placement_started_at: "2023-06-02 00:00:00 UTC", casa_case:, placement_type: placement_type_prev), - create(:placement, placement_started_at: "2021-12-25 10:10:10 UTC", casa_case:, placement_type: placement_type_first) + create(:placement, placement_started_at: "2024-08-15 20:40:44 UTC", casa_case:, placement_type: placement_current), + create(:placement, placement_started_at: "2023-06-02 00:00:00 UTC", casa_case:, placement_type: placement_prev), + create(:placement, placement_started_at: "2021-12-25 10:10:10 UTC", casa_case:, placement_type: placement_first) ] end @@ -35,10 +34,10 @@ expect(rendered).to have_content("Reunification") expect(rendered).to have_content(/August 15, 2024\s*-\s*Present/) - expect(rendered).to have_content("Custody/Guardianship by a relative") + expect(rendered).to have_content("Kinship") expect(rendered).to have_content(/June 02, 2023\s*-\s*August 14, 2024/) - expect(rendered).to have_content("APPLA") + expect(rendered).to have_content("Adoption") expect(rendered).to have_content(/December 25, 2021\s*-\s*June 01, 2023/) end From d2c47c2a1e5660968b07c4856ad21efa3bf8f09e Mon Sep 17 00:00:00 2001 From: guswhitten Date: Fri, 16 Aug 2024 18:09:24 -0400 Subject: [PATCH 08/26] add back placement show action and placement decorators --- app/controllers/placements_controller.rb | 4 +++ app/decorators/placement_decorator.rb | 2 +- app/views/casa_cases/_placements.html.erb | 3 +-- app/views/placements/show.html.erb | 32 +++++++++++++++++++++++ 4 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 app/views/placements/show.html.erb diff --git a/app/controllers/placements_controller.rb b/app/controllers/placements_controller.rb index 883d67d9f5..4430cb8bdf 100644 --- a/app/controllers/placements_controller.rb +++ b/app/controllers/placements_controller.rb @@ -10,6 +10,10 @@ def index @placements = @casa_case.placements.includes(:placement_type).order(placement_started_at: :desc) end + def show + authorize @casa_case + end + def new authorize @casa_case @placement = Placement.new diff --git a/app/decorators/placement_decorator.rb b/app/decorators/placement_decorator.rb index b5294c7a31..183e174a83 100644 --- a/app/decorators/placement_decorator.rb +++ b/app/decorators/placement_decorator.rb @@ -6,7 +6,7 @@ def formatted_date end def placement_info - [formatted_date, placement_type&.name&.to_s].compact.join(" - ") + ["Started At: #{formatted_date}", "Placement Type: #{placement_type&.name}"].compact.join(" - ") end def placement_started_at diff --git a/app/views/casa_cases/_placements.html.erb b/app/views/casa_cases/_placements.html.erb index cd6917d06c..1df58dcffc 100644 --- a/app/views/casa_cases/_placements.html.erb +++ b/app/views/casa_cases/_placements.html.erb @@ -1,5 +1,4 @@ -<% placements = casa_case.placements.includes(:placement_type) %> -<% current_placement = placements.order(placement_started_at: :desc).first %> +<% current_placement = casa_case.placements.order(placement_started_at: :desc).first %> <% if current_placement %> diff --git a/app/views/placements/show.html.erb b/app/views/placements/show.html.erb new file mode 100644 index 0000000000..819f17a4d5 --- /dev/null +++ b/app/views/placements/show.html.erb @@ -0,0 +1,32 @@ +
    +
    +
    +
    +

    Placement

    + +
    +
    +
    + +
    +
    +
    +
    +
    +
    +
    +
    Case Number:
    +
    +
    <%= link_to "#{@casa_case.case_number}", casa_case_path(@casa_case) %>
    +
    +
    Placement Type:
    +
    +
    <%= @placement.placement_type.name %>
    +
    +
    +
    From bf36ae1a9cb2f111e999e83b21c57003e0bc835c Mon Sep 17 00:00:00 2001 From: guswhitten Date: Fri, 16 Aug 2024 18:11:00 -0400 Subject: [PATCH 09/26] undo placement_types factory change --- spec/factories/placement_types.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/factories/placement_types.rb b/spec/factories/placement_types.rb index 978098934d..a85de92a1e 100644 --- a/spec/factories/placement_types.rb +++ b/spec/factories/placement_types.rb @@ -1,6 +1,6 @@ FactoryBot.define do factory :placement_type do - casa_org sequence(:name) { |n| "Placement Type #{n}" } + casa_org end end From 6fe1d04adaf038492a5bdcabe8b9849e6097eaaa Mon Sep 17 00:00:00 2001 From: guswhitten Date: Fri, 16 Aug 2024 18:21:25 -0400 Subject: [PATCH 10/26] fix-5780: add placement_policy_spec.rb --- app/policies/placement_policy.rb | 2 ++ config/environments/test.rb | 2 +- spec/policies/placement_policy_spec.rb | 45 ++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 spec/policies/placement_policy_spec.rb diff --git a/app/policies/placement_policy.rb b/app/policies/placement_policy.rb index d91eb9b174..f25fe27efa 100644 --- a/app/policies/placement_policy.rb +++ b/app/policies/placement_policy.rb @@ -3,6 +3,8 @@ def allowed_to_edit_casa_case? casa_case_policy.edit? end + alias_method :index?, :allowed_to_edit_casa_case? + alias_method :show?, :allowed_to_edit_casa_case? alias_method :edit?, :allowed_to_edit_casa_case? alias_method :update?, :allowed_to_edit_casa_case? alias_method :new?, :allowed_to_edit_casa_case? diff --git a/config/environments/test.rb b/config/environments/test.rb index 4cb00ebe24..73c0a71c7b 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -9,7 +9,7 @@ # Settings specified here will take precedence over those in config/application.rb. config.action_mailer.default_url_options = {host: "localhost", port: 3000} # for devise authentication # While tests run files are not watched, reloading is not necessary. - config.enable_reloading = false + config.enable_reloading = true # Turn false under Spring and add config.action_view.cache_template_loading = true. config.action_view.cache_template_loading = true diff --git a/spec/policies/placement_policy_spec.rb b/spec/policies/placement_policy_spec.rb new file mode 100644 index 0000000000..c97622fae5 --- /dev/null +++ b/spec/policies/placement_policy_spec.rb @@ -0,0 +1,45 @@ +require "rails_helper" + +RSpec.describe PlacementPolicy do + subject { described_class } + + let(:casa_org) { create(:casa_org) } + let(:diff_org) { create(:casa_org) } + + let(:placement) { create(:placement, casa_case:) } + let(:casa_case) { create(:casa_case, casa_org:) } + + let(:casa_admin) { create(:casa_admin, casa_org:) } + let(:volunteer) { create(:volunteer, casa_org:) } + let(:supervisor) { create(:supervisor, casa_org:) } + + permissions :index?, :new?, :create?, :edit?, :update?, :show? do + it { is_expected.to permit(casa_admin, placement) } + + context "when a supervisor belongs to the same org as the case" do + it { expect(subject).to permit(supervisor, placement) } + end + + context "when a supervisor does not belong to the same org as the case" do + let(:casa_case) { create(:casa_case, casa_org: diff_org) } + + it { expect(subject).not_to permit(supervisor, placement) } + end + + context "when volunteer is assigned" do + before { volunteer.casa_cases << casa_case } + + it { is_expected.to permit(volunteer, placement) } + end + + context "when volunteer is not assigned" do + it { is_expected.not_to permit(volunteer, placement) } + end + end + + permissions :destroy? do + it { is_expected.to permit(casa_admin, placement) } + it { is_expected.to permit(supervisor, placement) } + it { is_expected.not_to permit(volunteer, placement) } + end +end From cca8df11308ec019153687bb42bad9870ae009ce Mon Sep 17 00:00:00 2001 From: guswhitten Date: Fri, 16 Aug 2024 18:22:26 -0400 Subject: [PATCH 11/26] undo config change --- config/environments/test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/environments/test.rb b/config/environments/test.rb index 73c0a71c7b..4cb00ebe24 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -9,7 +9,7 @@ # Settings specified here will take precedence over those in config/application.rb. config.action_mailer.default_url_options = {host: "localhost", port: 3000} # for devise authentication # While tests run files are not watched, reloading is not necessary. - config.enable_reloading = true + config.enable_reloading = false # Turn false under Spring and add config.action_view.cache_template_loading = true. config.action_view.cache_template_loading = true From c49f4271dc4476cd62cb31c0a8c6fd8f852a9147 Mon Sep 17 00:00:00 2001 From: guswhitten Date: Sat, 17 Aug 2024 11:44:17 -0400 Subject: [PATCH 12/26] fix failing tests for casa_case.show --- app/views/casa_cases/_placements.html.erb | 2 +- spec/views/casa_cases/show.html.erb_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/casa_cases/_placements.html.erb b/app/views/casa_cases/_placements.html.erb index 1df58dcffc..583225968d 100644 --- a/app/views/casa_cases/_placements.html.erb +++ b/app/views/casa_cases/_placements.html.erb @@ -31,5 +31,5 @@ <% end %>
    <% else %> -

    No placements found.

    +

    No Placements

    <% end %> diff --git a/spec/views/casa_cases/show.html.erb_spec.rb b/spec/views/casa_cases/show.html.erb_spec.rb index a6ffdec3ab..b775e1175d 100644 --- a/spec/views/casa_cases/show.html.erb_spec.rb +++ b/spec/views/casa_cases/show.html.erb_spec.rb @@ -61,7 +61,7 @@ render expect(rendered).to match("111") - expect(rendered).to match("May 6, 2023") + expect(rendered).to match("May 06, 2023 - Present") end end From 1de908cf2b3feff1f97bd2dba106bad637150341 Mon Sep 17 00:00:00 2001 From: guswhitten Date: Mon, 19 Aug 2024 08:23:31 -0400 Subject: [PATCH 13/26] clean up placements, remove most added error handling and _placements partial table --- app/assets/stylesheets/pages/casa_cases.scss | 7 --- app/controllers/placements_controller.rb | 19 +++----- app/policies/placement_policy.rb | 14 +++--- app/views/casa_cases/_placements.html.erb | 46 ++++++-------------- app/views/placements/index.html.erb | 15 ++++--- 5 files changed, 35 insertions(+), 66 deletions(-) diff --git a/app/assets/stylesheets/pages/casa_cases.scss b/app/assets/stylesheets/pages/casa_cases.scss index 0e30645519..34ad221b4f 100644 --- a/app/assets/stylesheets/pages/casa_cases.scss +++ b/app/assets/stylesheets/pages/casa_cases.scss @@ -169,11 +169,4 @@ body.casa_cases-show { flex-direction: column; gap: .2rem; } -} - -.placement-dropdown { - .dropdown-toggle { - background: none; - border: none; - } } \ No newline at end of file diff --git a/app/controllers/placements_controller.rb b/app/controllers/placements_controller.rb index 4430cb8bdf..c94c89503b 100644 --- a/app/controllers/placements_controller.rb +++ b/app/controllers/placements_controller.rb @@ -3,8 +3,6 @@ class PlacementsController < ApplicationController before_action :set_placement, only: %i[edit show generate update destroy] before_action :require_organization! - rescue_from ActiveRecord::RecordNotFound, with: -> { head :not_found } - def index authorize @casa_case @placements = @casa_case.placements.includes(:placement_type).order(placement_started_at: :desc) @@ -30,13 +28,8 @@ def create if @placement.save redirect_to casa_case_placements_path(@casa_case), notice: "Placement was successfully created." else - Rails.logger.error("Placement creation failed: #{@placement.errors.full_messages}") - flash.now[:alert] = "Failed to create placement: #{@placement.errors.full_messages.join(", ")}" render :new, status: :unprocessable_entity end - rescue Pundit::NotAuthorizedError => e - Rails.logger.error("Authorization failed: #{e.message}") - redirect_to casa_case_placements_path, alert: "You are not authorized to create a placement for this case." end def update @@ -47,9 +40,6 @@ def update else render :edit, status: :unprocessable_entity end - rescue Pundit::NotAuthorizedError => e - Rails.logger.error("Authorization failed: #{e.message}") - redirect_to casa_case_placements_path, alert: "You are not authorized to create a placement for this case." end def destroy @@ -59,13 +49,14 @@ def destroy else render :edit, status: :unprocessable_entity end - rescue Pundit::NotAuthorizedError => e - Rails.logger.error("Authorization failed: #{e.message}") - redirect_to casa_case_placements_path, alert: "You are not authorized to delete placements for this case." end private + def authorize_placement + authorize @placement, policy_class: PlacementPolicy + end + def set_casa_case @casa_case = current_organization.casa_cases.friendly.find(params[:casa_case_id]) end @@ -78,6 +69,6 @@ def placement_params params.require(:placement).permit( :placement_started_at, :placement_type_id - ).merge({creator_id: current_user.id, casa_case_id: @casa_case.id}) + ).merge({ creator_id: current_user.id, casa_case_id: @casa_case.id }) end end diff --git a/app/policies/placement_policy.rb b/app/policies/placement_policy.rb index f25fe27efa..f9b5d4c1d7 100644 --- a/app/policies/placement_policy.rb +++ b/app/policies/placement_policy.rb @@ -3,13 +3,13 @@ def allowed_to_edit_casa_case? casa_case_policy.edit? end - alias_method :index?, :allowed_to_edit_casa_case? - alias_method :show?, :allowed_to_edit_casa_case? - alias_method :edit?, :allowed_to_edit_casa_case? - alias_method :update?, :allowed_to_edit_casa_case? - alias_method :new?, :allowed_to_edit_casa_case? - alias_method :create?, :allowed_to_edit_casa_case? - alias_method :destroy?, :admin_or_supervisor? + alias index? allowed_to_edit_casa_case? + alias show? allowed_to_edit_casa_case? + alias edit? allowed_to_edit_casa_case? + alias update? allowed_to_edit_casa_case? + alias new? allowed_to_edit_casa_case? + alias create? allowed_to_edit_casa_case? + alias destroy? admin_or_supervisor? private diff --git a/app/views/casa_cases/_placements.html.erb b/app/views/casa_cases/_placements.html.erb index 583225968d..eae1b4bdae 100644 --- a/app/views/casa_cases/_placements.html.erb +++ b/app/views/casa_cases/_placements.html.erb @@ -1,35 +1,15 @@ <% current_placement = casa_case.placements.order(placement_started_at: :desc).first %> -<% if current_placement %> - - - - - - - - - - - - - - <%= render(Modal::GroupComponent.new(id: current_placement.id)) do |component| %> - <% component.with_header(text: "Delete Current Placement?", id: current_placement.id) %> - <% component.with_footer do %> - <%= link_to casa_case_placement_path(@casa_case, current_placement), method: :delete, class: "btn-sm main-btn danger-btn btn-hover ms-auto" do %> - - Delete Placement - <% end %> - <% end %> - <% end %> -
    PlacementDateActions
    <%= current_placement.placement_type.name %><%= current_placement.placement_started_at.strftime('%B %d, %Y') %> - Present - <%= render(DropdownMenuComponent.new(menu_title: "Actions Menu", hide_label: true, klass: "placement-dropdown")) do %> -
  • <%= link_to "Show All", casa_case_placements_path(casa_case), class: "dropdown-item" %>
  • -
  • <%= link_to "Edit", edit_casa_case_placement_path(casa_case, current_placement), class: "dropdown-item" %>
  • -
  • <%= render(Modal::OpenLinkComponent.new(text: "Delete", target: current_placement.id, klass: "dropdown-item")) %>
  • - <% end %> -
    -<% else %> -

    No Placements

    -<% end %> +
    + Current Placement: + + <% if current_placement %> + <%= current_placement.placement_type.name %> +

    Placed since: <%= current_placement.decorate.formatted_date %>

    + <% else %> + Unknown + <% end %> + +

    <%= link_to "See All Placements", casa_case_placements_path(casa_case), class: 'text-primary hover-underline' %>

    +
    + diff --git a/app/views/placements/index.html.erb b/app/views/placements/index.html.erb index cd581652ea..1d1a750c97 100644 --- a/app/views/placements/index.html.erb +++ b/app/views/placements/index.html.erb @@ -2,7 +2,7 @@
    -

    Placements for +

    Placement History for <%= link_to "#{@casa_case.case_number}", casa_case_path(@casa_case) %>

    @@ -33,7 +33,7 @@ <%= placement.placement_type.name %> - <%= placement.placement_started_at.strftime('%B %d, %Y') %> + <%= placement.decorate.formatted_date %> - <% if idx.zero? %> Present @@ -46,14 +46,19 @@ Edit <% end %> - <%= render(Modal::OpenLinkComponent.new(text: "Delete", target: placement.id, klass: "btn-sm main-btn danger-btn-outline btn-hover ms-auto")) %> + + <%= render(Modal::OpenLinkComponent.new(target: placement.id, klass: "btn-sm main-btn danger-btn-outline btn-hover ms-auto")) do %> + + Delete + <% end %> + <%= render(Modal::GroupComponent.new(id: placement.id)) do |component| %> <% component.with_header(text: "Delete Placement?", id: placement.id) %> <% component.with_footer do %> <%= link_to casa_case_placement_path(@casa_case, placement), method: :delete, class: "btn-sm main-btn danger-btn btn-hover ms-auto" do %> - - Delete Placement + + Delete <% end %> <% end %> <% end %> From 61e332b37ec39985e4d4efa6b6cea7696adee8ac Mon Sep 17 00:00:00 2001 From: guswhitten Date: Tue, 20 Aug 2024 17:48:08 -0400 Subject: [PATCH 14/26] fix placement policy on certain actions --- app/controllers/placements_controller.rb | 13 +++++-------- app/policies/placement_policy.rb | 6 +++--- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/app/controllers/placements_controller.rb b/app/controllers/placements_controller.rb index c94c89503b..7f05e68063 100644 --- a/app/controllers/placements_controller.rb +++ b/app/controllers/placements_controller.rb @@ -4,21 +4,21 @@ class PlacementsController < ApplicationController before_action :require_organization! def index - authorize @casa_case + authorize Placement @placements = @casa_case.placements.includes(:placement_type).order(placement_started_at: :desc) end def show - authorize @casa_case + authorize Placement end def new - authorize @casa_case + authorize Placement @placement = Placement.new end def edit - authorize @casa_case + authorize @placement end def create @@ -44,6 +44,7 @@ def update def destroy authorize @placement + if @placement.destroy redirect_to casa_case_placements_path(@casa_case), notice: "Placement was successfully deleted." else @@ -53,10 +54,6 @@ def destroy private - def authorize_placement - authorize @placement, policy_class: PlacementPolicy - end - def set_casa_case @casa_case = current_organization.casa_cases.friendly.find(params[:casa_case_id]) end diff --git a/app/policies/placement_policy.rb b/app/policies/placement_policy.rb index f9b5d4c1d7..10489feaaf 100644 --- a/app/policies/placement_policy.rb +++ b/app/policies/placement_policy.rb @@ -3,11 +3,11 @@ def allowed_to_edit_casa_case? casa_case_policy.edit? end - alias index? allowed_to_edit_casa_case? - alias show? allowed_to_edit_casa_case? + alias index? admin_or_supervisor_or_volunteer_same_org? + alias show? admin_or_supervisor_or_volunteer_same_org? alias edit? allowed_to_edit_casa_case? alias update? allowed_to_edit_casa_case? - alias new? allowed_to_edit_casa_case? + alias new? admin_or_supervisor_or_volunteer_same_org? alias create? allowed_to_edit_casa_case? alias destroy? admin_or_supervisor? From c649a51a64172de25d5c6b005d8ddecff7fb7e2a Mon Sep 17 00:00:00 2001 From: guswhitten Date: Wed, 21 Aug 2024 08:34:26 -0400 Subject: [PATCH 15/26] add system specs for CRUD actions on placements --- app/controllers/placements_controller.rb | 2 +- app/policies/placement_policy.rb | 14 ++++---- app/views/casa_cases/_placements.html.erb | 1 - app/views/placements/_form.html.erb | 3 ++ app/views/placements/index.html.erb | 2 +- spec/system/placements/destroy_spec.rb | 34 ++++++++++++++++++ spec/system/placements/edit_spec.rb | 40 +++++++++++++++++++++ spec/system/placements/index_spec.rb | 42 +++++++++++++++++++++++ spec/system/placements/new_spec.rb | 40 +++++++++++++++++++++ 9 files changed, 168 insertions(+), 10 deletions(-) create mode 100644 spec/system/placements/destroy_spec.rb create mode 100644 spec/system/placements/edit_spec.rb create mode 100644 spec/system/placements/index_spec.rb create mode 100644 spec/system/placements/new_spec.rb diff --git a/app/controllers/placements_controller.rb b/app/controllers/placements_controller.rb index 7f05e68063..ae43daec0b 100644 --- a/app/controllers/placements_controller.rb +++ b/app/controllers/placements_controller.rb @@ -66,6 +66,6 @@ def placement_params params.require(:placement).permit( :placement_started_at, :placement_type_id - ).merge({ creator_id: current_user.id, casa_case_id: @casa_case.id }) + ).merge({creator_id: current_user.id, casa_case_id: @casa_case.id}) end end diff --git a/app/policies/placement_policy.rb b/app/policies/placement_policy.rb index 10489feaaf..e07228cee2 100644 --- a/app/policies/placement_policy.rb +++ b/app/policies/placement_policy.rb @@ -3,13 +3,13 @@ def allowed_to_edit_casa_case? casa_case_policy.edit? end - alias index? admin_or_supervisor_or_volunteer_same_org? - alias show? admin_or_supervisor_or_volunteer_same_org? - alias edit? allowed_to_edit_casa_case? - alias update? allowed_to_edit_casa_case? - alias new? admin_or_supervisor_or_volunteer_same_org? - alias create? allowed_to_edit_casa_case? - alias destroy? admin_or_supervisor? + alias_method :index?, :admin_or_supervisor_or_volunteer_same_org? + alias_method :show?, :admin_or_supervisor_or_volunteer_same_org? + alias_method :edit?, :allowed_to_edit_casa_case? + alias_method :update?, :allowed_to_edit_casa_case? + alias_method :new?, :admin_or_supervisor_or_volunteer_same_org? + alias_method :create?, :allowed_to_edit_casa_case? + alias_method :destroy?, :admin_or_supervisor? private diff --git a/app/views/casa_cases/_placements.html.erb b/app/views/casa_cases/_placements.html.erb index eae1b4bdae..455a67cd20 100644 --- a/app/views/casa_cases/_placements.html.erb +++ b/app/views/casa_cases/_placements.html.erb @@ -12,4 +12,3 @@

    <%= link_to "See All Placements", casa_case_placements_path(casa_case), class: 'text-primary hover-underline' %>

    - diff --git a/app/views/placements/_form.html.erb b/app/views/placements/_form.html.erb index 9fbd70827c..e4d0d5abae 100644 --- a/app/views/placements/_form.html.erb +++ b/app/views/placements/_form.html.erb @@ -1,4 +1,7 @@
    +
    + <%= render "/shared/error_messages", resource: placement %> +
    <%= form_with(model: placement, url: [casa_case, placement], local: true, data: { controller: "placement-form", nested_form_wrapper_selector_value: ".nested-form-wrapper" }) do |form| %>
    diff --git a/app/views/placements/index.html.erb b/app/views/placements/index.html.erb index 1d1a750c97..48b0d4647b 100644 --- a/app/views/placements/index.html.erb +++ b/app/views/placements/index.html.erb @@ -58,7 +58,7 @@ <% component.with_footer do %> <%= link_to casa_case_placement_path(@casa_case, placement), method: :delete, class: "btn-sm main-btn danger-btn btn-hover ms-auto" do %> - Delete + Confirm <% end %> <% end %> <% end %> diff --git a/spec/system/placements/destroy_spec.rb b/spec/system/placements/destroy_spec.rb new file mode 100644 index 0000000000..5ff11fa5b2 --- /dev/null +++ b/spec/system/placements/destroy_spec.rb @@ -0,0 +1,34 @@ +require "rails_helper" + +RSpec.describe "placements/destroy", type: :system do + let(:now) { Date.new(2025, 1, 2) } + let(:casa_org) { create(:casa_org, :with_placement_types) } + let(:admin) { create(:casa_admin, casa_org:) } + let(:casa_case) { create(:casa_case, casa_org:, case_number: "123") } + let(:placement_type) { create(:placement_type, name: "Reunification", casa_org:) } + let(:placement) { create(:placement, placement_started_at: "2024-08-15 20:40:44 UTC", casa_case:, placement_type:) } + + before do + travel_to now + sign_in admin + visit casa_case_placements_path(casa_case, placement) + click_on "Delete" + end + + it "does not delete on modal close" do + expect(page).to have_text("Delete Placement?") + click_on "Close" + + expect(page).to have_text("Reunification") + expect(page).to have_text("August 15, 2024 - Present") + end + + it "deletes placement" do + expect(page).to have_text("Delete Placement?") + click_on "Confirm" + + expect(page).to have_text("Placement was successfully deleted.") + expect(page).not_to have_text("Reunification") + expect(page).not_to have_text("August 15, 2024 - Present") + end +end diff --git a/spec/system/placements/edit_spec.rb b/spec/system/placements/edit_spec.rb new file mode 100644 index 0000000000..e7e9609ba0 --- /dev/null +++ b/spec/system/placements/edit_spec.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +require "rails_helper" + +RSpec.describe "placements/edit", type: :system do + let(:now) { Date.new(2025, 1, 2) } + let(:casa_org) { create(:casa_org, :with_placement_types) } + let(:admin) { create(:casa_admin, casa_org:) } + let(:casa_case) { create(:casa_case, casa_org:, case_number: "123") } + let(:placement_type) { create(:placement_type, name: "Reunification", casa_org:) } + let(:placement) { create(:placement, placement_started_at: "2024-08-15 20:40:44 UTC", casa_case:, placement_type:) } + + before do + travel_to now + sign_in admin + visit casa_case_placement_path(casa_case, placement) + click_link("Edit") + end + + it "updates placement with valid form data", js: true do + expect(page).to have_content("123") + + fill_in "Placement Started At", with: now - 5.years + select "Kinship", from: "Placement Type" + + click_on "Update" + + expect(page).to have_content("Placement was successfully updated.") + expect(page).to have_content("123") + expect(page).to have_content("January 2, 2020") + expect(page).to have_content("Kinship") + end + + it "rejects placement update with invalid form data" do + fill_in "Placement Started At", with: 1000.years.ago + click_on "Update" + + expect(page).to have_content("1 error prohibited this Placement from being saved:\nPlacement started at cannot be prior to 1/1/1989.") + end +end diff --git a/spec/system/placements/index_spec.rb b/spec/system/placements/index_spec.rb new file mode 100644 index 0000000000..eb417429cc --- /dev/null +++ b/spec/system/placements/index_spec.rb @@ -0,0 +1,42 @@ +require "rails_helper" + +RSpec.describe "placements/destroy", type: :system do + let(:now) { Date.new(2025, 1, 2) } + let(:casa_org) { create(:casa_org, :with_placement_types) } + let(:admin) { create(:casa_admin, casa_org:) } + let(:casa_case) { create(:casa_case, casa_org:, case_number: "123") } + let(:placement_current) { create(:placement_type, name: "Reunification", casa_org:) } + let(:placement_prev) { create(:placement_type, name: "Kinship", casa_org:) } + let(:placement_first) { create(:placement_type, name: "Adoption", casa_org:) } + let(:placements) do + [ + create(:placement, placement_started_at: "2024-08-15 20:40:44 UTC", casa_case:, placement_type: placement_current), + create(:placement, placement_started_at: "2023-06-02 00:00:00 UTC", casa_case:, placement_type: placement_prev), + create(:placement, placement_started_at: "2021-12-25 10:10:10 UTC", casa_case:, placement_type: placement_first) + ] + end + + before do + travel_to now + sign_in admin + visit casa_case_placements_path(casa_case, placement) + click_on "Delete" + end + + it "does not delete on modal close" do + expect(page).to have_text("Delete Placement?") + click_on "Close" + + expect(page).to have_text("Reunification") + expect(page).to have_text("August 15, 2024 - Present") + end + + it "deletes placement" do + expect(page).to have_text("Delete Placement?") + click_on "Confirm" + + expect(page).to have_text("Placement was successfully deleted.") + expect(page).not_to have_text("Reunification") + expect(page).not_to have_text("August 15, 2024 - Present") + end +end diff --git a/spec/system/placements/new_spec.rb b/spec/system/placements/new_spec.rb new file mode 100644 index 0000000000..05a559e553 --- /dev/null +++ b/spec/system/placements/new_spec.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +require "rails_helper" + +RSpec.describe "placements/new", type: :system do + let(:now) { Date.new(2025, 1, 2) } + let(:casa_org) { create(:casa_org, :with_placement_types) } + let(:admin) { create(:casa_admin, casa_org:) } + let(:casa_case) { create(:casa_case, casa_org:, case_number: "123") } + let(:placement_type) { create(:placement_type, name: "Reunification", casa_org:) } + let(:placement) { create(:placement, placement_started_at: "2024-08-15 20:40:44 UTC", casa_case:, placement_type:) } + + before do + travel_to now + sign_in admin + visit casa_case_placements_path(casa_case) + click_link("New Placement") + end + + it "creates placement with valid form data", js: true do + expect(page).to have_content("123") + + fill_in "Placement Started At", with: now + select placement_type.name, from: "Placement Type" + + click_on "Create" + + expect(page).to have_content("Placement was successfully created.") + expect(page).to have_content("123") + expect(page).to have_content("January 2, 2025") + expect(page).to have_content("Reunification") + end + + it "rejects placement with invalid form data" do + fill_in "Placement Started At", with: 1000.years.ago + click_on "Create" + + expect(page).to have_content("2 errors prohibited this Placement from being saved:\nPlacement type must exist Placement started at cannot be prior to 1/1/1989.") + end +end From 4ba2aca0578ab64badf47e8e919813f296091697 Mon Sep 17 00:00:00 2001 From: guswhitten Date: Thu, 22 Aug 2024 17:37:33 -0400 Subject: [PATCH 16/26] fix failing tests --- app/controllers/placements_controller.rb | 6 +++--- spec/system/placements/index_spec.rb | 23 +++++++-------------- spec/views/casa_cases/show.html.erb_spec.rb | 9 ++++++-- 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/app/controllers/placements_controller.rb b/app/controllers/placements_controller.rb index ae43daec0b..b60dd2aa7a 100644 --- a/app/controllers/placements_controller.rb +++ b/app/controllers/placements_controller.rb @@ -4,16 +4,16 @@ class PlacementsController < ApplicationController before_action :require_organization! def index - authorize Placement + authorize @casa_case @placements = @casa_case.placements.includes(:placement_type).order(placement_started_at: :desc) end def show - authorize Placement + authorize @casa_case end def new - authorize Placement + authorize @casa_case @placement = Placement.new end diff --git a/spec/system/placements/index_spec.rb b/spec/system/placements/index_spec.rb index eb417429cc..c2f7ecdb88 100644 --- a/spec/system/placements/index_spec.rb +++ b/spec/system/placements/index_spec.rb @@ -1,6 +1,6 @@ require "rails_helper" -RSpec.describe "placements/destroy", type: :system do +RSpec.describe "placements", type: :system do let(:now) { Date.new(2025, 1, 2) } let(:casa_org) { create(:casa_org, :with_placement_types) } let(:admin) { create(:casa_admin, casa_org:) } @@ -19,24 +19,15 @@ before do travel_to now sign_in admin - visit casa_case_placements_path(casa_case, placement) - click_on "Delete" + visit casa_case_placements_path(casa_case, placements) end - it "does not delete on modal close" do - expect(page).to have_text("Delete Placement?") - click_on "Close" - + it "displays all placements for org" do expect(page).to have_text("Reunification") expect(page).to have_text("August 15, 2024 - Present") - end - - it "deletes placement" do - expect(page).to have_text("Delete Placement?") - click_on "Confirm" - - expect(page).to have_text("Placement was successfully deleted.") - expect(page).not_to have_text("Reunification") - expect(page).not_to have_text("August 15, 2024 - Present") + expect(page).to have_text("Kinship") + expect(page).to have_text("June 2, 2023 - August 14, 2024") + expect(page).to have_text("Adoption") + expect(page).to have_text("December 25, 2021 - June 01, 2023") end end diff --git a/spec/views/casa_cases/show.html.erb_spec.rb b/spec/views/casa_cases/show.html.erb_spec.rb index b775e1175d..e73c1e131a 100644 --- a/spec/views/casa_cases/show.html.erb_spec.rb +++ b/spec/views/casa_cases/show.html.erb_spec.rb @@ -61,7 +61,10 @@ render expect(rendered).to match("111") - expect(rendered).to match("May 06, 2023 - Present") + expect(rendered).to match("Current Placement:") + expect(rendered).to match("Placement Type 1") + expect(rendered).to match("Placed since: May 6, 2023") + expect(rendered).to match("See All Placements") end end @@ -73,7 +76,9 @@ render expect(rendered).to match(casa_case.case_number) - expect(rendered).to have_content("No Placements") + expect(rendered).to have_content("Current Placement:") + expect(rendered).to have_content("Unknown") + expect(rendered).to have_content("See All Placements") end end end From bd7237f28bed4ca745e1a5651bd2c758b4f48e44 Mon Sep 17 00:00:00 2001 From: guswhitten Date: Fri, 23 Aug 2024 07:05:36 -0400 Subject: [PATCH 17/26] update placement policies --- app/controllers/placements_controller.rb | 8 ++--- app/models/placement.rb | 1 + app/policies/application_policy.rb | 2 +- app/policies/placement_policy.rb | 4 +-- app/views/placements/index.html.erb | 2 +- spec/policies/placement_policy_spec.rb | 32 ++++++++++++++++---- spec/views/placements/index.html.erb_spec.rb | 7 +++-- 7 files changed, 39 insertions(+), 17 deletions(-) diff --git a/app/controllers/placements_controller.rb b/app/controllers/placements_controller.rb index b60dd2aa7a..c1eff76762 100644 --- a/app/controllers/placements_controller.rb +++ b/app/controllers/placements_controller.rb @@ -4,17 +4,17 @@ class PlacementsController < ApplicationController before_action :require_organization! def index - authorize @casa_case + authorize Placement @placements = @casa_case.placements.includes(:placement_type).order(placement_started_at: :desc) end def show - authorize @casa_case + authorize @placement end def new - authorize @casa_case - @placement = Placement.new + @placement = Placement.new(casa_case: @casa_case) + authorize @placement end def edit diff --git a/app/models/placement.rb b/app/models/placement.rb index f1f4c71b30..f0ef8c102c 100644 --- a/app/models/placement.rb +++ b/app/models/placement.rb @@ -2,6 +2,7 @@ class Placement < ApplicationRecord belongs_to :casa_case belongs_to :placement_type belongs_to :creator, class_name: "User" + has_one :casa_org, through: :casa_case validates :placement_started_at, comparison: { greater_than_or_equal_to: "1989-01-01".to_date, diff --git a/app/policies/application_policy.rb b/app/policies/application_policy.rb index 84b43ef090..0f080351a6 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, Placement user.casa_org == record.casa_org when CourtDate, CaseContact, CaseAssignment user.casa_org == record&.casa_case&.casa_org diff --git a/app/policies/placement_policy.rb b/app/policies/placement_policy.rb index e07228cee2..aaa231cfa7 100644 --- a/app/policies/placement_policy.rb +++ b/app/policies/placement_policy.rb @@ -4,10 +4,10 @@ def allowed_to_edit_casa_case? end alias_method :index?, :admin_or_supervisor_or_volunteer_same_org? - alias_method :show?, :admin_or_supervisor_or_volunteer_same_org? + alias_method :show?, :allowed_to_edit_casa_case? alias_method :edit?, :allowed_to_edit_casa_case? alias_method :update?, :allowed_to_edit_casa_case? - alias_method :new?, :admin_or_supervisor_or_volunteer_same_org? + alias_method :new?, :allowed_to_edit_casa_case? alias_method :create?, :allowed_to_edit_casa_case? alias_method :destroy?, :admin_or_supervisor? diff --git a/app/views/placements/index.html.erb b/app/views/placements/index.html.erb index 48b0d4647b..b87fdc9ddc 100644 --- a/app/views/placements/index.html.erb +++ b/app/views/placements/index.html.erb @@ -38,7 +38,7 @@ <% if idx.zero? %> Present <% elsif @placements[idx - 1].placement_started_at %> - <%= (@placements[idx - 1].placement_started_at - 1.day).strftime('%B %d, %Y') %> + <%= @placements[idx - 1].decorate.formatted_date %> <% end %> <%= link_to edit_casa_case_placement_path(@casa_case, placement), class: "btn-sm main-btn primary-btn-outline btn-hover ms-auto" do %> diff --git a/spec/policies/placement_policy_spec.rb b/spec/policies/placement_policy_spec.rb index c97622fae5..5fdc6a9847 100644 --- a/spec/policies/placement_policy_spec.rb +++ b/spec/policies/placement_policy_spec.rb @@ -6,14 +6,34 @@ let(:casa_org) { create(:casa_org) } let(:diff_org) { create(:casa_org) } - let(:placement) { create(:placement, casa_case:) } let(:casa_case) { create(:casa_case, casa_org:) } + let(:placement) { create(:placement, casa_case:) } + + let(:casa_admin) { build(:casa_admin, casa_org:) } + let(:supervisor) { build(:supervisor, casa_org:) } + let(:volunteer) { build(:volunteer, casa_org:) } + let(:casa_admin_diff_org) { build(:casa_admin, casa_org: diff_org) } + let(:supervisor_diff_org) { build(:supervisor, casa_org: diff_org) } + let(:volunteer_diff_org) { build(:volunteer, casa_org: diff_org) } + + permissions :index? do + it "allows casa_admins" do + is_expected.to permit(casa_admin, Placement) + is_expected.to permit(casa_admin_diff_org, Placement) + end - let(:casa_admin) { create(:casa_admin, casa_org:) } - let(:volunteer) { create(:volunteer, casa_org:) } - let(:supervisor) { create(:supervisor, casa_org:) } + it "allows supervisor" do + is_expected.to permit(supervisor, Placement) + is_expected.to permit(supervisor_diff_org, Placement) + end + + it "allows volunteer" do + is_expected.to permit(volunteer, Placement) + is_expected.to permit(volunteer_diff_org, Placement) + end + end - permissions :index?, :new?, :create?, :edit?, :update?, :show? do + permissions :create?, :edit?, :update?, :show?, :new? do it { is_expected.to permit(casa_admin, placement) } context "when a supervisor belongs to the same org as the case" do @@ -27,7 +47,7 @@ end context "when volunteer is assigned" do - before { volunteer.casa_cases << casa_case } + before { create(:case_assignment, volunteer:, casa_case:, active: true) } it { is_expected.to permit(volunteer, placement) } end diff --git a/spec/views/placements/index.html.erb_spec.rb b/spec/views/placements/index.html.erb_spec.rb index f5113367a4..3142b68396 100644 --- a/spec/views/placements/index.html.erb_spec.rb +++ b/spec/views/placements/index.html.erb_spec.rb @@ -32,13 +32,14 @@ it "displays placement information for each placement" do expect(rendered).to have_content("Reunification") - expect(rendered).to have_content(/August 15, 2024\s*-\s*Present/) + expect(rendered).to have_content(/August 15, 2024/) + expect(rendered).to have_content(/Present/) expect(rendered).to have_content("Kinship") - expect(rendered).to have_content(/June 02, 2023\s*-\s*August 14, 2024/) + expect(rendered).to have_content(/June 2, 2023/) expect(rendered).to have_content("Adoption") - expect(rendered).to have_content(/December 25, 2021\s*-\s*June 01, 2023/) + expect(rendered).to have_content(/December 25, 2021/) end it "has edit links for each placement" do From a966bc5dd4f4dc86b60bfceb0ecc31931c0d0892 Mon Sep 17 00:00:00 2001 From: guswhitten Date: Fri, 23 Aug 2024 07:16:59 -0400 Subject: [PATCH 18/26] update spec/system/placements/index_spec.rb test --- spec/system/placements/index_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/system/placements/index_spec.rb b/spec/system/placements/index_spec.rb index c2f7ecdb88..007296f39a 100644 --- a/spec/system/placements/index_spec.rb +++ b/spec/system/placements/index_spec.rb @@ -26,8 +26,8 @@ expect(page).to have_text("Reunification") expect(page).to have_text("August 15, 2024 - Present") expect(page).to have_text("Kinship") - expect(page).to have_text("June 2, 2023 - August 14, 2024") + expect(page).to have_text("June 2, 2023 - August 15, 2024") expect(page).to have_text("Adoption") - expect(page).to have_text("December 25, 2021 - June 01, 2023") + expect(page).to have_text("December 25, 2021 - June 2, 2023") end end From 798eee1512ac8c628ac5476bfb450d8b64fc50b8 Mon Sep 17 00:00:00 2001 From: guswhitten Date: Fri, 23 Aug 2024 07:36:59 -0400 Subject: [PATCH 19/26] flaky test fixes --- spec/views/casa_cases/show.html.erb_spec.rb | 2 +- spec/views/notifications/index.html.erb_spec.rb | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/spec/views/casa_cases/show.html.erb_spec.rb b/spec/views/casa_cases/show.html.erb_spec.rb index e73c1e131a..6d74b50eb0 100644 --- a/spec/views/casa_cases/show.html.erb_spec.rb +++ b/spec/views/casa_cases/show.html.erb_spec.rb @@ -62,7 +62,7 @@ expect(rendered).to match("111") expect(rendered).to match("Current Placement:") - expect(rendered).to match("Placement Type 1") + expect(rendered).to match(/Placement Type/) expect(rendered).to match("Placed since: May 6, 2023") expect(rendered).to match("See All Placements") end diff --git a/spec/views/notifications/index.html.erb_spec.rb b/spec/views/notifications/index.html.erb_spec.rb index 8a2a71b587..97666b0455 100644 --- a/spec/views/notifications/index.html.erb_spec.rb +++ b/spec/views/notifications/index.html.erb_spec.rb @@ -1,6 +1,7 @@ require "rails_helper" RSpec.describe "notifications/index", type: :view do + let(:base_time) { Date.new(2025, 1, 2) } let(:notification_1_hour_ago) { create(:notification, :followup_with_note) } let(:notification_1_day_ago) { create(:notification, :emancipation_checklist_reminder) } let(:notification_2_days_ago) { create(:notification, :youth_birthday) } @@ -20,7 +21,7 @@ end context "when there is a deploy date" do - let(:deploy_time) { 2.days.ago } + let(:deploy_time) { base_time - 2.days } before do Health.instance.update_attribute(:latest_deploy_time, deploy_time) @@ -28,10 +29,10 @@ context "when there are notifications" do before do - notification_1_hour_ago.update_attribute(:created_at, 1.hour.ago) - notification_1_day_ago.update_attribute(:created_at, 1.day.ago) - notification_2_days_ago.update_attribute(:created_at, 2.days.ago) - notification_3_days_ago.update_attribute(:created_at, 3.days.ago) + notification_1_hour_ago.update_attribute(:created_at, base_time - 1.hour) + notification_1_day_ago.update_attribute(:created_at, base_time - 1.day) + notification_2_days_ago.update_attribute(:created_at, base_time - 2.days) + notification_3_days_ago.update_attribute(:created_at, base_time - 3.days) patch_note_1.update_attribute(:patch_note_group, patch_note_group_all_users) end From be506a9d64aa9993a96718e9735211ef999d7d91 Mon Sep 17 00:00:00 2001 From: guswhitten Date: Sat, 31 Aug 2024 14:38:59 -0400 Subject: [PATCH 20/26] add policy scope for placements index action --- app/controllers/placements_controller.rb | 3 +-- app/models/placement_type.rb | 3 ++- app/policies/placement_policy.rb | 14 +++++++++++++- app/views/placements/_fields.html.erb | 2 +- spec/policies/placement_policy_spec.rb | 17 ----------------- 5 files changed, 17 insertions(+), 22 deletions(-) diff --git a/app/controllers/placements_controller.rb b/app/controllers/placements_controller.rb index c1eff76762..0bc7490e61 100644 --- a/app/controllers/placements_controller.rb +++ b/app/controllers/placements_controller.rb @@ -4,8 +4,7 @@ class PlacementsController < ApplicationController before_action :require_organization! def index - authorize Placement - @placements = @casa_case.placements.includes(:placement_type).order(placement_started_at: :desc) + @placements = policy_scope(@casa_case.placements).includes(:placement_type).order(placement_started_at: :desc) end def show diff --git a/app/models/placement_type.rb b/app/models/placement_type.rb index b76fa08f6f..f4515c325f 100644 --- a/app/models/placement_type.rb +++ b/app/models/placement_type.rb @@ -2,7 +2,8 @@ class PlacementType < ApplicationRecord belongs_to :casa_org validates :name, presence: true - scope :for_organization, ->(org) { where(casa_org: org).order(:name) } + scope :for_organization, ->(org) { where(casa_org: org) } + scope :order_alphabetically, -> { order(:name) } end # == Schema Information diff --git a/app/policies/placement_policy.rb b/app/policies/placement_policy.rb index aaa231cfa7..88908f2664 100644 --- a/app/policies/placement_policy.rb +++ b/app/policies/placement_policy.rb @@ -1,9 +1,21 @@ class PlacementPolicy < ApplicationPolicy + class Scope < ApplicationPolicy::Scope + def resolve + case @user + when CasaAdmin, Supervisor + scope.joins(:casa_case).where(casa_cases: { casa_org_id: @user.casa_org_id }) + when Volunteer + scope.none + else + scope.none + end + end + end + def allowed_to_edit_casa_case? casa_case_policy.edit? end - alias_method :index?, :admin_or_supervisor_or_volunteer_same_org? alias_method :show?, :allowed_to_edit_casa_case? alias_method :edit?, :allowed_to_edit_casa_case? alias_method :update?, :allowed_to_edit_casa_case? diff --git a/app/views/placements/_fields.html.erb b/app/views/placements/_fields.html.erb index 1e08f20116..79922aafc3 100644 --- a/app/views/placements/_fields.html.erb +++ b/app/views/placements/_fields.html.erb @@ -9,7 +9,7 @@
    <%= form.collection_select( :placement_type_id, - PlacementType.for_organization(current_organization), + PlacementType.for_organization(current_organization).order_alphabetically, :id, :name, {include_hidden: false, include_blank: "-Select Placement Type-"}, {class: "form-control"} diff --git a/spec/policies/placement_policy_spec.rb b/spec/policies/placement_policy_spec.rb index 5fdc6a9847..abe5f6a8c8 100644 --- a/spec/policies/placement_policy_spec.rb +++ b/spec/policies/placement_policy_spec.rb @@ -16,23 +16,6 @@ let(:supervisor_diff_org) { build(:supervisor, casa_org: diff_org) } let(:volunteer_diff_org) { build(:volunteer, casa_org: diff_org) } - permissions :index? do - it "allows casa_admins" do - is_expected.to permit(casa_admin, Placement) - is_expected.to permit(casa_admin_diff_org, Placement) - end - - it "allows supervisor" do - is_expected.to permit(supervisor, Placement) - is_expected.to permit(supervisor_diff_org, Placement) - end - - it "allows volunteer" do - is_expected.to permit(volunteer, Placement) - is_expected.to permit(volunteer_diff_org, Placement) - end - end - permissions :create?, :edit?, :update?, :show?, :new? do it { is_expected.to permit(casa_admin, placement) } From ff8544555fc9e8c6bdd7dddc48fa93507d1b9a55 Mon Sep 17 00:00:00 2001 From: guswhitten Date: Sat, 31 Aug 2024 14:45:47 -0400 Subject: [PATCH 21/26] update placement policy scope --- app/policies/placement_policy.rb | 9 +-------- config/environments/test.rb | 2 +- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/app/policies/placement_policy.rb b/app/policies/placement_policy.rb index 88908f2664..ad5050ae52 100644 --- a/app/policies/placement_policy.rb +++ b/app/policies/placement_policy.rb @@ -1,14 +1,7 @@ class PlacementPolicy < ApplicationPolicy class Scope < ApplicationPolicy::Scope def resolve - case @user - when CasaAdmin, Supervisor - scope.joins(:casa_case).where(casa_cases: { casa_org_id: @user.casa_org_id }) - when Volunteer - scope.none - else - scope.none - end + scope.joins(:casa_case).where(casa_cases: { casa_org_id: @user.casa_org_id }) end end diff --git a/config/environments/test.rb b/config/environments/test.rb index 4cb00ebe24..73c0a71c7b 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -9,7 +9,7 @@ # Settings specified here will take precedence over those in config/application.rb. config.action_mailer.default_url_options = {host: "localhost", port: 3000} # for devise authentication # While tests run files are not watched, reloading is not necessary. - config.enable_reloading = false + config.enable_reloading = true # Turn false under Spring and add config.action_view.cache_template_loading = true. config.action_view.cache_template_loading = true From 9262d036b8213f29e6d58867c4f2df901929baab Mon Sep 17 00:00:00 2001 From: guswhitten Date: Sat, 31 Aug 2024 14:47:34 -0400 Subject: [PATCH 22/26] please linter --- app/policies/placement_policy.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/policies/placement_policy.rb b/app/policies/placement_policy.rb index ad5050ae52..f66abd27bf 100644 --- a/app/policies/placement_policy.rb +++ b/app/policies/placement_policy.rb @@ -1,7 +1,7 @@ class PlacementPolicy < ApplicationPolicy class Scope < ApplicationPolicy::Scope def resolve - scope.joins(:casa_case).where(casa_cases: { casa_org_id: @user.casa_org_id }) + scope.joins(:casa_case).where(casa_cases: {casa_org_id: @user.casa_org_id}) end end From 4d3bcf375e9219f2a037d9747379e65445b839b1 Mon Sep 17 00:00:00 2001 From: guswhitten <90280763+guswhitten@users.noreply.github.com> Date: Sat, 31 Aug 2024 15:19:15 -0400 Subject: [PATCH 23/26] Update config/environments/test.rb Co-authored-by: Jon Roberts --- config/environments/test.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config/environments/test.rb b/config/environments/test.rb index 73c0a71c7b..36f6667f1f 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -18,7 +18,8 @@ # recommended that you enable it in continuous integration systems to ensure eager # loading is working properly before deploying your code. config.eager_load = ENV["CI"].present? - + # cache classes on CI, but enable reloading for local work (bin/rspec) + config.enable_reloading = ENV["CI"].blank? # Configure public file server for tests with Cache-Control for performance. config.public_file_server.enabled = true config.public_file_server.headers = { From bb6f0030bbbca92b4aba72cfbbd3a0c4e1986cfb Mon Sep 17 00:00:00 2001 From: guswhitten <90280763+guswhitten@users.noreply.github.com> Date: Sat, 31 Aug 2024 15:19:23 -0400 Subject: [PATCH 24/26] Update config/environments/test.rb Co-authored-by: Jon Roberts --- config/environments/test.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/config/environments/test.rb b/config/environments/test.rb index 36f6667f1f..ac1618269c 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -9,7 +9,6 @@ # Settings specified here will take precedence over those in config/application.rb. config.action_mailer.default_url_options = {host: "localhost", port: 3000} # for devise authentication # While tests run files are not watched, reloading is not necessary. - config.enable_reloading = true # Turn false under Spring and add config.action_view.cache_template_loading = true. config.action_view.cache_template_loading = true From 38353a0ec0dccde810a4734fe66d1403965f1dd7 Mon Sep 17 00:00:00 2001 From: guswhitten Date: Tue, 3 Sep 2024 07:45:47 -0400 Subject: [PATCH 25/26] dont display placement info on casa case when org has no placement types yet --- app/policies/placement_policy.rb | 4 +++- app/views/casa_cases/_placements.html.erb | 20 ++++++++++++-------- spec/factories/casa_orgs.rb | 4 ++-- spec/views/casa_cases/show.html.erb_spec.rb | 17 +++++++++++++++-- 4 files changed, 32 insertions(+), 13 deletions(-) diff --git a/app/policies/placement_policy.rb b/app/policies/placement_policy.rb index f66abd27bf..da622c4b0d 100644 --- a/app/policies/placement_policy.rb +++ b/app/policies/placement_policy.rb @@ -1,7 +1,9 @@ class PlacementPolicy < ApplicationPolicy class Scope < ApplicationPolicy::Scope def resolve - scope.joins(:casa_case).where(casa_cases: {casa_org_id: @user.casa_org_id}) + return scope.none unless @user&.casa_org + + scope.joins(:casa_case).where(casa_cases: {casa_org: @user.casa_org}) end end diff --git a/app/views/casa_cases/_placements.html.erb b/app/views/casa_cases/_placements.html.erb index 455a67cd20..10e41c0a25 100644 --- a/app/views/casa_cases/_placements.html.erb +++ b/app/views/casa_cases/_placements.html.erb @@ -1,14 +1,18 @@ <% current_placement = casa_case.placements.order(placement_started_at: :desc).first %> -
    - Current Placement: - - <% if current_placement %> +<% if current_placement %> +
    + Current Placement: <%= current_placement.placement_type.name %> -

    Placed since: <%= current_placement.decorate.formatted_date %>

    - <% else %> +
    + +

    Placed since: <%= current_placement.decorate.formatted_date %>

    +

    <%= link_to "See All Placements", casa_case_placements_path(casa_case), class: 'text-primary hover-underline' %>

    +<% elsif casa_case.casa_org.placement_types.present? %> +
    + Current Placement: Unknown - <% end %> +

    <%= link_to "See All Placements", casa_case_placements_path(casa_case), class: 'text-primary hover-underline' %>

    - +<% end %> \ No newline at end of file diff --git a/spec/factories/casa_orgs.rb b/spec/factories/casa_orgs.rb index f06d845768..7017f88bf8 100644 --- a/spec/factories/casa_orgs.rb +++ b/spec/factories/casa_orgs.rb @@ -14,10 +14,10 @@ end trait :with_placement_types do - transient { placement_types { ["Reunification", "Adoption", "Foster Care", "Kinship"] } } + transient { placement_names { ["Reunification", "Adoption", "Foster Care", "Kinship"] } } after(:create) do |org, evaluator| - evaluator.placement_types.each do |name| + evaluator.placement_names.each do |name| org.placement_types.create!(name: name) end end diff --git a/spec/views/casa_cases/show.html.erb_spec.rb b/spec/views/casa_cases/show.html.erb_spec.rb index 6d74b50eb0..9e9d6b5836 100644 --- a/spec/views/casa_cases/show.html.erb_spec.rb +++ b/spec/views/casa_cases/show.html.erb_spec.rb @@ -68,9 +68,10 @@ end end - context "where there is no placement" do + context "when there is no placement" do it "renders casa case without placements" do - casa_case = create(:casa_case) + casa_org = create(:casa_org, :with_placement_types) + casa_case = create(:casa_case, casa_org:) assign(:casa_case, casa_case) render @@ -80,5 +81,17 @@ expect(rendered).to have_content("Unknown") expect(rendered).to have_content("See All Placements") end + + it "renders nothing about placements when org has no placement types" do + casa_case = create(:casa_case) + assign(:casa_case, casa_case) + + render + + expect(rendered).to match(casa_case.case_number) + expect(rendered).not_to have_content("Current Placement:") + expect(rendered).not_to have_content("Unknown") + expect(rendered).not_to have_content("See All Placements") + end end end From 630bb24535a3a525471733183eb2db793f5f84f4 Mon Sep 17 00:00:00 2001 From: guswhitten Date: Tue, 3 Sep 2024 07:48:32 -0400 Subject: [PATCH 26/26] run linter --- app/views/casa_cases/_placements.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/casa_cases/_placements.html.erb b/app/views/casa_cases/_placements.html.erb index 10e41c0a25..be1545446c 100644 --- a/app/views/casa_cases/_placements.html.erb +++ b/app/views/casa_cases/_placements.html.erb @@ -15,4 +15,4 @@

    <%= link_to "See All Placements", casa_case_placements_path(casa_case), class: 'text-primary hover-underline' %>

    -<% end %> \ No newline at end of file +<% end %>