No route matches in controller tests
jaclync opened this issue · 3 comments
Hello, similar to #71 , I encountered test failures on controllers inside localized
without specifying locale
in params
:
ActionController::UrlGenerationError: No route matches {:action=>"index", :controller=>"welcome"}
After I added locale
param in those failing tests, then tests passed. Though it would be convenient if the default locale could be passed by default? From previous discussion, this seems to have been the behavior, maybe something has changed or regression?
(Using version 5.6.4
)
Hi,
could you please provide a failing test?
Yep, forgot to mention I am also using devise
.
Example failing test: (it passed after adding params: { locale: 'en' }
in the request)
require 'test_helper'
class ExploreTripsControllerTest < ActionController::TestCase
include Devise::Test::ControllerHelpers
test "should get index" do
get :index
assert_response :success
end
end
routes:
localized do
get 'explore_trips/index'
...
end
rake routes:
explore_trips_index_zh_tw GET /zh-tw/explore_trips/index(.:format) explore_trips#index {:locale=>"zh-TW"}
explore_trips_index_en GET /explore_trips/index(.:format) explore_trips#index {:locale=>"en"}
Any insight is appreciated!
Ok, thanks
The locale parameter is mandatory. This is also covered in the README:
https://github.com/enriclluelles/route_translator#testing
Testing your controllers with routes-translator is easy, just add a locale parameter for your localized routes. Otherwise, an ActionController::UrlGenerationError will raise.
Hope it helps
Closing here