Welcome to another edition of This Week in #dev, a series of posts where we bring some of our most interesting Slack conversations to the public.
URL-Safe serialization for any Ruby object
Matheus Richard shares a gem called Universal ID that can serialize any Ruby object into a URL-safe string. This is a generalization of Rails’ Global ID.
uri = URI::UID.build(:demo).to_s
#=> "uid://universalid/iwKA1gBkZW1vAw#CwWAkccHf6ZTeW1ib2wD"
Configuring Rails Generators to Use FactoryBot with Minitest
Louis Antonopoulos provides guidance for Minitest users on configuring Rails’ generators to use FactoryBot instead of fixtures.
To set up:
- Add
gem "minitest-rails", "~> 8.0.0"
to the:test
group in your Gemfile, matching your Rails version. - Update
config/application.rb
with:
# Use FactoryBot instead of fixtures when using Rails generators
config.generators do |g|
g.test_framework :minitest, spec: false, fixture: false
g.fixture_replacement :factory_bot, dir: "test/factories"
end
Running rails g model tomato
will now:
- Add a
:tomato
factory totest/factories.rb
- Avoid generating
test/fixtures/tomatoes.yml
Thanks
This edition was brought to you by Louis Antonopoulos and Matheus Richard. Thanks to all contributors! 🎉