Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 5780 #5991

Merged
merged 28 commits into from
Sep 6, 2024
Merged

Fix 5780 #5991

merged 28 commits into from
Sep 6, 2024

Conversation

guswhitten
Copy link
Contributor

@guswhitten guswhitten commented Aug 16, 2024

What github issue is this PR for, if any?

Resolves #5780

What changed, and why?

Add basic CRUD operations for case Placements.

How is this tested? (please write tests!) 💖💪

  • index.html.erb_spec.rb
  • edit.html.erb_spec.rb
  • new.html.erb_spec.rb

Screenshots please :)

placement-partial-updated
index-view
edit-view
delete-modal

@github-actions github-actions bot added ruby Pull requests that update Ruby code Tests! 🎉💖👏 erb labels Aug 16, 2024
@guswhitten guswhitten marked this pull request as ready for review August 16, 2024 22:25
Copy link
Collaborator

@elasticspoon elasticspoon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey. This is a great start!

Overall, my comments are more about removal of code than anything.

I also would like to see a system spec to exercise the major work flows => creating, editing and deleting a placement.

app/controllers/placements_controller.rb Outdated Show resolved Hide resolved
@@ -5,23 +5,63 @@ class PlacementsController < ApplicationController

rescue_from ActiveRecord::RecordNotFound, with: -> { head :not_found }

def index
authorize @casa_case
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use the placement policy for this. You should be able to do something like Placement.authorize.

app/controllers/placements_controller.rb Outdated Show resolved Hide resolved
app/controllers/placements_controller.rb Outdated Show resolved Hide resolved
app/controllers/placements_controller.rb Outdated Show resolved Hide resolved
app/views/casa_cases/_placements.html.erb Outdated Show resolved Hide resolved
app/views/casa_cases/_placements.html.erb Show resolved Hide resolved
app/assets/stylesheets/pages/casa_cases.scss Outdated Show resolved Hide resolved
Copy link
Contributor

@thejonroberts thejonroberts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have to run before finished reviewing, have some minor suggestions.

@@ -5,23 +5,63 @@ class PlacementsController < ApplicationController

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)

This comment was marked as resolved.

This comment was marked as resolved.

Comment on lines 16 to 17
authorize @casa_case
@placement = Placement.new

This comment was marked as resolved.

validates :name, presence: true
scope :for_organization, ->(org) { where(casa_org: org).order(:name) }

This comment was marked as resolved.

@@ -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"] } }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
transient { placement_types { ["Reunification", "Adoption", "Foster Care", "Kinship"] } }
transient { placement_names { ["Reunification", "Adoption", "Foster Care", "Kinship"] } }

Confusing, these aren't placement types, they are just type names.

Comment on lines 19 to 23
after(:create) do |org, evaluator|
evaluator.placement_types.each do |name|
org.placement_types.create!(name: name)
end
end
Copy link
Contributor

@thejonroberts thejonroberts Aug 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do think the placement_names change should be made at the least:

Suggested change
after(:create) do |org, evaluator|
evaluator.placement_types.each do |name|
org.placement_types.create!(name: name)
end
end
after(:create) do |org, evaluator|
evaluator.placement_names.each do |name|
org.placement_types.create!(name: name)
end
end

Copy link
Contributor

@thejonroberts thejonroberts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got a lot of comments, some are a little nit picky. But this is good overall! Will pull this down and try it out (probably tomorrow) before approval, but not requesting changes.

validates :name, presence: true
scope :for_organization, ->(org) { where(casa_org: org) }
scope :order_alphabetically, -> { order(:name) }

This comment was marked as resolved.

class PlacementPolicy < ApplicationPolicy
class Scope < ApplicationPolicy::Scope
def resolve
scope.joins(:casa_case).where(casa_cases: {casa_org_id: @user.casa_org_id})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would break for nil user, or user with no casa org (all_casa_admin or some edge case).

Suggested change
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})

Also, can use casa_org object instead of casa_org_id (not urgent, more of a convention/nit I pick, prefer to use the object over the object_id. unless necessary).

<strong>Current Placement:</strong>

<% if current_placement %>
<%= current_placement.placement_type.name %>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<%= current_placement.placement_type.name %>
<span><%= current_placement.placement_type.name %></span>

wrap with p or span some kind of html element. same with "Unknown" below.

I don't love all of these paragraphs being wrapped by a heading (h6) element. Should that h6 just be for "Current Placement"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to keep it similar to other casa_case partials. the h6 includes Current Placement and the placement_type, but now excludes the link to "See All Placements" (though its CSS was being overridden anyway)

