I’m trying out OpenNext with Cloudflare. One kind of annoying thing already I’ve run into is that libraries that use cross-fetch end up running into errors, because OpenNext patches the deployment package enough that cross-fetch tries to use Node libraries, when actually it can just use native fetch. In the case I ran into, I could work around this by...
I tried to get to Eastern Hutt Hut on Friday. Didn’t quite make it, just because I’d committed to a half day rather than full day trip, but it seemed doable. I turned around here with 2km to go, it took me 2 hours to get there after biking over from Kaitoke on the 4WD road - 1 hour biking,...
Just a quick tip! If you’re like me, you start with just one or two tabs (or tmux panes), and things get more and more disorganised as the day goes on. If you need to restart your Rails server quickly, and don’t feel like hunting out your Rail server terminal, no worries! Just running bin/rails restart will signal the server...
Note: I discovered this API based on a suggestion from an AI editor assistant, just to disclaim that. When creating an RSpec test against an enumerable, rubocop-rspec will enforce that the all matcher be used instead: it "only returns odd numbers" do odd = [1 3 5] expect(odd).all(be_odd) end This is fine for a matcher that doesn’t require any args...
In a before|after_destroy callback, you can use the destroyed_by_association method to access the association (therefore the parent record or parent record type) that is causing this record to be destroyed. This is also a handy way to tell the difference betwee a ‘direct’ destruction (widget.destroy), and a ‘dependent’ destruction has_many :widgets, dependent: :destroy`). I had a use case for this...
Several years ago, the Rails core team advised that controller tests/specs were being discouraged, in favour of request specs. The basis for this was that controller tests had more visibility into the internals of the controller, and were not purely testing the HTTP interaction as request specs were. This is valid, but one method I end up missing a lot...
ActionMailer Previews are a great way to provide some living documentation in the form of rendered emails. They’re also great for testing. Often, in order to generate a preview, you might need to create a database record - perhaps using fixtures, or a tool like factory_bot. When you do this, you might be surprised to see these records then show...
Minitest has support for stubbing via Minitest::Mock. This is a good fit for providing fake results to a caller, but what about asserting that a method is actually called? To do this, you can leverage the fact that if the stubbed value is callable, it will be called. This means that you can provide a mock, then expect that the...
I love gdal, particularly ogr2ogr. Like ffmpeg, and convert, it’s just one of those convert anything to anything commands that is so handy to know about. ogr2ogr is part of the GDAL library, and is particularly suited to converting files containing geospatial data from one source to another. I often use this tool to convert shapefiles into GeoJSON for example,...
Normally I would use Bootstrap’s stretched link behaviour to implement functionality where clicking anywhere on a containing element triggers a link element. This is useful for cards, menus, and other cases where a ‘primary’ link can benefit from a larger tap target. Bootstrap’s stretched link works by adding an ::after pseudo element to the link element with the stretched-link class,...