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 build user update params #2657

Merged
merged 6 commits into from
Jan 25, 2024
Merged

Conversation

chrislo
Copy link
Contributor

@chrislo chrislo commented Jan 22, 2024

Trello: https://trello.com/c/yDM25WlZ

This PR is an attempt to remove some of the duplication we added in c723644, edf2e83 and 92c5f5c with the build_user_update_params controller method. I did consider folding some of this logic into UserUpdate but as we're currently thinking about simplifying or removing that altogether (e.g. #2623) I think for now it's an improvement to have the code shared between the three controllers via a simple Ruby object. It'll at least make it easier to move somewhere else in the future.

@chrislo chrislo force-pushed the refactor_build_user_update_params branch 2 times, most recently from 5d44e19 to a034b98 Compare January 23, 2024 16:39
@chrislo chrislo marked this pull request as ready for review January 23, 2024 16:56
Copy link
Contributor

@chrisroos chrisroos left a comment

Choose a reason for hiding this comment

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

Looks good to me, @chrislo 👍

This method is effectively duplicated across three controllers. I'd
like to extract it to remove the duplication. Parameterizing the
arguments rather than relying on shared state will help me do that.
This method is effectively duplicated across three controllers. I'd
like to extract it to remove the duplication. Parameterizing the
arguments rather than relying on shared state will help me do that.
This method is effectively duplicated across three controllers. I'd
like to extract it to remove the duplication. Parameterizing the
arguments rather than relying on shared state will help me do that.
This makes the call to UserUpdate.new easier to follow and makes the
return value of build_user_update_params less tightly coupled to how
it is eventually used.
This commit moves the identical build_user_update_params method from
each of the three controllers into a class. I think this is an
improvement as it ensures that the business logic is defined in a
single place and can't drift out of sync.

The implementation of this method is currently covered by the
controller tests but in a subsequent commit I'll introduce some unit
tests for this class to help reduce the duplication in the controller
tests.
We test these two scenarios multiple times in three different
controller tests. Now the underlying logic has been extracted to
UserUpdatePermissionBuilder I think they can be replaced with simpler
and more comprehensive tests of `UserUpdatePermissionBuilder#build`.

Note the remaining tests of the update method in the three permissions
controllers are still useful - they effectively test that the correct
values are set by the `set_application` and `set_permissions` methods
on those controllers.

I considered refactoring these tests to `expect` that
`UserUpdatePermissionBuilder` is called correctly, but decided to keep
things as they are for now. This change still feels like an
improvement.
@chrislo
Copy link
Contributor Author

chrislo commented Jan 25, 2024

Thanks @chrisroos - rebasing before merging.

@chrislo chrislo force-pushed the refactor_build_user_update_params branch from a034b98 to beb5d26 Compare January 25, 2024 10:56
@chrislo chrislo merged commit cc84050 into main Jan 25, 2024
16 checks passed
@chrislo chrislo deleted the refactor_build_user_update_params branch January 25, 2024 11:01
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