I’ve been working on rewriting some legacy feature tests that have been unmaintained for several years as system tests. One of the most convenient methods I have found while creating these tests is have_attributes. The RSpec documentation I linked to above is a great overview of the matcher. I have found that it’s useful to matching the result of a...
This trip was a bit opportunistic, making the most of a fine weekend in late winter to start getting back into the Forest Park before the official start of the summer season! Mitre Flats is one of the more popular spots to visit from the Wairarapa side of the Tararua range, and has been on our to-do list for some...
I spent a couple of hours last weekend getting a RaspberryPi Zero (W) up and running as a home automation node, joining my existing fleet of MySensor Arduino nodes. The Raspberry Pi is being used instead of an Arduino as it is eventually going to perform a number of functions along with climate sensing - for example, bluetooth presence detection...
This is something I use all the time. I don’t have it in my ~/.vimrc yet - partially because I haven’t got around to it, partially because I sometimes want to use different line lenghts, and partially because I don’t want to bikeshed myself trying to decide on what line length I want for different file formats. Vim supports soft...
I’ve recently been working on a small project that uses OAuth for authentication, which is proving to be a great approach for what I need it for. After I got the OAuth authentication layer working through, I realised that I needed a place to store the hash of user data I receive back from the OAuth provider, along with some...
ActiveModel::Errors are widely used in ActiveRecord and therefore Rails, and while custom messages can be provided to each validation using the message key, it’s much more flexible to instead pass a symbol as the message, which will cause the message to be looked up using the internationalisation framework provided by the i18n gem that is a dependency of Rails. Here...
Cloudflare is a brilliant service, and I’ve been using it for personal use for a couple of years now. In particular, its universal SSL, CDN, and always online capabilities have really come in handy. I use Cloudflare for my personal domain, and frequently build little toy applications that I usually host on Heroku free tier dynos. Because of how Heroku...
S3 supports redirecting content in a number of ways. In most cases, providing an XML-formatted collection of redirect rules is a good way of centralising where content is going. Using the XML format of redirect rules is also a neat way of extending an S3 bucket with additional behaviour by redirecting to a Lambda function or similar dynamic generation endpoint....
When testing CORS headers in Rails, an additional step is needed to check that the headers are working correctly. This is because of a behaviour in Chrome specifically, where requests that are to the same origin do not perform CORS validation - so it’s very difficult to tell whether CORS is working correctly or not. Chrome does not even appear...
This code snippet is a reusable pattern for testing out a model/association structure in ActiveRecord to see whether it’s worth proceeding with. The snippet covers installing necessary dependencies, setting up an in-memory SQLite3 database, and loading a database schema into this database. The example included in the pattern was prepared to demonstrate a has many through association between users and...