DEV Community

Jared Bears
Jared Bears

Posted on

1

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.

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (1)

Collapse
 
samuellubliner profile image
Samuel Lubliner ā€¢

Manually running through the steps of test is clever!

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

šŸ‘‹ Kindness is contagious

Please leave a ā¤ļø or a friendly comment on this post if you found it helpful!

Okay