We are rewriting the front end of the application on which I work. Several of the forms which gather data that drives the application previously had checkboxes, which would set a value to true or false in the database.
Some of the checkboxes were ancillary, however, and didn’t result in a database value. Instead, they were used to calculate a different result depending on whether the checkbox was checked or not. That result would then be saved to the database. This was all tested via rspec controller tests.
In at least one case, the calculation depended on the existence of the parameter. Checkbox parameters are sent when they are checked and omitted when they are not.
Then we changed the forms to radio buttons.
Instead of sending the parameter if the box was checked yes or not sending the parameter if it was checked no, we sent yes if the radio button was checked and no if it was not.
The tests continued to pass, because they hadn’t been updated to the new values.
So the calculation was incorrect. Which meant that the functionality that depended on the calculation was incorrect. Unfortunately, that functionality was related to billing. So I just spent the last few days backing that out, checking with clients to see what they actually intended to do, and in general fixing the issue.
The underlying code was an easy enough fix, but this story just goes to show that software is complicated. Lessons learned:
- favor a test for an exact parameter value rather than parameter existence
- when changing forms, consider writing tests with the new input values
- integration tests that drive a browser would have caught this issue. These are much slower so need to be used judiciously, but are still a valuable automated test