route_translator 3.1.0 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +15 -0
- data/lib/route_translator.rb +3 -1
- data/lib/route_translator/extensions/action_controller.rb +10 -3
- data/lib/route_translator/extensions/mapper.rb +2 -3
- data/lib/route_translator/extensions/route_set.rb +1 -1
- data/lib/route_translator/translator.rb +35 -14
- data/lib/route_translator/version.rb +1 -1
- data/test/dummy/config/application.rb +1 -0
- data/test/dummy/config/routes.rb +1 -1
- data/test/dummy/dummy_mounted_app.rb +3 -4
- data/test/integration_test.rb +9 -0
- data/test/locales/routes.yml +1 -0
- data/test/routing_test.rb +131 -9
- data/test/test_helper.rb +10 -3
- metadata +20 -12
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,15 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            !binary "U0hBMQ==":
         | 
| 3 | 
            +
              metadata.gz: !binary |-
         | 
| 4 | 
            +
                MmZkNDU4NGVlZjk3YWQ5ZmNmYjlmNTZiNjczNzcxODNmYzIxNTNiZQ==
         | 
| 5 | 
            +
              data.tar.gz: !binary |-
         | 
| 6 | 
            +
                MGFlZTZiYWVkZWFkZTU0YzdjZjlmYjRkM2U5NTFjODI4NWVjYzljZA==
         | 
| 7 | 
            +
            SHA512:
         | 
| 8 | 
            +
              metadata.gz: !binary |-
         | 
| 9 | 
            +
                MmM4ZTQwNzZhMmIxNjM2NzA5NGY2YTMyMjkzOTZjZWI0M2FkY2I1MjEyMGNl
         | 
| 10 | 
            +
                OTAxYjMyOTBmNjY2ZDQ4YmZmYzE2ZWU4YjZkZWUwOTM0YWFmZTkzMzI2MTQ4
         | 
| 11 | 
            +
                NGI5MmFjMmRjNmMyYjU0YjkyYjM5NDAzNmM0MjI5MGJhYjMyYzY=
         | 
| 12 | 
            +
              data.tar.gz: !binary |-
         | 
| 13 | 
            +
                MjkyZjZlODExMTFhZThiZGY0NWE2M2YzZjllZWVlOTViYjg5MzAxZTYwOGUy
         | 
| 14 | 
            +
                MTAxNTkzODI0ZDkzODQ5Mjg0OThhYWYzZGMwNWQ5ZDNkOGNhNmQ1OWY5NzY3
         | 
| 15 | 
            +
                OGVkMjA5ZjBkOTU0MmE1YzI0YzBiZmFiNzE4ZDQwYmY4OTI2NzE=
         | 
    
        data/lib/route_translator.rb
    CHANGED
    
    | @@ -10,13 +10,15 @@ module RouteTranslator | |
