Hey, happy new year! Welcome to the first 2023 edition of This Week in #dev, a series of posts where we bring some of the most interesting Slack conversations to the public. Today we’re talking about hiding HTML content, Active Record methods, and debugging system tests.
Steve Polito has discovered a global attribute in HTML that can be used to hide content from the user. This attribute is hidden from all presentations, including screen readers. You can read more about it here.
<p>This content should be read right now, as it is important. I am so glad you are able to find it!</p> <p hidden>This content is not relevant to this page right now, so should not be seen. Nothing to see here. Nada.</p>
Rémy Hannequin discussed the use of the
dependent: :destroy_async option
has_many associations in Ruby on Rails. This option will enqueue an
ActiveRecord::DestroyAssociationAsyncJob job which will call destroy on the
associated objects, but Active Job must be set up for it to work.
Neil Carvalho explained that
Enumerator#with_index can take an offset argument,
which is useful when you need to start the index at a number other than 0.
# Note the `each` to build an enumerator ["first", "second", "third"].each.with_index(1) do |element, index| # element => "first" / index => 1 # element => "second" / index => 2 # element => "third" / index => 3 end
User.in_order_of(:id, [1, 5, 3]) # This generates this SQL query: # SELECT "users".* FROM "users" # WHERE "users"."id" IN (1, 5, 3) # ORDER BY CASE # WHEN "users"."id" = 1 THEN 1 # WHEN "users"."id" = 5 THEN 2 # WHEN "users"."id" = 3 THEN 3 # END ASC # # => [#<User id: 1, name: "First User">, # #<User id: 5, name: "Fifth User">, # #<User id: 3, name: "Third User">]
Neil also discovered a difference between using
binding.pry to pause a system test using Capybara.
debugger pauses the
entire program execution, while
binding.pry pauses only the spec. With
binding.pry, the background process running the system spec server is not
paused, allowing the user to manually click and inspect the network effects of