TIL that aria- attributes get the same treatment in Rails tag helpers as data-. That is, you can do: link_to "X", y_path, aria: { pressed: true } -> aria-pressed="true" OR link_to "X", y_path, "aria-pressed" => true -> aria-pressed="true" I can’t find any multi-dash aria properties on MDN, but I imagine Rails will follow the same formatting rules of turning underscores...
Trix is fairly new to me, but now that it’s closely integrated with Rails, it’s become by go-to for rich text editing. I’ve been working on a project where I wanted a text field with some basic rich text capabilities, but I wanted the input to look like a normal textarea. This would allow standard text entry, but allow users...
View specs are great. While I always keep in mind they are a unit test and do not test the full integration of a feature, I find that they are fantastic for asserting around all the edge cases of a feature - things like the expected validation messages showing up, or buttons appearing or disappearing based on different scenarios. I...
entr is a tool I’ve been using a bunch recently - mostly for watching source files, and running tests when I change the source file. entr can be piped one or more files, which means it’s really easy to use - just use ls, find, or any other tool that outputs filenames, and then pipe it to entr: ls app/models/widget.rb...
I have a React component that is part of a wider Ruby on Rails application. It fetches a record, and if the record does not exist, it redirects to the server-rendered 404 page. Unfortunately, while the user will see the ‘not found’ page, the HTTP status code will be 200 OK by default, because this page is static. Best practise...
This trip report is really more a cautionary tale of overconfidence and inexperience leading to a challenging Tararua overnight trip to Mid King Biv. Started: 11am from Holdsworth Carpark Finished: 6:30pm the next day at Holdsworth Carpark Travel Times: Day 1: 2 hours to Atiwhakatu Hut (break) 1 hour from Atiwhakatu Hut to the swingbridge over Atiwhakatu Stream 20 minutes...
Often, mailer specs will start with a simple assertion like expect(mail.body).to include "Some text in the expected email here". This works for a while, but quickly breaks down when an email grows more complex, such as having special characters causing it to be encoded as 7bit or QuotedPrintable, having attachments, or supporting different formats (like plaintext & HTML). I’ve always...
I recently created a Presenter object to wrap around an ActiveStorage::Blob that I wanted to decorate with some presentation methods for things like a human file size and content type. The initialisation signature for my presenter looks like this: class MyPresenter < SimpleDelegator def initialize(obj, view_context) super(obj) @view_context = view_context end def human_file_size @view_context.number_to_human_size(byte_size, precision: 1) end # more presentation...
Sometimes I’ll need to find an element in relation to another. An example of this is a link with a single icon element inside it: <a href="/example"><img src="icon.png" alt="Example Page" /></a> Because Capybara element finders can be chained (e.g. you can do find().find().find() to traverse down elements, the ability of XPath to traverse the DOM tree can be used to...
When an update method like @my_record.update(test_attr_1: "foo", test_attr_2: "bar") is called, my assumption was that those attributes immediately got passed to some ActiveRecord magic to update the record. Not true! Each attribute key calls the setter on the object - in this case, @my_record.test_attr_1=(new_value) and @my_record.test_attr_2=(new_value) would be called. This is neat because you can ‘redirect’ that attribute assignment to...