route_translator 3.2.1 → 3.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: baab3c78c16c578fd058f629b0194719b4284494
4
- data.tar.gz: 49d208644c13a219b5343af3c4b260b7d0d5f252
3
+ metadata.gz: 2978c69c256242672228bd99538e631a12446cef
4
+ data.tar.gz: 2fcb536aa8f1ce290696dd3a3e8f44cd84deb8c5
5
5
  SHA512:
6
- metadata.gz: a4db686f84980ed7e6f7dd8d39cc31254a6554e21d2c13a7c209ea1e373507460e6016319ceb79a393a6ee10a8c832fa5b9c89f8bacee6accac948219ce8225b
7
- data.tar.gz: 233344cea148bfb6c4db43314caf26c07a9b15e77b4aa3be6ecd4a4d630e3502101dcbdbe2d41547cde507a1e98393b73202f7e6315069be312dbee56ac10e0f
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
@@ -1,3 +1,3 @@
1
1
  module RouteTranslator
2
- VERSION = '3.2.1'
2
+ VERSION = '3.2.2'
3
3
  end
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
- 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
473
+ class ProductsControllerTest < ActionController::TestCase
474
+ include ActionDispatch::Assertions::RoutingAssertions
475
+ include RouteTranslator::TestHelper
479
476
 
480
- def test_action_mailer_test_case_reads_default_urls
481
- test_case_reads_default_urls(ActionMailer::TestCase)
482
- end
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 :person
487
+ resources :products
491
488
  end
492
489
  end
490
+ end
493
491
 
494
- test_case = klass.new(:respond_to?)
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
- # Not localized
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
- # Localized
501
- assert test_case.respond_to?(:people_en_path)
502
- assert test_case.respond_to?(:new_person_en_path)
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
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: route_translator
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.1
4
+ version: 3.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Raul Murciano