svenfuchs / routing-filter

routing-filter wraps around the complex beast that the Rails routing system is, allowing for unseen flexibility and power in Rails URL recognition and generation.
http://www.artweb-design.de
MIT License
464 stars 84 forks source link

Filter locale breaks default_url_options in tests (setting the Locale from URL Params) #80

Open viktorianer opened 2 years ago

viktorianer commented 2 years ago

In the Usage section, under Tests, it says that

RoutingFilter should not be enabled in functional tests by default.

And if I do so, it breaks the recommended way to Setting the Locale from URL Params, as described in the Rails I18n Guides.

Step to reproduce

rails _7.0.0_ new sample_app
rails generate scaffold Contact email
# run test, all passing
# add this gem
# configure it like described under [usage](https://github.com/svenfuchs/routing-filter#usage) section
# add `RoutingFilter.active = false` to test_helper.rb
# run tests again
rails test test/controllers/contacts_controller_test.rb
# it will fails with
Expected response to be a redirect to <http://www.example.com/contacts/980190963> but was a redirect to <http://www.example.com/en/contacts/980190963>.
Expected "http://www.example.com/contacts/980190963" to be === "http://www.example.com/en/contacts/980190963".

Expected behavior

When I add RoutingFilter.active = false to test_helper.rb all generated controller or route tests are passing.

or:

Add description in the README, how to use this gem with recommended way to setting the locale from URL params.

Actual behavior

In generated *ContactsControllerTest < ActionDispatch::IntegrationTest all assertions like assert_redirected_to contact_url(Contact.last) or assert_redirected_to contacts_url will fail.

Workaround

I find out, that instead of adding RoutingFilter.active = false to test_helper.rb I had to add RoutingFilter::Locale.include_default_locale = false.