Photo by Roberto Nickson on Unsplash

Testing endpoints in Ruby on Rails can be either very simple, or incredibly frustrating. If you are performing a simple get statement for a JSON object, setting up tests that return this object for assertions is easy. However, how do you test an endpoint that returns a number of instance variables for use in ERB files?

A tenant of good OOP programming is keeping a clear division between public and private interface. Other models, controllers and views should be able to access only what they need to. By keeping the surface areas of your interface small, you avoid code misuse…

Photo by KOBU Agency on Unsplash

If you’ve worked on an app or website for a long enough time then you’ve surely run into the issue of having more items to look through than is manually possible for users. While the widely accepted solution to this issue is to slap Elasticsearch on your project, there are other ways to allow users to find what they’re looking for.

For projects built with SQL, there is a statement structure and special operators that allow you to easily implement a lightweight search. …

Photo by Stephen Dawson on Unsplash

Databases are the backbone of any data intensive app. They keep track of who did what and when. While databases are usually great at recording the order of events, just like human memories, they are prone to lapses.

A set of instructions sent to a database can be interrupted and ruined for many reasons. While something like redoing a draft of an article may be a minor inconvenience, a botched bank transfer could lead to the loss of millions of dollars for a company. Because of this, computer scientists introduced the concept of transaction blocks.

What is a transaction block?

Photo by Samuel Sianipar on Unsplash

Even after working with git for a few years I am still left in awe sometimes at its capabilities. The ability for developers to work on different parts of the same project at the same time through the use of branches is amazing. While these branches can help boost productivity by allowing simultaneous progress, they can also lead to wasted time and thought if used without proper naming conventions.

If you thought variables were the only items that caused issues when named improperly, just try to work with a 10 dev team who all use different naming conventions to create…

Photo by Science in HD on Unsplash

Good tests revolve around great data. How you get or generate this data can occur in many different ways. For Ruby on Rails, two of the most common ways to get data for testing are factories and fixtures. Though both of these strategies create data that can be used across tests, they do it in different ways.

Before we dive into the benefits and drawbacks of features and fixtures let’s first look at what they are. A fixture is “the fixed state used as a baseline for running tests in software testing.” …

Photo by Veron Wessels on Unsplash

TLDR: Enums are a great user-defined model level validation for stored values. There are many ways to implement enums in Ruby on Rails, but the best way uses hashes with strings for the keys and values.

Ruby on Rails is great for newer developers as it preaches convention over configuration. What this means is that there is a community agreed upon “correct” way to setup models and controllers. This convention includes scaffolding scripts which makes setup quicker, allowing for more time implementing solutions rather than writing boilerplate code.

When creating database migrations there are a number of different types for…

Photo by Ryan Quintal on Unsplash

TLDR: You can create a reusable Layout component in React without knowing its nested components by making use of React’s “children” prop. By passing in the children prop to your Layout component, you can add JSX of { children } to your component which will inject any nested components into Layout when you call it.

What is the children prop?

React is great as it allows developers to create sets of reusable UI components. Because of this, developers are able to quickly create a beautiful, interactive webpage from a set of common building blocks. …

Photo by Patrick Tomasso on Unsplash

TLDR: You can use commits to move around in your project’s history, and moving to a specific commit will place you in a detached HEAD state. A detached HEAD state means that git’s pointer points towards a specific commit instead of a branch and requires a new branch to save any work done from the detached HEAD state.

A few weeks ago I was putting the finishing touches on some changes I had made for a ticket, and was getting ready to push the changes up to GitHub. I had been working on this issue for a while and had…

Photo by Shane Aldendorff on Unsplash

TLDR: RSpec offers a powerful match matcher that will allow you to leverage regular expressions to make non-brittle tests. Coding non-brittle tests that are robust and test behavior instead of implementation will save you maintenance time and lead to overall better quality code.

A common set of tests cases for any web app is checking that the correct message is returned upon user request. This can be anything from checking for “insufficient account funds” to “shoe size X not available.”

While software engineers like to think that the first message they code will be the last, these messages are often subject to change by the business group or users. The message might be too short, or too long or not clear in what it conveys. Because of this, a software engineer could end up changing this message many many times.

If these changes…

Photo by Fleur on Unsplash

While working on a recent project, I came upon a guard clause acting on an API response. My app returned a specific message to the user based on whether or not the API gave back a value of true or false. Whether this API was unstable or the previous developer was just cautious, I found a “to_b” appended to the end of the attribute we were checking. While I had worked with “to_b” before, I had never dove into it’s inner workings, and was curious to learn more.

One of the great challenges of interacting with 3rd party APIs is…

Daniel Pericich

Former Big Beer Engineer turned Full Stack Software Engineer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store