-
-
Notifications
You must be signed in to change notification settings - Fork 484
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
Fix 5780 #5991
Conversation
There was a problem hiding this 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.
@@ -5,23 +5,63 @@ class PlacementsController < ApplicationController | |||
|
|||
rescue_from ActiveRecord::RecordNotFound, with: -> { head :not_found } | |||
|
|||
def index | |||
authorize @casa_case |
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
Sorry, something went wrong.
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
authorize @casa_case | ||
@placement = Placement.new |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
app/models/placement_type.rb
Outdated
validates :name, presence: true | ||
scope :for_organization, ->(org) { where(casa_org: org).order(:name) } |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
Co-authored-by: Jon Roberts <[email protected]>
Co-authored-by: Jon Roberts <[email protected]>
spec/factories/casa_orgs.rb
Outdated
@@ -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"] } } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
spec/factories/casa_orgs.rb
Outdated
after(:create) do |org, evaluator| | ||
evaluator.placement_types.each do |name| | ||
org.placement_types.create!(name: name) | ||
end | ||
end |
There was a problem hiding this comment.
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:
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 |
There was a problem hiding this 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.
This comment was marked as resolved.
Sorry, something went wrong.
app/policies/placement_policy.rb
Outdated
class PlacementPolicy < ApplicationPolicy | ||
class Scope < ApplicationPolicy::Scope | ||
def resolve | ||
scope.joins(:casa_case).where(casa_cases: {casa_org_id: @user.casa_org_id}) |
There was a problem hiding this comment.
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).
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 %> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<%= 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"?
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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.
<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.
This comment was marked as outdated.
Sorry, something went wrong.
visit casa_case_placement_path(casa_case, placement) | ||
click_link("Edit") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
This comment was marked as resolved.
Sorry, something went wrong.
visit casa_case_placements_path(casa_case) | ||
click_link("New Placement") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) } |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
This comment was marked as outdated.
Sorry, something went wrong.
@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 |
There was a problem hiding this 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:
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.
There was a problem hiding this 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.
There was a problem hiding this 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!
👍 thank you for the work @guswhitten and @thejonroberts for the in depth review. |
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 :)