Skip to content

Refactor NewPhoneForm class for clarity, consistency, conventions#7766

Merged
aduth merged 5 commits intomainfrom
aduth-new-phone-form-refactor
Feb 3, 2023
Merged

Refactor NewPhoneForm class for clarity, consistency, conventions#7766
aduth merged 5 commits intomainfrom
aduth-new-phone-form-refactor

Conversation

@aduth
Copy link
Contributor

@aduth aduth commented Feb 3, 2023

🎫 Ticket

Extracted from #7761, related to LG-8771.

🛠 Summary of changes

Minor revisions to NewPhoneForm to improve clarity and consistency of arguments, and adopt conventions of instance variable assignment.

  • Change user from positional argument to keyword argument, so that there's not an unnecessary combination of both, and to improve the clarity of the arguments that the class is expected to receive, since it's not instinctively obvious that user would be the first argument of the class's constructor.
  • Use @ instead of self. for class instance variable assignment, since it's more conventional.

📜 Testing Plan

  • rspec spec/forms/new_phone_form_spec.rb

Copy link
Contributor

@zachmargolis zachmargolis left a comment

Choose a reason for hiding this comment

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

LGTM one small suggestion

Comment on lines +24 to +27
@user = user
@otp_delivery_preference = user.otp_delivery_preference
@otp_make_default_number = false
@setup_voice_preference = setup_voice_preference
Copy link
Contributor

Choose a reason for hiding this comment

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

if we're no longer using the writer methods, let's change the attr_accessor above to attr_reader?

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 I'd be on-board with that. I'll need to check that the accessor methods weren't being used outside the class implementation.

Rewrites phone validation specs since they rely on the accessor, which isn't actually how the class validation would happen in the real-world
@aduth aduth merged commit d0f9e38 into main Feb 3, 2023
@aduth aduth deleted the aduth-new-phone-form-refactor branch February 3, 2023 19:40
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.

3 participants