<div class="select-position">
<%= form.collection_select(
:placement_type_id,
PlacementType.for_organization(current_organization).order_alphabetically,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I would prefer this set in the controller in @placement_types.

You couldn't use a policy scope because we don't have one for PlacementType, so this will do, but that is more likely to be fixed/updated with a scope if it's in the controller, rather than tucked away in this partial.

Not a must do, just a suggestion.

Comment on lines +1 to +9
<div class="title-wrapper pt-30">
<div class="row align-items-center">
<div class="col-md-6">
<div class="title mb-30">
<h1>Editing Placement</h1>
</div>
</div>
</div>
</div>

This comment was marked as outdated.

Comment on lines +16 to +17
visit casa_case_placement_path(casa_case, placement)
click_link("Edit")
Copy link
Contributor

@thejonroberts thejonroberts Aug 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
visit casa_case_placement_path(casa_case, placement)
click_link("Edit")
visit edit_casa_case_placement_path(casa_case, placement)

I think would work - can run bin/rails routes -g casa_case_placement to check it's there. no big deal, just one less page load for every test.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would argue that those are two different tests. Navigating to the index first catches any issues with the edit link not being present etc.

That being said that might already be covered in another test and be unnecessary.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, but I would say that is a concern of the index system or view spec... it "displays link to edit" do or similar there... edit spec shouldn't worry about index (or the other ways we can get to this page) at all imo.

This comment was marked as resolved.

Comment on lines +16 to +17
visit casa_case_placements_path(casa_case)
click_link("New Placement")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
visit casa_case_placements_path(casa_case)
click_link("New Placement")
visit new_casa_case_placements_path(casa_case)

should work here.

@@ -1,6 +1,7 @@
require "rails_helper"

RSpec.describe "notifications/index", type: :view do
let(:base_time) { Date.new(2025, 1, 2) }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's going on here? seems unrelated?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah this is unrelated. fixes a flaky test (from a previous PR of mine)

enable_pundit(view, user)
allow(view).to receive(:current_user).and_return(user)
allow(view).to receive(:current_organization).and_return(user.casa_org)
render

This comment was marked as outdated.

@guswhitten
Copy link
Contributor Author

@thejonroberts i appreciate your effort, but it's functional and tested. this many refactorizations that change nothing about the actual product seems a bit ridiculous?

@thejonroberts
Copy link
Contributor

@thejonroberts i appreciate your effort, but it's functional and tested. this many refactorizations that change nothing about the actual product seems a bit ridiculous?

@guswhitten I hid some of the comments that were less important imo (I can't resolve convos).

I do think that maintainability is important in addition to functionality - whether things are readable and modifiable in the future matters. That's the motivation behind most of the suggestions. But I take your point. I didn't block merge by requesting changes. The suggestions are my opinions, the decision to use them is yours. I will approve when I can pull down and try it out, regardless.

I also made formatted suggestions so that you could commit directly from GitHub if you agree with the change, requiring less effort for you. Try it out with the two placement_types/placement_names changes in the factory if you like. I think that is definitely confusing to a reader because placement_type is a model/factory, and therefore prone to breaking something if changed/used incorrectly.

Copy link
Collaborator

@elasticspoon elasticspoon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@guswhitten Hey sorry bout the delay reviewing this. Largely I am fine with the whole thing. It works nice in local testing.

I have 1 remaining concern which is mainly around not confusing users. Because the implementation order is a bit wack and orgs don't actually currently have a way to create placement types could you make this bit:

image
not show up. Either via flipper flag or just checking if an org has placements.

I'll leave it up to you on how much of the refactorings you want to accept but none of that stuff is blocking.

Copy link
Collaborator

@elasticspoon elasticspoon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually after thinking a bit my earlier comment still applies but I would rather have this in sooner rather than later even in a slightly imperfect form.

Feel free to add the conditional on the org having placement types and any other refactorings, otherwise I'll probably merge it in tomorrow and make an issue to not show the html until a organization has placements.

Copy link
Contributor

@thejonroberts thejonroberts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the scope and factory changes! Looks good!

@elasticspoon
Copy link
Collaborator

👍 thank you for the work @guswhitten and @thejonroberts for the in depth review.

@elasticspoon elasticspoon merged commit b682c08 into rubyforgood:main Sep 6, 2024
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
erb ruby Pull requests that update Ruby code Tests! 🎉💖👏
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add creating, editing and displaying placements to casa case show page
3 participants