Skip to content

Commit

Permalink
Add a test case to detect side effects of localized blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
gi-lunaweb committed Nov 8, 2014
1 parent ae66311 commit b23cf21
Showing 1 changed file with 20 additions and 23 deletions.
43 changes: 20 additions & 23 deletions test/routing_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ def teardown
end

def test_unnamed_root_route
config_default_locale_settings 'en'
draw_routes do
localized do
root :to => 'people#index'
Expand Down Expand Up @@ -140,8 +139,6 @@ def test_unnamed_root_route_without_prefix
end

def test_unnamed_untranslated_route
config_default_locale_settings 'en'

draw_routes do
localized do
get 'foo', :to => 'people#index'
Expand All @@ -168,7 +165,6 @@ def test_unnamed_translated_route_on_default_locale
end

def test_unnamed_translated_route_on_non_default_locale
config_default_locale_settings 'en'
draw_routes do
localized do
get 'people', :to => 'people#index'
Expand All @@ -180,8 +176,6 @@ def test_unnamed_translated_route_on_non_default_locale
end

def test_named_translated_route_with_prefix_must_have_locale_as_static_segment
config_default_locale_settings 'en'

draw_routes do
localized do
get 'people', :to => 'people#index'
Expand Down Expand Up @@ -258,12 +252,9 @@ def test_named_translated_route_on_non_default_locale_without_prefix
end
end

config_default_locale_settings 'en'

assert_routing '/people', :controller => 'people', :action => 'index', :locale => 'en'
assert_routing '/es/gente', :controller => 'people', :action => 'index', :locale => 'es'


assert_helpers_include :people_en, :people_es, :people
end

Expand Down Expand Up @@ -308,8 +299,6 @@ def test_route_with_optional_format
end

def test_i18n_based_translations_setting_locales
config_default_locale_settings 'en'

draw_routes do
localized do
get 'people', :to => 'people#index', :as => 'people'
Expand All @@ -325,8 +314,6 @@ def test_i18n_based_translations_setting_locales

def test_translations_depend_on_available_locales
available_locales = I18n.available_locales
config_default_locale_settings 'en'

begin
I18n.available_locales = [:es, :en, :fr]

Expand Down Expand Up @@ -375,8 +362,6 @@ def test_not_localizing_routes_outside_blocks
end

def test_force_locale
I18n.locale = 'en'
config_default_locale_settings 'en'
config_force_locale true

draw_routes do
Expand All @@ -395,8 +380,6 @@ def test_force_locale
end

def test_generate_unlocalized_routes
I18n.locale = 'en'
config_default_locale_settings 'en'
config_generate_unlocalized_routes true

draw_routes do
Expand All @@ -415,8 +398,6 @@ def test_generate_unlocalized_routes
end

def test_generate_unnamed_unlocalized_routes
I18n.locale = 'en'
config_default_locale_settings 'en'
config_generate_unnamed_unlocalized_routes true

draw_routes do
Expand All @@ -436,9 +417,6 @@ def test_generate_unnamed_unlocalized_routes
end

def test_blank_localized_routes
I18n.locale = 'en'
config_default_locale_settings 'en'

draw_routes do
localized do
get 'people/blank', :to => 'people#index', :as => 'people'
Expand Down Expand Up @@ -490,7 +468,6 @@ def test_dont_add_locale_to_routes_if_local_param_present
end

def test_config_hide_locale
config_default_locale_settings 'en'
config_hide_locale true

draw_routes do
Expand Down Expand Up @@ -533,6 +510,26 @@ def test_action_controller_gets_locale_suffix_helper
def test_action_view_gets_locale_suffix_helper
ActionView::Base.instance_methods.include?('locale_suffix')
end

# See https://github.com/enriclluelles/route_translator/issues/69
def test_no_side_effects
draw_routes do
localized do
resources :people
end

scope "(:locale)", :locale => /(en|es)/ do
get '*id' => 'products#show', :as => 'product'
end
end

assert_routing '/es/gente', :controller => 'people', :action => 'index', :locale => 'es'
assert_routing '/people', :controller => 'people', :action => 'index', :locale => 'en'

assert_routing '/es/path/to/a/product', :controller => 'products', :action => 'show', :locale => 'es', :id => 'path/to/a/product'
assert_routing '/path/to/another/product', :controller => 'products', :action => 'show', :id => 'path/to/another/product'
end

end

class ProductsControllerTest < ActionController::TestCase
Expand Down

0 comments on commit b23cf21

Please sign in to comment.