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

Refactor matches #524

Merged
merged 7 commits into from
Mar 11, 2024
Merged

Refactor matches #524

merged 7 commits into from
Mar 11, 2024

Conversation

mononoken
Copy link
Collaborator

@mononoken mononoken commented Mar 10, 2024

🔗 Issue

No issue.
Similar to #475, I thought Match could benefit from refactoring. Note that I will be cleaning it up further, getting rid of same_organization? and get_pet_id in the Authz PR too.

✍️ Description

This started with me changing the routes to the Rails convention. I personally found it a little confusing that sometimes we refer to adoptions as "adoptions" and sometimes as a "match". This PR tries to at least make it so that things using Match refer to it as a "match". This includes things like the strong params name.

The other portion of this PR works to get AdopterApplication logic out of MatchesController. I think this business logic belongs in the models. I also like setting withdraw for an individual object more as an instance method rather than as a class method like self.set_status_to_withdrawn was doing. Feels more intuitive.

Using update!

One thing I would like to bring attention to and get opinions on, is that I opted to use update! instead of update for these new methods. I was of two minds on it. The main difference is that update! is not silent and will raise an error. That seems undesirable in some cases.

However, where would this failure occur? Currently, retire_applications is called in AdopterApplication#create after a valid creation is performed. If something was going wrong where the applications could not update following a successful match, I think we would want to know about that. I also think the use cases here are fairly reliable and can't think of a case where I would expect them to fail.

Using mocks

I would also be curious of opinions on how I wrote the model tests too. I think mocking works well for some of those tests but would love to hear other's thoughts.

@nsiwnf
Copy link
Collaborator

nsiwnf commented Mar 10, 2024

Thanks for the cleanup on this! Taking a look now 👀

Yeah, at some point we thought "Match" made more sense than "Adoption" since we wanted to support "Foster" as well. "Match a pet with an adopter/foster"

Copy link
Collaborator

@nsiwnf nsiwnf left a comment

Choose a reason for hiding this comment

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

Running into a few errors locally - some are unrelated to this PR. Are you able to go through various flows on the application_review page?

end

def set_match
@match = Match.find(params[:id])
end

def get_pet_id
return params[:pet_id] if params[:pet_id]
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this should be match_params[:pet_id]?

Suggested change
return params[:pet_id] if params[:pet_id]
return match_params[:pet_id] if match_params[:pet_id]

app/controllers/matches_controller.rb Show resolved Hide resolved
@mononoken
Copy link
Collaborator Author

mononoken commented Mar 10, 2024

Thanks for the cleanup on this! Taking a look now 👀

Yeah, at some point we thought "Match" made more sense than "Adoption" since we wanted to support "Foster" as well. "Match a pet with an adopter/foster"

Thank you! That makes sense.

Running into a few errors locally - some are unrelated to this PR. Are you able to go through various flows on the application_review page?

Good catch. Your suggested change on line 46 fixes this I think. I have added that now. I just realized I was not getting this error because I had been running the server off of the authz branch instead of this branch and the authz branch already got rid of get_pet_id and same_organization?. Woops! Should be working now.

Copy link
Collaborator

@nsiwnf nsiwnf left a comment

Choose a reason for hiding this comment

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

lgtm!

@mononoken mononoken merged commit df19a14 into rubyforgood:main Mar 11, 2024
5 checks passed
@mononoken mononoken deleted the refactor_matches branch March 18, 2024 06:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants