route_translator 3.2.1 → 3.2.2
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 +4 -4
- data/lib/route_translator/translator.rb +4 -6
- data/lib/route_translator/version.rb +1 -1
- data/test/routing_test.rb +28 -20
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2978c69c256242672228bd99538e631a12446cef
|
4
|
+
data.tar.gz: 2fcb536aa8f1ce290696dd3a3e8f44cd84deb8c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f29d2badba785d4a7dbae525d908b6440a99e77c8ea900ab99eb354898075ae4b131b96a350dde15557f224cf1e9b0a976b33a4880287f0b9480883cc1b39ccf
|
7
|
+
data.tar.gz: cd7d39f3ab0ca1fdaa108803fcde30e7d87afefdfccb09a097b90f8cbe889fc9ecd3cc2c2b378e8896a3cb07bd2ad8378da4283205b20d43213dd8cbed41515b
|
@@ -5,10 +5,12 @@ module RouteTranslator
|
|
5
5
|
# people_path -> people_de_path
|
6
6
|
# I18n.locale = :fr
|
7
7
|
# people_path -> people_fr_path
|
8
|
-
def self.add_untranslated_helpers_to_controllers_and_views(old_name, helper_container)
|
8
|
+
def self.add_untranslated_helpers_to_controllers_and_views(old_name, helper_container, helper_list)
|
9
9
|
['path', 'url'].each do |suffix|
|
10
10
|
new_helper_name = "#{old_name}_#{suffix}"
|
11
11
|
|
12
|
+
helper_list.push(new_helper_name.to_sym) unless helper_list.include?(new_helper_name.to_sym)
|
13
|
+
|
12
14
|
helper_container.__send__(:define_method, new_helper_name) do |*args|
|
13
15
|
locale_suffix = I18n.locale.to_s.underscore
|
14
16
|
if respond_to?("#{old_name}_#{locale_suffix}_#{suffix}")
|
@@ -18,15 +20,11 @@ module RouteTranslator
|
|
18
20
|
end
|
19
21
|
end
|
20
22
|
|
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
|
25
23
|
end
|
26
24
|
end
|
27
25
|
|
28
26
|
def self.translations_for(app, conditions, requirements, defaults, route_name, anchor, route_set, &block)
|
29
|
-
add_untranslated_helpers_to_controllers_and_views(route_name, route_set.named_routes.module)
|
27
|
+
add_untranslated_helpers_to_controllers_and_views(route_name, route_set.named_routes.module, route_set.named_routes.helpers)
|
30
28
|
# Make sure the default locale is translated in last place to avoid
|
31
29
|
# problems with wildcards when default locale is omitted in paths. The
|
32
30
|
# default routes will catch all paths like wildcard if it is translated first
|
data/test/routing_test.rb
CHANGED
@@ -468,37 +468,45 @@ class TranslateRoutesTest < ActionController::TestCase
|
|
468
468
|
def test_action_view_gets_locale_suffix_helper
|
469
469
|
ActionView::Base.instance_methods.include?('locale_suffix')
|
470
470
|
end
|
471
|
+
end
|
471
472
|
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
def test_action_view_test_case_reads_default_urls
|
477
|
-
test_case_reads_default_urls(ActionView::TestCase)
|
478
|
-
end
|
473
|
+
class ProductsControllerTest < ActionController::TestCase
|
474
|
+
include ActionDispatch::Assertions::RoutingAssertions
|
475
|
+
include RouteTranslator::TestHelper
|
479
476
|
|
480
|
-
def
|
481
|
-
|
482
|
-
|
477
|
+
def setup
|
478
|
+
@routes = ActionDispatch::Routing::RouteSet.new
|
479
|
+
I18n.backend = I18n::Backend::Simple.new
|
480
|
+
I18n.load_path = [ File.expand_path('../locales/routes.yml', __FILE__) ]
|
481
|
+
I18n.reload!
|
483
482
|
|
484
|
-
private
|
485
|
-
def test_case_reads_default_urls(klass)
|
486
483
|
config_default_locale_settings 'en'
|
487
484
|
|
488
485
|
draw_routes do
|
489
486
|
localized do
|
490
|
-
resources :
|
487
|
+
resources :products
|
491
488
|
end
|
492
489
|
end
|
490
|
+
end
|
493
491
|
|
494
|
-
|
492
|
+
def teardown
|
493
|
+
config_force_locale false
|
494
|
+
config_hide_locale false
|
495
|
+
config_generate_unlocalized_routes false
|
496
|
+
config_default_locale_settings("en")
|
497
|
+
config_generate_unnamed_unlocalized_routes false
|
498
|
+
end
|
495
499
|
|
496
|
-
|
497
|
-
assert test_case.respond_to?(:people_path)
|
498
|
-
assert test_case.respond_to?(:new_person_path)
|
500
|
+
def test_url_helpers_are_included
|
499
501
|
|
500
|
-
#
|
501
|
-
|
502
|
-
|
502
|
+
#doing it this way because assert_nothing_raised doesn't work on all rails versions
|
503
|
+
%w(product_path product_url product_es_path product_es_url).each do |method|
|
504
|
+
begin
|
505
|
+
send(method)
|
506
|
+
rescue Exception => e
|
507
|
+
raise e if e.is_a?(NameError) #swallow anything that isn't a NameError
|
508
|
+
end
|
509
|
+
end
|
503
510
|
end
|
504
511
|
end
|
512
|
+
|