This tutorial inspects turning on each setting of new_framework_defaults_7.0.rb
file. The intended goal is to fully migrate to Rails 7's default set-up.
1. button_to_generates_button_tag
Rails.application.config.action_view.button_to_generates_button_tag = true
What
The button_to helper had inconsistent behaviour. Rails PR.
- string argument:
<input type="submit">
- block argument:
<button type="submit">
# 'new' is the string argument
<%= button_to "New", new_task_path %>
Before
<input type="submit" value="New">
After
<button type="submit">New</button>
2. apply_stylesheet_media_default
Rails.application.config.action_view.apply_stylesheet_media_default = false
What
A stylesheet_link_tag
can specify a media type. When omitting a media attribute, screen
is no longer set as the default media value Rails Guide.
<%= stylesheet_link_tag "application" %>
Before
<link rel="stylesheet" href="...css" media="screen">
After
<link rel="stylesheet" href="...css">
3. verify_foreign_keys_for_fixtures
Rails.application.config.active_record.verify_foreign_keys_for_fixtures = true
What
Ensures all foreign key constraints are valid after fixtures are loaded in tests. Rails PR
Before
# test/fixtures/parrots.yml
george:
name: "Curious George"
pirate: redbeard
# test/fixtures/pirates.yml
blackbeard:
name: "Blackbeard"
Fixtures can refer to a missing association.
parrots(:george).pirate
will be nil
After
An error is raised when fixtures are loaded in tests.
"Foreign key violations found in your fixture data. Ensure you aren't referring to labels that don't exist on associations."
Top comments (5)
Any tips on how to get info on which fixture has the violation?
Did you find a solution? 🤦♂️
I used VS Code to open the local copy of Active Record and edited out a statement that was suppressing the backtrace. Then I could see where the errors were coming from.
Fantastic!! Do you remember exactly what you changed?
No, but I think it was a statement in the AR Postgres adapter that rescues a PG exception and returns false instead, which then causes AR to raise the fixture error.