Enable rubocop rule to disallow OpenStruct usage#11397
Conversation
changelog: Internal, Performance, Enable rubocop rule to disallow OpenStruct usage
|
|
||
| def proof(applicant) | ||
| aamva_applicant = | ||
| Aamva::Applicant.from_proofer_applicant(OpenStruct.new(applicant)) |
There was a problem hiding this comment.
This is the scariest removal, but in looking through the usage, it doesn't seem like we call methods on it at all, and only use hash key access.
| # controller's params. As this is a model spec, we have to fake | ||
| # the params object. | ||
| fake_params = ActionController::Parameters.new( | ||
| user: OpenStruct.new(id: 'fake_user_id'), |
There was a problem hiding this comment.
I feel like we could add an exception to this rule for specs if we wanted?
There was a problem hiding this comment.
I kinda feel like most of these examples are improved (made more realistic) by not using structs?
There was a problem hiding this comment.
Yeah, that was my thought as well. We also have double() which is not quite the same as OpenStruct, but appropriate enough for testing cases where we need something that responds to a given method.
There was a problem hiding this comment.
I also meant to mention that I'm much less concerned about using it in specs though, yeah.
spec/views/users/piv_cac_authentication_setup/new.html.erb_spec.rb
Outdated
Show resolved
Hide resolved
| # controller's params. As this is a model spec, we have to fake | ||
| # the params object. | ||
| fake_params = ActionController::Parameters.new( | ||
| user: OpenStruct.new(id: 'fake_user_id'), |
There was a problem hiding this comment.
I kinda feel like most of these examples are improved (made more realistic) by not using structs?
…c.rb Co-authored-by: Andrew Duthie <1779930+aduth@users.noreply.github.com>
🛠 Summary of changes
OpenStruct usage is discouraged and Ruby 3.3 emits performance warnings for its use. This PR removes all of our usage as well as updates
yardwho removed usage in the most recent release. I have also enabled a Rubocop rule that will fail if we use it in the future.