Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Tests fixed: required gems/libs + clean routes on setup

  • Loading branch information...
commit 53210b040e32d55f31be210bfd501b836b6b6961 1 parent c24bddf
@raul authored
Showing with 40 additions and 39 deletions.
  1. +40 −39 test/translate_routes_test.rb
View
79 test/translate_routes_test.rb
@@ -1,10 +1,8 @@
require 'test/unit'
require 'rubygems'
-%w(actionpack activesupport actionmailer).each{ |gem_lib| gem gem_lib, '2.2.2' }
-%w( activesupport actionpack actionmailer action_controller action_controller/test_case
- action_controller/test_process action_controller/assertions
- ).each{ |lib| require lib }
+%w(actionpack activesupport actionmailer).each{ |gem_lib| gem gem_lib, '2.3.2' }
+%w(activesupport actionpack actionmailer action_controller).each{ |lib| require lib }
plugin_root = File.join(File.dirname(__FILE__), '..')
require "#{plugin_root}/lib/translate_routes"
@@ -12,11 +10,14 @@
class PeopleController < ActionController::Base; end
-class TranslateRoutesTest < Test::Unit::TestCase
+class TranslateRoutesTest < ActionController::TestCase
+
+ include ActionController::Assertions::RoutingAssertions
def setup
@controller = ActionController::Base.new
@view = ActionView::Base.new
+ ActionController::Routing::Routes.clear!
end
@@ -30,12 +31,12 @@ def test_unnamed_empty_route_with_prefix
assert_routing '/es', :controller => 'people', :action => 'index', :locale => 'es'
assert_routing '/en', :controller => 'people', :action => 'index', :locale => 'en'
end
-
+
def test_unnamed_root_route_with_prefix
ActionController::Routing::Routes.draw { |map| map.connect '/', :controller => 'people', :action => 'index'}
config_default_locale_settings('es', true)
ActionController::Routing::Translator.translate_from_file 'test', 'locales', 'routes.yml'
-
+
assert_routing '/', :controller => 'people', :action => 'index'
assert_routing '/es', :controller => 'people', :action => 'index', :locale => 'es'
assert_routing '/en', :controller => 'people', :action => 'index', :locale => 'en'
@@ -57,7 +58,7 @@ def test_unnamed_translated_route_on_default_locale_with_prefix
assert_routing '/es/gente', :controller => 'people', :action => 'index', :locale => 'es'
end
-
+
def test_unnamed_translated_route_on_non_default_locale_with_prefix
ActionController::Routing::Routes.draw { |map| map.connect 'people', :controller => 'people', :action => 'index' }
config_default_locale_settings('en', true)
@@ -66,10 +67,10 @@ def test_unnamed_translated_route_on_non_default_locale_with_prefix
assert_routing '/es/gente', :controller => 'people', :action => 'index', :locale => 'es'
assert_routing '/en/people', :controller => 'people', :action => 'index', :locale => 'en'
end
-
-
+
+
# Unnamed routes without prefix on default locale:
-
+
def test_unnamed_empty_route_without_prefix
ActionController::Routing::Routes.draw { |map| map.connect '', :controller => 'people', :action => 'index' }
config_default_locale_settings('en', false)
@@ -78,12 +79,12 @@ def test_unnamed_empty_route_without_prefix
assert_routing '/es', :controller => 'people', :action => 'index', :locale => 'es'
assert_routing '/', :controller => 'people', :action => 'index', :locale => 'en'
end
-
+
def test_unnamed_root_route_without_prefix
ActionController::Routing::Routes.draw { |map| map.connect '/', :controller => 'people', :action => 'index'}
config_default_locale_settings('es', false)
ActionController::Routing::Translator.translate_from_file 'test', 'locales', 'routes.yml'
-
+
assert_routing '/', :controller => 'people', :action => 'index', :locale => 'es'
assert_routing '/en', :controller => 'people', :action => 'index', :locale => 'en'
assert_unrecognized_route '/es', :controller => 'people', :action => 'index', :locale => 'es'
@@ -102,38 +103,38 @@ def test_unnamed_translated_route_on_default_locale_without_prefix
ActionController::Routing::Routes.draw { |map| map.people 'people', :controller => 'people', :action => 'index'}
config_default_locale_settings('es', false)
ActionController::Routing::Translator.translate { |t| t['en'] = {}; t['es'] = {'people' => 'gente'} }
-
+
assert_routing '/en/people', :controller => 'people', :action => 'index', :locale => 'en'
assert_routing 'gente', :controller => 'people', :action => 'index', :locale => 'es'
end
-
+
def test_unnamed_translated_route_on_non_default_locale_without_prefix
ActionController::Routing::Routes.draw { |map| map.people 'people', :controller => 'people', :action => 'index'}
config_default_locale_settings('en', false)
ActionController::Routing::Translator.translate { |t| t['en'] = {}; t['es'] = {'people' => 'gente'} }
-
+
assert_routing '/es/gente', :controller => 'people', :action => 'index', :locale => 'es'
assert_routing '/people', :controller => 'people', :action => 'index', :locale => 'en'
end
-
-
+
+
# Named routes with prefix on default locale:
-
+
def test_named_empty_route_with_prefix
ActionController::Routing::Routes.draw { |map| map.people '', :controller => 'people', :action => 'index' }
config_default_locale_settings('en', true)
ActionController::Routing::Translator.translate { |t| t['en'] = {}; t['es'] = {'people' => 'gente'} }
-
+
assert_routing '/es', :controller => 'people', :action => 'index', :locale => 'es'
assert_routing '/en', :controller => 'people', :action => 'index', :locale => 'en'
assert_helpers_include :people_en, :people_es, :people
end
-
+
def test_named_root_route_with_prefix
ActionController::Routing::Routes.draw { |map| map.root :controller => 'people', :action => 'index'}
config_default_locale_settings('es', true)
ActionController::Routing::Translator.translate_from_file 'test', 'locales', 'routes.yml'
-
+
assert_routing '/', :controller => 'people', :action => 'index'
assert_routing '/es', :controller => 'people', :action => 'index', :locale => 'es'
assert_routing '/en', :controller => 'people', :action => 'index', :locale => 'en'
@@ -153,12 +154,12 @@ def test_named_translated_route_on_default_locale_with_prefix
ActionController::Routing::Routes.draw { |map| map.people 'people', :controller => 'people', :action => 'index'}
config_default_locale_settings('es', true)
ActionController::Routing::Translator.translate { |t| t['en'] = {}; t['es'] = {'people' => 'gente'} }
-
+
assert_routing '/en/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
-
+
def test_named_translated_route_on_non_default_locale_with_prefix
ActionController::Routing::Routes.draw { |map| map.people 'people', :controller => 'people', :action => 'index' }
config_default_locale_settings('en', true)
@@ -170,32 +171,32 @@ def test_named_translated_route_on_non_default_locale_with_prefix
end
# Named routes without prefix on default locale:
-
+
def test_named_empty_route_without_prefix
ActionController::Routing::Routes.draw { |map| map.people '', :controller => 'people', :action => 'index'}
config_default_locale_settings('es', false)
ActionController::Routing::Translator.translate { |t| t['es'] = {}; t['en'] = {'people' => 'gente'}; }
-
+
assert_routing '/en', :controller => 'people', :action => 'index', :locale => 'en'
assert_routing '/', :controller => 'people', :action => 'index', :locale => 'es'
assert_routing '', :controller => 'people', :action => 'index', :locale => 'es'
end
-
+
def test_named_root_route_without_prefix
ActionController::Routing::Routes.draw { |map| map.root :controller => 'people', :action => 'index'}
config_default_locale_settings('es', false)
ActionController::Routing::Translator.translate_from_file 'test', 'locales', 'routes.yml'
-
+
assert_routing '/', :controller => 'people', :action => 'index', :locale => 'es'
assert_routing '/en', :controller => 'people', :action => 'index', :locale => 'en'
assert_unrecognized_route '/es', :controller => 'people', :action => 'index', :locale => 'es'
end
-
+
def test_named_untranslated_route_without_prefix
ActionController::Routing::Routes.draw { |map| map.people 'foo', :controller => 'people', :action => 'index'}
config_default_locale_settings('es', false)
ActionController::Routing::Translator.translate { |t| t['en'] = {}; t['es'] = {'people' => 'gente'} }
-
+
assert_routing '/en/foo', :controller => 'people', :action => 'index', :locale => 'en'
assert_routing 'foo', :controller => 'people', :action => 'index', :locale => 'es'
assert_helpers_include :people_en, :people_es, :people
@@ -210,7 +211,7 @@ def test_named_translated_route_on_default_locale_without_prefix
assert_routing 'gente', :controller => 'people', :action => 'index', :locale => 'es'
assert_helpers_include :people_en, :people_es, :people
end
-
+
def test_named_translated_route_on_non_default_locale_without_prefix
ActionController::Routing::Routes.draw { |map| map.people 'people', :controller => 'people', :action => 'index'}
config_default_locale_settings('en', false)
@@ -220,7 +221,7 @@ def test_named_translated_route_on_non_default_locale_without_prefix
assert_routing '/es/gente', :controller => 'people', :action => 'index', :locale => 'es'
assert_helpers_include :people_en, :people_es, :people
end
-
+
def test_languages_load_from_file
ActionController::Routing::Routes.draw { |map| map.people 'people', :controller => 'people', :action => 'index'}
config_default_locale_settings('en', false)
@@ -241,39 +242,39 @@ def test_languages_load_from_file_without_dictionary_for_default_locale
assert_routing '/es/gente', :controller => 'people', :action => 'index', :locale => 'es'
assert_helpers_include :people_fr, :people_en, :people_es, :people
end
-
+
def test_i18n_based_translations_setting_locales
ActionController::Routing::Routes.draw { |map| map.people 'people', :controller => 'people', :action => 'index'}
config_default_locale_settings('en', false)
I18n.backend = StubbedI18nBackend
ActionController::Routing::Translator.i18n('es')
-
+
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
-
+
def test_i18n_based_translations_taking_i18n_available_locales
ActionController::Routing::Routes.draw { |map| map.people 'people', :controller => 'people', :action => 'index'}
config_default_locale_settings('en', false)
I18n.stubs(:available_locales).at_least_once.returns StubbedI18nBackend.available_locales
I18n.backend = StubbedI18nBackend
ActionController::Routing::Translator.i18n
-
+
assert_routing '/people', :controller => 'people', :action => 'index', :locale => 'en'
assert_routing '/fr/people', :controller => 'people', :action => 'index', :locale => 'fr'
assert_routing '/es/gente', :controller => 'people', :action => 'index', :locale => 'es'
assert_helpers_include :people_fr, :people_en, :people_es, :people
end
-
+
def test_action_controller_gets_locale_setter
ActionController::Base.instance_methods.include?('set_locale_from_url')
end
-
+
def test_action_controller_gets_locale_suffix_helper
ActionController::Base.instance_methods.include?('locale_suffix')
end
-
+
def test_action_view_gets_locale_suffix_helper
ActionView::Base.instance_methods.include?('locale_suffix')
end
Please sign in to comment.
Something went wrong with that request. Please try again.