DEV Community

Jared Bears
Jared Bears

Posted on

Remember the Importance of Data Validation

After being introduced to Active Records and working with SQL in Rails, I was working on an assignment earlier today and came up with a roadblock.

I completed the assignment, and submitted it to the auto-grader. Everything looked perfect on my end, all of my own tests worked, but for some reason 1 single test on the auto-grader was failing, and I could not figure out why.

I approached one of the course instructors and asked for help. He advised me to open up the test, and manually run through the steps the test was going through. This was absolutely helpful advice: I was looking at the code and didn't see any problems, but I did not think to step through the test in this way.

It turns out the test was providing incomplete data to enter into the database, and so it was throwing an error when I tried to read that same data back.

The code was perfectly fine, but the data was not fine! And this is something we definitely need to remember - when working with user supplied data, there is no guarantee it will be accurate or complete.

We must always build our systems in such a way that we can validate any externally provided information, and determine an appropriate way to handle that information depending on the purpose of the application.

Top comments (1)

Collapse
 
samuellubliner profile image
Samuel Lubliner

Manually running through the steps of test is clever!