It's still tricky to get this right in Rails 7, but fortunately much more straightforward compared to Rails 6.
It can be done by adding this line in ```config/environments/test.rb```:
```
Rails.application.routes.default_url_options[:locale] = I18n.default_locale
```
Or by adding this in ```test_helper.rb```:
```
class ActiveSupport::TestCase
setup do
Rails.application.routes.default_url_options[:locale] = I18n.default_locale
end
```
However, neither of the above solutions solve the issue for system tests. To address that, add this into ```application_system_test_case.rb```:
```
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
...
setup do
default_url_options[:locale] = I18n.default_locale
end
```
This is still tricky, but fortunately ultimately much more straightforward to solve in Rails 7.
Controller/Integration tests can be made to work correctly by adding this line in ```config/environments/test.rb```:
```
Rails.application.routes.default_url_options[:locale] = I18n.default_locale
```
Or by adding this in ```test_helper.rb```:
```
class ActiveSupport::TestCase
setup do
Rails.application.routes.default_url_options[:locale] = I18n.default_locale
end
```
However, neither of the above solutions solve the issue for system tests. To get system tests working correctly, add this into ```application_system_test_case.rb```:
```
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
...
setup do
default_url_options[:locale] = I18n.default_locale
end
```