Development Simplified | A blog about ruby, sql, performance, and patterns. By Josh Frankel.

Testing request specs for invalid formats, Pundit authorization, and ActiveRecord failures

posted in today i learned

 

Request formats should match their endpoints. Authorization adds a split between authorized and unauthorized requests. ActiveRecord means we’re at times making an unnecessary database calls (which I like to avoid). One way to minimize such calls is to stub interactions between objects using stubbing.

For the remainder of this post, we’re going to dig into how to properly test invalid request formats, authorization logic, and ActiveRecord failures. Let’s get to it!

Using request-based constraints to only accept JSON formats for endpoints

posted in today i learned

 

I prefer doing things The Rails Waytm whenever possible. Oftentimes when you are working with web requests, your controllers expect to respond to specific content formats. Formats that are outside of this expected format are generally handled within the controller layer. There’s nothing wrong with this approach BUT we can do better here by using request-based constraints in the Routing layer.

Prevent CSS transitions on page load with ES6

posted in articles

 

I recently noticed on my blog that sometimes the CSS hover transitions for font-size, border-color, and color animate on page load. While this doesn’t impact the final design, it does make the initial page load a bit of a stylistic mess.

I stumbled upon a great post on css-tricks that outlined a fix for this issue using jQuery. However, my goal for this site has always been keeping it as lean as possible. That's why I use Jekyll for static pages and minimal scripting (outside Disqus and Google Analytics). So of course I dug into how we can skip jQuery and just use ES6.

Calculating Frequency Distribution in PostgreSQL

posted in tutorials

 

I’ve always loved statistics. Being a software engineer has allowed me a lot of opportunities to solve complex statistical problems in SQL. With programming, we want to consider the current state of data which means running calculations on demand. Recently, I had the opportunity to calculate frequency distribution in SQL and wanted to share what I’ve learned with you.

Formatting Enum columns into a human readable format with SQL

posted in today i learned

 

Enum columns can be really handy when working with Rails. There are a lot of built-in helper methods that allow for quickly writing code and they make type-checking simple. However, when working with raw SQL they can be difficult to work with as they’re stored as integers and as such lose their meaning. Keep reading to dig into a shortcut for staying SQL-land while returning an Enum in a human readable format.

Using RSpec to set expectations for stdout

posted in today i learned

 

I’ve been working on a gem in my spare time for code coverage and one of its goals is to output coverage reports to stdout. The hope is that while running something like guard for RSpec, also having test coverage output during the red-green-refactor cycling will be useful. What I didn’t realize beforehand is that output is fully testable within RSpec. Here’s an example of ensuring a proper message is sent via puts.

Configure Puma SSL for local development on Ubuntu

posted in tutorials

 

Having your development environment match production helps ensure that a feature works the same in both contexts. An example of when local SSL is beneficial is whenever you are dealing with hardware specific permissions such as a webcam or microphone. This tutorial is specifically for Debian based Linux on the lvh.me domain for Google Chrome but it could also be used in other contexts.

  • 1
  • 2
  • 3
  • 4
  • 5