| 10 10 |  | 
| 11 11 | 
             
              TRANSLATABLE_SEGMENT = /^([-_a-zA-Z0-9]+)(\()?/.freeze
         | 
| 12 12 |  | 
| 13 | 
            -
              Configuration = Struct.new(:force_locale, :generate_unlocalized_routes, : | 
| 13 | 
            +
              Configuration = Struct.new(:force_locale, :hide_locale, :generate_unlocalized_routes, :locale_param_key, :generate_unnamed_unlocalized_routes)
         | 
| 14 14 |  | 
| 15 15 | 
             
              def self.config(&block)
         | 
| 16 16 | 
             
                @config ||= Configuration.new
         | 
| 17 17 | 
             
                @config.force_locale ||= false
         | 
| 18 | 
            +
                @config.hide_locale ||= false
         | 
| 18 19 | 
             
                @config.generate_unlocalized_routes ||= false
         | 
| 19 20 | 
             
                @config.locale_param_key ||= :locale
         | 
| 21 | 
            +
                @config.generate_unnamed_unlocalized_routes ||= false
         | 
| 20 22 | 
             
                yield @config if block
         | 
| 21 23 | 
             
                @config
         | 
| 22 24 | 
             
              end
         | 
| @@ -2,10 +2,17 @@ require 'action_controller' | |
| 2 2 |  | 
| 3 3 | 
             
            module ActionController
         | 
| 4 4 | 
             
              class Base
         | 
| 5 | 
            -
                 | 
| 5 | 
            +
                around_filter :set_locale_from_url
         | 
| 6 6 |  | 
| 7 | 
            -
                def set_locale_from_url
         | 
| 8 | 
            -
                  I18n. | 
| 7 | 
            +
                def set_locale_from_url(&block)
         | 
| 8 | 
            +
                  I18n.with_locale params[RouteTranslator.locale_param_key], &block
         | 
| 9 9 | 
             
                end
         | 
| 10 10 | 
             
              end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
              class TestCase
         | 
| 13 | 
            +
                include ActionController::UrlFor
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                delegate :env, :request, :to => :@controller
         | 
| 16 | 
            +
                def _routes; @routes; end
         | 
| 17 | 
            +
              end
         | 
| 11 18 | 
             
            end
         | 
| @@ -26,11 +26,10 @@ module ActionDispatch | |
| 26 26 | 
             
                      end
         | 
| 27 27 |  | 
| 28 28 | 
             
                      mapping = Mapping.new(@set, @scope, path, options)
         | 
| 29 | 
            -
                      app, conditions, requirements, defaults, as, anchor = mapping.to_route
         | 
| 30 29 | 
             
                      if @localized
         | 
| 31 | 
            -
                        @set.add_localized_route( | 
| 30 | 
            +
                        @set.add_localized_route(*mapping.to_route)
         | 
| 32 31 | 
             
                      else
         | 
| 33 | 
            -
                        @set.add_route( | 
| 32 | 
            +
                        @set.add_route(*mapping.to_route)
         | 
| 34 33 | 
             
                      end
         | 
| 35 34 | 
             
                    end
         | 
| 36 35 | 
             
                  else
         | 
| @@ -17,12 +17,23 @@ module RouteTranslator | |
| 17 17 | 
             
                        __send__("#{old_name}_#{I18n.default_locale.to_s.underscore}_#{suffix}", *args)
         | 
| 18 18 | 
             
                      end
         | 
| 19 19 | 
             
                    end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                    # Including the named routes helpers module
         | 
| 22 | 
            +
                    [ActionController::TestCase, ActionView::TestCase, ActionMailer::TestCase].each do |klass|
         | 
| 23 | 
            +
                      klass.__send__(:include, helper_container)
         | 
| 24 | 
            +
                    end
         | 
| 20 25 | 
             
                  end
         | 
| 21 26 | 
             
                end
         | 
| 22 27 |  | 
| 23 28 | 
             
                def self.translations_for(app, conditions, requirements, defaults, route_name, anchor, route_set, &block)
         | 
| 24 29 | 
             
                  add_untranslated_helpers_to_controllers_and_views(route_name, route_set.named_routes.module)
         | 
| 25 | 
            -
                   | 
| 30 | 
            +
                  # Make sure the default locale is translated in last place to avoid
         | 
| 31 | 
            +
                  # problems with wildcards when default locale is omitted in paths. The
         | 
| 32 | 
            +
                  # default routes will catch all paths like wildcard if it is translated first
         | 
| 33 | 
            +
                  available_locales = I18n.available_locales.dup
         | 
| 34 | 
            +
                  available_locales.delete I18n.default_locale
         | 
| 35 | 
            +
                  available_locales.push I18n.default_locale
         | 
| 36 | 
            +
                  available_locales.each do |locale|
         | 
| 26 37 | 
             
                    new_conditions = conditions.dup
         | 
| 27 38 | 
             
                    new_conditions[:path_info] = translate_path(conditions[:path_info], locale)
         | 
| 28 39 | 
             
                    if new_conditions[:required_defaults] && !new_conditions[:required_defaults].include?(RouteTranslator.locale_param_key)
         | 
| @@ -34,25 +45,30 @@ module RouteTranslator | |
| 34 45 | 
             
                    new_route_name = nil if new_route_name && route_set.named_routes.routes[new_route_name.to_sym] #TODO: Investigate this :(
         | 
| 35 46 | 
             
                    block.call(app, new_conditions, new_requirements, new_defaults, new_route_name, anchor)
         | 
| 36 47 | 
             
                  end
         | 
| 37 | 
            -
                   | 
| 48 | 
            +
                  if RouteTranslator.config.generate_unnamed_unlocalized_routes
         | 
| 49 | 
            +
                    block.call(app, conditions, requirements, defaults, nil, anchor)
         | 
| 50 | 
            +
                  elsif RouteTranslator.config.generate_unlocalized_routes
         | 
| 51 | 
            +
                    block.call(app, conditions, requirements, defaults, route_name, anchor)
         | 
| 52 | 
            +
                  end
         | 
| 38 53 | 
             
                end
         | 
| 39 54 |  | 
| 40 55 | 
             
                # Translates a path and adds the locale prefix.
         | 
| 41 56 | 
             
                def self.translate_path(path, locale)
         | 
| 42 57 | 
             
                  new_path = path.dup
         | 
| 43 | 
            -
                  final_optional_segments = new_path.slice!(/(\( | 
| 44 | 
            -
                   | 
| 58 | 
            +
                  final_optional_segments = new_path.slice!(/(\([^\/]+\))$/)
         | 
| 59 | 
            +
                  translated_segments = new_path.split("/").map{ |seg| translate_path_segment(seg, locale) }.select{ |seg| !seg.blank? }
         | 
| 45 60 |  | 
| 46 | 
            -
                  #  | 
| 61 | 
            +
                  # if not hiding locale then
         | 
| 62 | 
            +
                  # add locale prefix if it's not the default locale,
         | 
| 47 63 | 
             
                  # or forcing locale to all routes,
         | 
| 48 64 | 
             
                  # or already generating actual unlocalized routes
         | 
| 49 | 
            -
                  if !default_locale?(locale) || RouteTranslator.config.force_locale || RouteTranslator.config.generate_unlocalized_routes
         | 
| 50 | 
            -
                     | 
| 65 | 
            +
                  if !RouteTranslator.config.hide_locale && (!default_locale?(locale) || RouteTranslator.config.force_locale || RouteTranslator.config.generate_unlocalized_routes || RouteTranslator.config.generate_unnamed_unlocalized_routes)
         | 
| 66 | 
            +
                    if !locale_param_present?(new_path)
         | 
| 67 | 
            +
                      translated_segments.unshift locale.to_s.downcase
         | 
| 68 | 
            +
                    end
         | 
| 51 69 | 
             
                  end
         | 
| 52 70 |  | 
| 53 | 
            -
                   | 
| 54 | 
            -
             | 
| 55 | 
            -
                  "#{new_path}#{final_optional_segments}"
         | 
| 71 | 
            +
                  "/#{translated_segments.join('/')}#{final_optional_segments}".gsub(/\/\(\//, '(/')
         | 
| 56 72 | 
             
                end
         | 
| 57 73 |  | 
| 58 74 | 
             
                def self.translate_name(n, locale)
         | 
| @@ -66,19 +82,24 @@ module RouteTranslator | |
| 66 82 | 
             
                # Tries to translate a single path segment. If the path segment
         | 
| 67 83 | 
             
                # contains sth. like a optional format "people(.:format)", only
         | 
| 68 84 | 
             
                # "people" will be translated, if there is no translation, the path
         | 
| 69 | 
            -
                # segment is blank  | 
| 70 | 
            -
                # is returned untouched
         | 
| 85 | 
            +
                # segment is blank, begins with a ":" (param key) or "*" (wildcard),
         | 
| 86 | 
            +
                # the segment is returned untouched
         | 
| 71 87 | 
             
                def self.translate_path_segment segment, locale
         | 
| 72 | 
            -
                  return segment if segment.blank? or segment.starts_with?(":")
         | 
| 88 | 
            +
                  return segment if segment.blank? or segment.starts_with?(":") or segment.starts_with?("(") or segment.starts_with?("*")
         | 
| 73 89 |  | 
| 90 | 
            +
                  appended_part = segment.slice!(/(\()$/)
         | 
| 74 91 | 
             
                  match = TRANSLATABLE_SEGMENT.match(segment)[1] rescue nil
         | 
| 75 92 |  | 
| 76 | 
            -
                  (translate_string(match, locale) || segment)
         | 
| 93 | 
            +
                  (translate_string(match, locale) || segment) + appended_part.to_s
         | 
| 77 94 | 
             
                end
         | 
| 78 95 |  | 
| 79 96 | 
             
                def self.translate_string(str, locale)
         | 
| 80 97 | 
             
                  res = I18n.translate(str, :scope => :routes, :locale => locale, :default => str)
         | 
| 81 98 | 
             
                  URI.escape(res)
         | 
| 82 99 | 
             
                end
         | 
| 100 | 
            +
             | 
| 101 | 
            +
                def self.locale_param_present?(path)
         | 
| 102 | 
            +
                  !(path.split('/').detect { |segment| segment.to_s == ":#{RouteTranslator.locale_param_key.to_s}" }.nil?)
         | 
| 103 | 
            +
                end
         | 
| 83 104 | 
             
              end
         | 
| 84 105 | 
             
            end
         | 
    
        data/test/dummy/config/routes.rb
    CHANGED
    
    
    
        data/test/integration_test.rb
    CHANGED
    
    | @@ -20,4 +20,13 @@ class IntegrationTest < class_to_inherit | |
| 20 20 | 
             
                assert_equal "Good", @response.body
         | 
| 21 21 | 
             
                assert_response :success
         | 
| 22 22 | 
             
              end
         | 
| 23 | 
            +
              
         | 
| 24 | 
            +
              def test_i18n_locale_thread_safe
         | 
| 25 | 
            +
                config_default_locale_settings 'en'
         | 
| 26 | 
            +
                
         | 
| 27 | 
            +
                get '/es/dummy'
         | 
| 28 | 
            +
                assert_equal 'es', @response.body
         | 
| 29 | 
            +
                
         | 
| 30 | 
            +
                assert_equal :en, I18n.locale
         | 
| 31 | 
            +
              end
         | 
| 23 32 | 
             
            end
         | 
    
        data/test/locales/routes.yml
    CHANGED
    
    
    
        data/test/routing_test.rb
    CHANGED
    
    | @@ -18,8 +18,10 @@ class TranslateRoutesTest < ActionController::TestCase | |
| 18 18 |  | 
| 19 19 | 
             
              def teardown
         | 
| 20 20 | 
             
                config_force_locale false
         | 
| 21 | 
            +
                config_hide_locale false
         | 
| 21 22 | 
             
                config_generate_unlocalized_routes false
         | 
| 22 23 | 
             
                config_default_locale_settings("en")
         | 
| 24 | 
            +
                config_generate_unnamed_unlocalized_routes false
         | 
| 23 25 | 
             
              end
         | 
| 24 26 |  | 
| 25 27 | 
             
              def test_unnamed_root_route
         | 
| @@ -55,6 +57,17 @@ class TranslateRoutesTest < ActionController::TestCase | |
| 55 57 | 
             
                assert_routing '/es/productos/a/b', :controller => 'products', :action => 'index', :locale => 'es', :non_optional_param => 'b', :optional_param => 'a'
         | 
| 56 58 | 
             
              end
         | 
| 57 59 |  | 
| 60 | 
            +
              def test_translations_after_optional_segments
         | 
| 61 | 
            +
                draw_routes do
         | 
| 62 | 
            +
                  localized do
         | 
| 63 | 
            +
                    get '(/:optional_param)/products', :to => 'products#index'
         | 
| 64 | 
            +
                  end
         | 
| 65 | 
            +
                end
         | 
| 66 | 
            +
             | 
| 67 | 
            +
                assert_routing '/es/productos', :controller => 'products', :action => 'index', :locale => 'es'
         | 
| 68 | 
            +
                assert_routing '/es/a/productos', :controller => 'products', :action => 'index', :locale => 'es', :optional_param => 'a'
         | 
| 69 | 
            +
              end
         | 
| 70 | 
            +
             | 
| 58 71 | 
             
              def test_dynamic_segments_dont_get_translated
         | 
| 59 72 | 
             
                draw_routes do
         | 
| 60 73 | 
             
                  localized do
         | 
| @@ -64,6 +77,15 @@ class TranslateRoutesTest < ActionController::TestCase | |
| 64 77 | 
             
                assert_routing '/es/productos/a', :controller => 'products', :action => 'index', :locale => 'es', :tr_param => 'a'
         | 
| 65 78 | 
             
              end
         | 
| 66 79 |  | 
| 80 | 
            +
              def test_wildcards_dont_get_translated
         | 
| 81 | 
            +
                draw_routes do
         | 
| 82 | 
            +
                  localized do
         | 
| 83 | 
            +
                    get 'products/*tr_param', :to => 'products#index'
         | 
| 84 | 
            +
                  end
         | 
| 85 | 
            +
                end
         | 
| 86 | 
            +
                assert_routing '/es/productos/a/b', :controller => 'products', :action => 'index', :locale => 'es', :tr_param => 'a/b'
         | 
| 87 | 
            +
              end
         | 
| 88 | 
            +
             | 
| 67 89 | 
             
              def test_resources
         | 
| 68 90 | 
             
                config_default_locale_settings 'es'
         | 
| 69 91 |  | 
| @@ -227,7 +249,7 @@ class TranslateRoutesTest < ActionController::TestCase | |
| 227 249 | 
             
                assert_routing '/en/people', :controller => 'people', :action => 'index', :locale => 'en'
         | 
| 228 250 | 
             
                assert_routing 'gente', :controller => 'people', :action => 'index', :locale => 'es'
         | 
| 229 251 |  | 
| 230 | 
            -
             | 
| 252 | 
            +
             | 
| 231 253 | 
             
                assert_helpers_include :people_en, :people_es, :people
         | 
| 232 254 | 
             
              end
         | 
| 233 255 |  | 
| @@ -243,7 +265,7 @@ class TranslateRoutesTest < ActionController::TestCase | |
| 243 265 | 
             
                assert_routing '/people', :controller => 'people', :action => 'index', :locale => 'en'
         | 
| 244 266 | 
             
                assert_routing '/es/gente', :controller => 'people', :action => 'index', :locale => 'es'
         | 
| 245 267 |  | 
| 246 | 
            -
             | 
| 268 | 
            +
             | 
| 247 269 | 
             
                assert_helpers_include :people_en, :people_es, :people
         | 
| 248 270 | 
             
              end
         | 
| 249 271 |  | 
| @@ -275,7 +297,7 @@ class TranslateRoutesTest < ActionController::TestCase | |
| 275 297 | 
             
                assert_routing '/es/gente', :controller => 'people', :action => 'index', :locale => 'es'
         | 
| 276 298 | 
             
                assert_routing '/people', :controller => 'people', :action => 'index', :locale => 'en'
         | 
| 277 299 |  | 
| 278 | 
            -
             | 
| 300 | 
            +
             | 
| 279 301 | 
             
                assert_helpers_include :people_en, :people_es, :people
         | 
| 280 302 | 
             
              end
         | 
| 281 303 |  | 
| @@ -326,6 +348,7 @@ class TranslateRoutesTest < ActionController::TestCase | |
| 326 348 | 
             
              end
         | 
| 327 349 |  | 
| 328 350 | 
             
              def test_force_locale
         | 
| 351 | 
            +
                I18n.locale = 'en'
         | 
| 329 352 | 
             
                config_default_locale_settings 'en'
         | 
| 330 353 | 
             
                config_force_locale true
         | 
| 331 354 |  | 
| @@ -337,9 +360,15 @@ class TranslateRoutesTest < ActionController::TestCase | |
| 337 360 |  | 
| 338 361 | 
             
                assert_routing '/en/people', :controller => 'people', :action => 'index', :locale => 'en'
         | 
| 339 362 | 
             
                assert_unrecognized_route '/people', :controller => 'people', :action => 'index'
         | 
| 363 | 
            +
                assert_equal '/en/people', @routes.url_helpers.people_en_path
         | 
| 364 | 
            +
                assert_equal '/en/people', @routes.url_helpers.people_path
         | 
| 365 | 
            +
                I18n.locale = 'es'
         | 
| 366 | 
            +
                # The dynamic route maps to the current locale
         | 
| 367 | 
            +
                assert_equal '/es/gente', @routes.url_helpers.people_path
         | 
| 340 368 | 
             
              end
         | 
| 341 369 |  | 
| 342 370 | 
             
              def test_generate_unlocalized_routes
         | 
| 371 | 
            +
                I18n.locale = 'en'
         | 
| 343 372 | 
             
                config_default_locale_settings 'en'
         | 
| 344 373 | 
             
                config_generate_unlocalized_routes true
         | 
| 345 374 |  | 
| @@ -351,22 +380,82 @@ class TranslateRoutesTest < ActionController::TestCase | |
| 351 380 |  | 
| 352 381 | 
             
                assert_routing '/en/people', :controller => 'people', :action => 'index', :locale => 'en'
         | 
| 353 382 | 
             
                assert_routing '/people', :controller => 'people', :action => 'index'
         | 
| 383 | 
            +
                assert_equal '/en/people', @routes.url_helpers.people_en_path
         | 
| 384 | 
            +
                assert_equal '/people', @routes.url_helpers.people_path
         | 
| 385 | 
            +
                I18n.locale = 'es'
         | 
| 386 | 
            +
                # The dynamic route maps to the default locale, not the current
         | 
| 387 | 
            +
                assert_equal '/people', @routes.url_helpers.people_path
         | 
| 354 388 | 
             
              end
         | 
| 355 389 |  | 
| 356 | 
            -
              def  | 
| 357 | 
            -
                 | 
| 390 | 
            +
              def test_generate_unnamed_unlocalized_routes
         | 
| 391 | 
            +
                I18n.locale = 'en'
         | 
| 392 | 
            +
                config_default_locale_settings 'en'
         | 
| 393 | 
            +
                config_generate_unnamed_unlocalized_routes true
         | 
| 358 394 |  | 
| 359 395 | 
             
                draw_routes do
         | 
| 360 396 | 
             
                  localized do
         | 
| 361 | 
            -
                     | 
| 397 | 
            +
                    get 'people', :to => 'people#index', :as => 'people'
         | 
| 362 398 | 
             
                  end
         | 
| 363 399 | 
             
                end
         | 
| 364 400 |  | 
| 365 | 
            -
                assert_routing '/', :controller => 'people', :action => 'index', :locale => ' | 
| 366 | 
            -
                assert_routing '/ | 
| 367 | 
            -
                 | 
| 401 | 
            +
                assert_routing '/en/people', :controller => 'people', :action => 'index', :locale => 'en'
         | 
| 402 | 
            +
                assert_routing '/people', :controller => 'people', :action => 'index'
         | 
| 403 | 
            +
                assert_equal '/en/people', @routes.url_helpers.people_en_path
         | 
| 404 | 
            +
                assert_equal '/en/people', @routes.url_helpers.people_path
         | 
| 405 | 
            +
             | 
| 406 | 
            +
                I18n.locale = 'es'
         | 
| 407 | 
            +
                # The dynamic route maps to the current locale
         | 
| 408 | 
            +
                assert_equal '/es/gente', @routes.url_helpers.people_path
         | 
| 409 | 
            +
              end
         | 
| 410 | 
            +
              
         | 
| 411 | 
            +
              def test_blank_localized_routes
         | 
| 412 | 
            +
                I18n.locale = 'en'
         | 
| 413 | 
            +
                config_default_locale_settings 'en'
         | 
| 414 | 
            +
             | 
| 415 | 
            +
                draw_routes do
         | 
| 416 | 
            +
                  localized do
         | 
| 417 | 
            +
                    get 'people/blank', :to => 'people#index', :as => 'people'
         | 
| 418 | 
            +
                  end
         | 
| 419 | 
            +
                end
         | 
| 420 | 
            +
                
         | 
| 421 | 
            +
                I18n.locale = 'en'
         | 
| 422 | 
            +
                assert_routing '/people/blank', :controller => 'people', :action => 'index', :locale => 'en'
         | 
| 423 | 
            +
                assert_equal '/people/blank', @routes.url_helpers.people_en_path
         | 
| 424 | 
            +
                
         | 
| 425 | 
            +
                I18n.locale = 'es'
         | 
| 426 | 
            +
                assert_routing '/es/gente', :controller => 'people', :action => 'index', :locale => 'es'
         | 
| 427 | 
            +
                assert_equal '/es/gente', @routes.url_helpers.people_es_path
         | 
| 428 | 
            +
              end
         | 
| 429 | 
            +
             | 
| 430 | 
            +
              def test_dont_add_locale_to_routes_if_local_param_present
         | 
| 431 | 
            +
                config_default_locale_settings 'es'
         | 
| 432 | 
            +
                config_force_locale true
         | 
| 433 | 
            +
             | 
| 434 | 
            +
                draw_routes do
         | 
| 435 | 
            +
                  scope 'segment/:locale' do
         | 
| 436 | 
            +
                    localized do
         | 
| 437 | 
            +
                      resources :products
         | 
| 438 | 
            +
                    end
         | 
| 439 | 
            +
                  end
         | 
| 440 | 
            +
                end
         | 
| 441 | 
            +
             | 
| 442 | 
            +
                assert_routing '/segment/es/productos/product_slug', :controller => 'products', :action => 'show', :locale => 'es', :id => 'product_slug'
         | 
| 443 | 
            +
                assert_routing '/segment/en/products/product_slug', :controller => 'products', :action => 'show', :locale => 'en', :id => 'product_slug'
         | 
| 368 444 | 
             
              end
         | 
| 369 445 |  | 
| 446 | 
            +
              def test_config_hide_locale
         | 
| 447 | 
            +
                config_default_locale_settings 'en'
         | 
| 448 | 
            +
                config_hide_locale true
         | 
| 449 | 
            +
             | 
| 450 | 
            +
                draw_routes do
         | 
| 451 | 
            +
                  localized do
         | 
| 452 | 
            +
                    resources :people
         | 
| 453 | 
            +
                  end
         | 
| 454 | 
            +
                end
         | 
| 455 | 
            +
             | 
| 456 | 
            +
                assert_routing '/gente', :controller => 'people', :action => 'index', :locale => 'es'
         | 
| 457 | 
            +
                assert_routing '/people', :controller => 'people', :action => 'index', :locale => 'en'
         | 
| 458 | 
            +
              end
         | 
| 370 459 |  | 
| 371 460 | 
             
              def test_action_controller_gets_locale_setter
         | 
| 372 461 | 
             
                ActionController::Base.instance_methods.include?('set_locale_from_url')
         | 
| @@ -379,4 +468,37 @@ class TranslateRoutesTest < ActionController::TestCase | |
| 379 468 | 
             
              def test_action_view_gets_locale_suffix_helper
         | 
| 380 469 | 
             
                ActionView::Base.instance_methods.include?('locale_suffix')
         | 
| 381 470 | 
             
              end
         | 
| 471 | 
            +
             | 
| 472 | 
            +
              def test_action_controller_test_case_reads_default_urls
         | 
| 473 | 
            +
                test_case_reads_default_urls(ActionController::TestCase)
         | 
| 474 | 
            +
              end
         | 
| 475 | 
            +
             | 
| 476 | 
            +
              def test_action_view_test_case_reads_default_urls
         | 
| 477 | 
            +
                test_case_reads_default_urls(ActionView::TestCase)
         | 
| 478 | 
            +
              end
         | 
| 479 | 
            +
             | 
| 480 | 
            +
              def test_action_mailer_test_case_reads_default_urls
         | 
| 481 | 
            +
                test_case_reads_default_urls(ActionMailer::TestCase)
         | 
| 482 | 
            +
              end
         | 
| 483 | 
            +
             | 
| 484 | 
            +
              private
         | 
| 485 | 
            +
              def test_case_reads_default_urls(klass)
         | 
| 486 | 
            +
                config_default_locale_settings 'en'
         | 
| 487 | 
            +
             | 
| 488 | 
            +
                draw_routes do
         | 
| 489 | 
            +
                  localized do
         | 
| 490 | 
            +
                    resources :person
         | 
| 491 | 
            +
                  end
         | 
| 492 | 
            +
                end
         | 
| 493 | 
            +
             | 
| 494 | 
            +
                test_case = klass.new(:respond_to?)
         | 
| 495 | 
            +
             | 
| 496 | 
            +
                # Not localized
         | 
| 497 | 
            +
                assert test_case.respond_to?(:people_path)
         | 
| 498 | 
            +
                assert test_case.respond_to?(:new_person_path)
         | 
| 499 | 
            +
             | 
| 500 | 
            +
                # Localized
         | 
| 501 | 
            +
                assert test_case.respond_to?(:people_en_path)
         | 
| 502 | 
            +
                assert test_case.respond_to?(:new_person_en_path)
         | 
| 503 | 
            +
              end
         | 
| 382 504 | 
             
            end
         | 
    
        data/test/test_helper.rb
    CHANGED
    
    | @@ -2,6 +2,9 @@ require 'test/unit' | |
| 2 2 | 
             
            require 'minitest/mock'
         | 
| 3 3 | 
             
            require 'minitest/unit'
         | 
| 4 4 |  | 
| 5 | 
            +
            require 'i18n'
         | 
| 6 | 
            +
            I18n.enforce_available_locales = true
         | 
| 7 | 
            +
             | 
| 5 8 | 
             
            require "rails"
         | 
| 6 9 | 
             
            require "action_controller/railtie"
         | 
| 7 10 |  | 
| @@ -24,7 +27,7 @@ module RouteTranslator | |
| 24 27 | 
             
                def draw_routes(&block)
         | 
| 25 28 | 
             
                  @routes.draw(&block)
         | 
| 26 29 | 
             
                  if @routes.respond_to?(:install_helpers)
         | 
| 27 | 
            -
                    @routes.install_helpers | 
| 30 | 
            +
                    @routes.install_helpers
         | 
| 28 31 | 
             
                  else
         | 
| 29 32 | 
             
                    ActionView::Base.send(:include, @routes.url_helpers)
         | 
| 30 33 | 
             
                    ActionController::Base.send(:include, @routes.url_helpers)
         | 
| @@ -39,12 +42,16 @@ module RouteTranslator | |
| 39 42 | 
             
                  RouteTranslator.config.force_locale = boolean
         | 
| 40 43 | 
             
                end
         | 
| 41 44 |  | 
| 45 | 
            +
                def config_hide_locale(boolean)
         | 
| 46 | 
            +
                  RouteTranslator.config.hide_locale = boolean
         | 
| 47 | 
            +
                end
         | 
| 48 | 
            +
             | 
| 42 49 | 
             
                def config_generate_unlocalized_routes(boolean)
         | 
| 43 50 | 
             
                  RouteTranslator.config.generate_unlocalized_routes = boolean
         | 
| 44 51 | 
             
                end
         | 
| 45 52 |  | 
| 46 | 
            -
                def  | 
| 47 | 
            -
                  RouteTranslator.config. | 
| 53 | 
            +
                def config_generate_unnamed_unlocalized_routes(boolean)
         | 
| 54 | 
            +
                  RouteTranslator.config.generate_unnamed_unlocalized_routes = boolean
         | 
| 48 55 | 
             
                end
         | 
| 49 56 |  | 
| 50 57 | 
             
                def path_string(route)
         | 
    
        metadata
    CHANGED
    
    | @@ -1,8 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: route_translator
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 3. | 
| 5 | 
            -
              prerelease: 
         | 
| 4 | 
            +
              version: 3.2.0
         | 
| 6 5 | 
             
            platform: ruby
         | 
| 7 6 | 
             
            authors:
         | 
| 8 7 | 
             
            - Raul Murciano
         | 
| @@ -10,12 +9,11 @@ authors: | |
| 10 9 | 
             
            autorequire: 
         | 
| 11 10 | 
             
            bindir: bin
         | 
| 12 11 | 
             
            cert_chain: []
         | 
| 13 | 
            -
            date:  | 
| 12 | 
            +
            date: 2014-03-13 00:00:00.000000000 Z
         | 
| 14 13 | 
             
            dependencies:
         | 
| 15 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 16 15 | 
             
              name: minitest
         | 
| 17 16 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 18 | 
            -
                none: false
         | 
| 19 17 | 
             
                requirements:
         | 
| 20 18 | 
             
                - - ~>
         | 
| 21 19 | 
             
                  - !ruby/object:Gem::Version
         | 
| @@ -23,15 +21,27 @@ dependencies: | |
| 23 21 | 
             
              type: :development
         | 
| 24 22 | 
             
              prerelease: false
         | 
| 25 23 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 26 | 
            -
                none: false
         | 
| 27 24 | 
             
                requirements:
         | 
| 28 25 | 
             
                - - ~>
         | 
| 29 26 | 
             
                  - !ruby/object:Gem::Version
         | 
| 30 27 | 
             
                    version: 4.7.0
         | 
| 31 28 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 32 | 
            -
              name:  | 
| 29 | 
            +
              name: pry
         | 
| 30 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 31 | 
            +
                requirements:
         | 
| 32 | 
            +
                - - ! '>='
         | 
| 33 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 34 | 
            +
                    version: '0'
         | 
| 35 | 
            +
              type: :development
         | 
| 36 | 
            +
              prerelease: false
         | 
| 37 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 38 | 
            +
                requirements:
         | 
| 39 | 
            +
                - - ! '>='
         | 
| 40 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 41 | 
            +
                    version: '0'
         | 
| 42 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 43 | 
            +
              name: pry-nav
         | 
| 33 44 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 34 | 
            -
                none: false
         | 
| 35 45 | 
             
                requirements:
         | 
| 36 46 | 
             
                - - ! '>='
         | 
| 37 47 | 
             
                  - !ruby/object:Gem::Version
         | 
| @@ -39,7 +49,6 @@ dependencies: | |
| 39 49 | 
             
              type: :development
         | 
| 40 50 | 
             
              prerelease: false
         | 
| 41 51 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 42 | 
            -
                none: false
         | 
| 43 52 | 
             
                requirements:
         | 
| 44 53 | 
             
                - - ! '>='
         | 
| 45 54 | 
             
                  - !ruby/object:Gem::Version
         | 
| @@ -75,27 +84,26 @@ files: | |
| 75 84 | 
             
            - test/test_helper.rb
         | 
| 76 85 | 
             
            homepage: http://github.com/enriclluelles/route_translator
         | 
| 77 86 | 
             
            licenses: []
         | 
| 87 | 
            +
            metadata: {}
         | 
| 78 88 | 
             
            post_install_message: 
         | 
| 79 89 | 
             
            rdoc_options: []
         | 
| 80 90 | 
             
            require_paths:
         | 
| 81 91 | 
             
            - lib
         | 
| 82 92 | 
             
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 83 | 
            -
              none: false
         | 
| 84 93 | 
             
              requirements:
         | 
| 85 94 | 
             
              - - ! '>='
         | 
| 86 95 | 
             
                - !ruby/object:Gem::Version
         | 
| 87 96 | 
             
                  version: '0'
         | 
| 88 97 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 89 | 
            -
              none: false
         | 
| 90 98 | 
             
              requirements:
         | 
| 91 99 | 
             
              - - ! '>='
         | 
| 92 100 | 
             
                - !ruby/object:Gem::Version
         | 
| 93 101 | 
             
                  version: '0'
         | 
| 94 102 | 
             
            requirements: []
         | 
| 95 103 | 
             
            rubyforge_project: 
         | 
| 96 | 
            -
            rubygems_version:  | 
| 104 | 
            +
            rubygems_version: 2.2.2
         | 
| 97 105 | 
             
            signing_key: 
         | 
| 98 | 
            -
            specification_version:  | 
| 106 | 
            +
            specification_version: 4
         | 
| 99 107 | 
             
            summary: Translate your Rails routes in a simple manner
         | 
| 100 108 | 
             
            test_files:
         | 
| 101 109 | 
             
            - test/dummy/app/controllers/dummy_controller.rb
         |