Use form object pattern for Idv::AddressController submission#10388
Use form object pattern for Idv::AddressController submission#10388
Idv::AddressController submission#10388Conversation
While I was working on #10385 I noticed that the `Idv::AddressController` includes a form object but does not implement the Form Object Pattern the way I expected. Specifically the form was only initialized and used to validate input params. As a result a few of the expected features were missing. Namely error messages did not appear on the rendered view. This commit adjusts `Idv::AddressController` to use the pattern as expected. This commit also adds specs for `Idv::AddressForm` which I noticed were missing despite the form object having some complexity to account for the `address_edited` value in the `FormResponse`. [skip changelog]
| ATTRIBUTES.each do |attribute_name| | ||
| if send(attribute_name).to_s != params[attribute_name].to_s | ||
| @address_edited = true | ||
| end | ||
| send(:"#{attribute_name}=", params[attribute_name].to_s) | ||
| end |
There was a problem hiding this comment.
It looks like this is very similar to set_ivars_with_pii except this sets @address_edited = true, do you think it would be worth trying to combine? or nah
There was a problem hiding this comment.
I made an effort to combine and struggled with a good way to do it well. I am going to be working on this again in #10385 and I'm hoping that it will be easier when we have a struct to represent an address because then we can just compare them.
There was a problem hiding this comment.
@zachmargolis: I just opened #10390 which includes these changes to the AddressForm: https://github.com/18F/identity-idp/pull/10390/files#diff-1b0c80e533f13f34a865f61b08ff023a3efbd21ba6bfa03aa84e0c3d0c108128
I got it out of the business of tracking address edits. My thinking is that once we stop overwriting the address in pii_from_doc we will get a fix for this bug: https://github.com/18F/identity-idp/pull/10385/files#diff-ee8ce27b8fbb65556458f217dd0017a6418194fd31087457ac79c219f750d337R130
While I was working on #10385 I noticed that the
Idv::AddressControllerincludes a form object but does not implement the Form Object Pattern the way I expected. Specifically the form was only initialized and used to validate input params. As a result a few of the expected features were missing. Namely error messages did not appear on the rendered view. This commit adjustsIdv::AddressControllerto use the pattern as expected.This commit also adds specs for
Idv::AddressFormwhich I noticed were missing despite the form object having some complexity to account for theaddress_editedvalue in theFormResponse.Now the form looks like this if you submit an error:

Previously this was not the case. The form would not render errors at all. This was not a huge issue since there was client side validation.