System tests ignore default_url_options and default_locale. Other tests don't

For some reason, system tests don’t respect the default_locale and/or default_url_options.

url_for based path helpers that work fine in production and development all fail with an error like this:

ActionController::UrlGenerationError: No route matches {:action=>"show", :controller=>"posts", :locale=>#<Post id: 980190962, title: "MyString", content: "MyText", created_at: "2019-11-27 22:50:33", updated_at: "2019-11-27 22:50:33">}, missing required keys: [:id]

I absolute think system test should respect the default_locale and default_url_options though, as they are part of the … well system and controller tests for example, mind those settings too.

One would have to work around this by manually passing the locale to each and every path helper invocation in all system tests or monkey patch the initialize(*) method from actionpack/lib/action_dispatch/system_test_case.rb (previously there has been a simpler workaround, that stopped working from 6.0.1 onward).

I would be happy to try and provide a PR to fix this, if this is something that other people also think should be changed. A issue I opened about that topic has been closed though.

2 Likes

It looks like the issue was closed as stale, so my guess is that you opened it during a time the maintainers were particularly busy and it fell of the radar. I suspect that if you opened a PR it would be greeted enthusiastically – lmk if you want a hand shepherding that through!

1 Like

Sure, that would be great. Here is my email.

Afaic this is still an issue in Rails 7.x ?!

2 Likes