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,...
Virtualtrails uses Strada to bridge native iOS code to the web application, including notifications, native Apple + Google Signin and Apple Healthkit integration. I added a feature yesterday to replace a Bootstrap dropdown with a native iOS sheet, just because it’s a more intuitive experience for users. Strada has two parts - the web side (which is in the form...
I use both RSpec and Minitest, but prefer Minitest. It’s not quite as feature-rich as RSpec, but I find that I prefer the tests I write in Minitest - they are more Ruby-ish, and aren’t as reliant on RSpec’s DSL to work. I don’t use around callbacks in RSpec very often, but it is something I recently found myself wanting...