route_translator 4.1.0 → 4.2.1
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/CHANGELOG.md +11 -0
- data/LICENSE +21 -0
- data/README.md +231 -0
- data/lib/route_translator/extensions/action_controller.rb +5 -2
- data/lib/route_translator/extensions/mapper.rb +5 -5
- data/lib/route_translator/extensions/route_set.rb +1 -1
- data/lib/route_translator/host.rb +4 -5
- data/lib/route_translator/translator.rb +17 -13
- data/lib/route_translator/version.rb +1 -1
- data/lib/route_translator.rb +1 -1
- metadata +92 -59
- data/test/dummy/Rakefile +0 -7
- data/test/dummy/app/controllers/dummy_controller.rb +0 -11
- data/test/dummy/app/views/dummy/show.html.erb +0 -1
- data/test/dummy/config/application.rb +0 -21
- data/test/dummy/config/boot.rb +0 -0
- data/test/dummy/config/environment.rb +0 -5
- data/test/dummy/config/initializers/secret_token.rb +0 -7
- data/test/dummy/config/initializers/session_store.rb +0 -8
- data/test/dummy/config/locales/all.yml +0 -15
- data/test/dummy/config/routes.rb +0 -12
- data/test/dummy/config.ru +0 -4
- data/test/dummy/dummy_mounted_app.rb +0 -5
- data/test/dummy/script/rails +0 -6
- data/test/host_test.rb +0 -108
- data/test/integration/generated_path_test.rb +0 -37
- data/test/integration/host_locales_test.rb +0 -59
- data/test/integration/routing_test.rb +0 -22
- data/test/integration/thread_safety_test.rb +0 -16
- data/test/locales/routes.yml +0 -13
- data/test/routing_test.rb +0 -664
- data/test/support/assertion_helper.rb +0 -27
- data/test/support/configuration_helper.rb +0 -52
- data/test/support/i18n_helper.rb +0 -24
- data/test/support/integration_helper.rb +0 -6
- data/test/support/routes_helper.rb +0 -60
- data/test/test_helper.rb +0 -32
data/test/dummy/Rakefile
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
#!/usr/bin/env rake
|
2
|
-
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
3
|
-
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
4
|
-
|
5
|
-
require File.expand_path('../config/application', __FILE__)
|
6
|
-
|
7
|
-
Dummy::Application.load_tasks
|
@@ -1 +0,0 @@
|
|
1
|
-
<%= link_to "Show [#{I18n.locale}]", show_path %>
|
@@ -1,21 +0,0 @@
|
|
1
|
-
|
2
|
-
require 'i18n'
|
3
|
-
begin
|
4
|
-
I18n.enforce_available_locales = true
|
5
|
-
rescue NoMethodError
|
6
|
-
end
|
7
|
-
|
8
|
-
require "action_controller/railtie"
|
9
|
-
begin
|
10
|
-
require "active_resource/railtie"
|
11
|
-
rescue LoadError
|
12
|
-
end
|
13
|
-
require "route_translator"
|
14
|
-
|
15
|
-
module Dummy
|
16
|
-
class Application < Rails::Application
|
17
|
-
# config.logger = Logger.new(File.new("/dev/null", 'w'))
|
18
|
-
config.active_support.deprecation = :log
|
19
|
-
config.eager_load = false
|
20
|
-
end
|
21
|
-
end
|
data/test/dummy/config/boot.rb
DELETED
File without changes
|
@@ -1,7 +0,0 @@
|
|
1
|
-
# Be sure to restart your server when you modify this file.
|
2
|
-
|
3
|
-
# Your secret key for verifying the integrity of signed cookies.
|
4
|
-
# If you change this key, all old signed cookies will become invalid!
|
5
|
-
# Make sure the secret is at least 30 characters and all random,
|
6
|
-
# no regular words or you'll be exposed to dictionary attacks.
|
7
|
-
Dummy::Application.config.secret_token = '831d41b30a9e2d662a2d0c6f1f05b5f0b7db5d59446a18686b122e623e10bc5462eb48f9c9245f3e8b00cbe0cf007786482ba7012331de8f1bde93985c4d9686'
|
@@ -1,8 +0,0 @@
|
|
1
|
-
# Be sure to restart your server when you modify this file.
|
2
|
-
|
3
|
-
Dummy::Application.config.session_store :cookie_store, :key => '_dummy_session'
|
4
|
-
|
5
|
-
# Use the database for sessions instead of the cookie-based default,
|
6
|
-
# which shouldn't be used to store highly confidential information
|
7
|
-
# (create the session table with "rails generate session_migration")
|
8
|
-
# Dummy::Application.config.session_store :active_record_store
|
@@ -1,15 +0,0 @@
|
|
1
|
-
# Sample localization file for English. Add more files in this directory for other locales.
|
2
|
-
# See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
|
3
|
-
|
4
|
-
en:
|
5
|
-
routes:
|
6
|
-
dummy: dummy
|
7
|
-
show: show
|
8
|
-
es:
|
9
|
-
routes:
|
10
|
-
dummy: dummy
|
11
|
-
show: mostrar
|
12
|
-
ru:
|
13
|
-
routes:
|
14
|
-
dummy: манекен
|
15
|
-
show: показывать
|
data/test/dummy/config/routes.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
require File.join(Dummy::Application.root, 'dummy_mounted_app.rb')
|
2
|
-
|
3
|
-
Dummy::Application.routes.draw do
|
4
|
-
localized do
|
5
|
-
get 'dummy', :to => 'dummy#dummy'
|
6
|
-
get 'show', :to => 'dummy#show'
|
7
|
-
end
|
8
|
-
|
9
|
-
root :to => 'dummy#dummy'
|
10
|
-
|
11
|
-
mount DummyMountedApp.new => '/dummy_mounted_app'
|
12
|
-
end
|
data/test/dummy/config.ru
DELETED
data/test/dummy/script/rails
DELETED
@@ -1,6 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
3
|
-
|
4
|
-
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
5
|
-
require File.expand_path('../../config/boot', __FILE__)
|
6
|
-
require 'rails/commands'
|
data/test/host_test.rb
DELETED
@@ -1,108 +0,0 @@
|
|
1
|
-
#encoding: utf-8
|
2
|
-
require File.expand_path('../test_helper', __FILE__)
|
3
|
-
|
4
|
-
class TestHostsFromLocale < MiniTest::Unit::TestCase
|
5
|
-
|
6
|
-
include RouteTranslator::ConfigurationHelper
|
7
|
-
include RouteTranslator::I18nHelper
|
8
|
-
include RouteTranslator::RoutesHelper
|
9
|
-
|
10
|
-
def setup
|
11
|
-
setup_config
|
12
|
-
setup_i18n
|
13
|
-
|
14
|
-
config = host_locales_config_hash
|
15
|
-
config['*.something.es'] = :es
|
16
|
-
config['*.ru.subdomain.domain.*'] = :ru
|
17
|
-
config['russia.something.net'] = :ru
|
18
|
-
config['*.com'] = :en
|
19
|
-
|
20
|
-
config_host_locales(config)
|
21
|
-
end
|
22
|
-
|
23
|
-
def teardown
|
24
|
-
teardown_i18n
|
25
|
-
teardown_config
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_wildcard_at_beginning_matches
|
29
|
-
assert_equal :en, RouteTranslator::Host.locale_from_host('something.com')
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_wildcard_at_beginning_with_subdomain_matches
|
33
|
-
assert_equal :en, RouteTranslator::Host.locale_from_host('www.domain.com')
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_wildcard_at_beginning_without_subdomain_matches
|
37
|
-
assert_equal :en, RouteTranslator::Host.locale_from_host('domain.com')
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_wildcard_at_end_with_subdomain_matches
|
41
|
-
assert_equal :es, RouteTranslator::Host.locale_from_host('www.something.es')
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_wildcard_at_end_without_subdomain_matches
|
45
|
-
assert_equal :es, RouteTranslator::Host.locale_from_host('something.es')
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_no_wildcard_matches
|
49
|
-
assert_equal :ru, RouteTranslator::Host.locale_from_host('russia.something.net')
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_multiple_wildcard_matches
|
53
|
-
assert_equal :ru, RouteTranslator::Host.locale_from_host('www.ru.subdomain.domain.biz')
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_case_is_ignored
|
57
|
-
assert_equal :es, RouteTranslator::Host.locale_from_host('www.SoMeThInG.ES')
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_precedence_if_more_than_one_match
|
61
|
-
config = host_locales_config_hash
|
62
|
-
config['russia.*'] = :ru
|
63
|
-
config['*.com'] = :en
|
64
|
-
config_host_locales(config)
|
65
|
-
assert_equal :ru, RouteTranslator::Host.locale_from_host('russia.com')
|
66
|
-
|
67
|
-
config = host_locales_config_hash
|
68
|
-
config['*.com'] = :en
|
69
|
-
config['russia.*'] = :ru
|
70
|
-
config_host_locales(config)
|
71
|
-
assert_equal :en, RouteTranslator::Host.locale_from_host('russia.com')
|
72
|
-
end
|
73
|
-
|
74
|
-
def test_default_locale_if_no_matches
|
75
|
-
assert_equal I18n.default_locale, RouteTranslator::Host.locale_from_host('nomatches.co.uk')
|
76
|
-
end
|
77
|
-
|
78
|
-
def test_readme_examples_work
|
79
|
-
config = host_locales_config_hash
|
80
|
-
config['*.es'] = :es # matches ['domain.es', 'subdomain.domain.es', 'www.long.string.of.subdomains.es'] etc.
|
81
|
-
config['ru.wikipedia.*'] = :ru # matches ['ru.wikipedia.org', 'ru.wikipedia.net', 'ru.wikipedia.com'] etc.
|
82
|
-
config['*.subdomain.domain.*'] = :ru # matches ['subdomain.domain.org', 'www.subdomain.domain.net'] etc.
|
83
|
-
config['news.bbc.co.uk'] = :en # matches ['news.bbc.co.uk'] only
|
84
|
-
|
85
|
-
config_host_locales(config)
|
86
|
-
|
87
|
-
examples_1 = ['domain.es', 'subdomain.domain.es', 'www.long.string.of.subdomains.es']
|
88
|
-
examples_2 = ['ru.wikipedia.org', 'ru.wikipedia.net', 'ru.wikipedia.com']
|
89
|
-
examples_3 = ['subdomain.domain.org', 'www.subdomain.domain.net']
|
90
|
-
examples_4 = ['news.bbc.co.uk']
|
91
|
-
|
92
|
-
examples_1.each do |domain|
|
93
|
-
assert_equal :es, RouteTranslator::Host.locale_from_host(domain)
|
94
|
-
end
|
95
|
-
|
96
|
-
examples_2.each do |domain|
|
97
|
-
assert_equal :ru, RouteTranslator::Host.locale_from_host(domain)
|
98
|
-
end
|
99
|
-
|
100
|
-
examples_3.each do |domain|
|
101
|
-
assert_equal :ru, RouteTranslator::Host.locale_from_host(domain)
|
102
|
-
end
|
103
|
-
|
104
|
-
examples_4.each do |domain|
|
105
|
-
assert_equal :en, RouteTranslator::Host.locale_from_host(domain)
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
#encoding: utf-8
|
2
|
-
require File.expand_path('../../test_helper', __FILE__)
|
3
|
-
|
4
|
-
class GeneratedPathTest < integration_test_suite_parent_class
|
5
|
-
|
6
|
-
include RouteTranslator::ConfigurationHelper
|
7
|
-
|
8
|
-
def test_path_generated
|
9
|
-
get '/show'
|
10
|
-
assert_response :success
|
11
|
-
assert_tag :tag => "a", :attributes => { :href => "/show" }
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_path_translated
|
15
|
-
get '/es/mostrar'
|
16
|
-
assert_response :success
|
17
|
-
assert_tag :tag => "a", :attributes => { :href => "/es/mostrar" }
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_path_translated_after_force
|
21
|
-
config_force_locale true
|
22
|
-
|
23
|
-
get '/es/mostrar'
|
24
|
-
assert_response :success
|
25
|
-
assert_tag :tag => "a", :attributes => { :href => "/es/mostrar" }
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_path_translated_while_generate_unlocalized_routes
|
29
|
-
config_default_locale_settings 'en'
|
30
|
-
config_generate_unlocalized_routes true
|
31
|
-
|
32
|
-
get '/es/mostrar'
|
33
|
-
assert_response :success
|
34
|
-
assert_tag :tag => "a", :attributes => { :href => "/es/mostrar" }
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
@@ -1,59 +0,0 @@
|
|
1
|
-
#encoding: utf-8
|
2
|
-
require File.expand_path('../../test_helper', __FILE__)
|
3
|
-
|
4
|
-
class HostLocalesTest < integration_test_suite_parent_class
|
5
|
-
|
6
|
-
include RouteTranslator::ConfigurationHelper
|
7
|
-
|
8
|
-
def setup
|
9
|
-
config_host_locales('*.es' => 'es', 'ru.*.com' => 'ru')
|
10
|
-
Dummy::Application.reload_routes!
|
11
|
-
end
|
12
|
-
|
13
|
-
def teardown
|
14
|
-
config_host_locales({})
|
15
|
-
Dummy::Application.reload_routes!
|
16
|
-
end
|
17
|
-
|
18
|
-
|
19
|
-
def test_root_path
|
20
|
-
## root of es com
|
21
|
-
host! 'www.testapp.es'
|
22
|
-
get '/'
|
23
|
-
assert_equal 'es', @response.body
|
24
|
-
assert_response :success
|
25
|
-
|
26
|
-
## root of ru com
|
27
|
-
host! 'ru.testapp.com'
|
28
|
-
get '/'
|
29
|
-
assert_equal 'ru', @response.body
|
30
|
-
assert_response :success
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_explicit_path
|
34
|
-
## native es route on es com
|
35
|
-
host! 'www.testapp.es'
|
36
|
-
get '/dummy'
|
37
|
-
assert_equal 'es', @response.body
|
38
|
-
assert_response :success
|
39
|
-
|
40
|
-
## ru route on es com
|
41
|
-
host! 'www.testapp.es'
|
42
|
-
get URI.escape('/ru/манекен')
|
43
|
-
assert_equal 'ru', @response.body
|
44
|
-
assert_response :success
|
45
|
-
|
46
|
-
## native ru route on ru com
|
47
|
-
host! 'ru.testapp.com'
|
48
|
-
get URI.escape('/манекен')
|
49
|
-
assert_equal 'ru', @response.body
|
50
|
-
assert_response :success
|
51
|
-
|
52
|
-
## es route on ru com
|
53
|
-
host! 'ru.testapp.com'
|
54
|
-
get '/es/dummy'
|
55
|
-
assert_equal 'es', @response.body
|
56
|
-
assert_response :success
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
#encoding: utf-8
|
2
|
-
require File.expand_path('../../test_helper', __FILE__)
|
3
|
-
|
4
|
-
class RoutingTest < integration_test_suite_parent_class
|
5
|
-
|
6
|
-
include RouteTranslator::ConfigurationHelper
|
7
|
-
|
8
|
-
def test_set_locale_from_params
|
9
|
-
config_default_locale_settings 'en'
|
10
|
-
|
11
|
-
get '/es/dummy'
|
12
|
-
assert_equal 'es', @response.body
|
13
|
-
assert_response :success
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_mounted_apps_work_with_correct_path
|
17
|
-
get '/dummy_mounted_app'
|
18
|
-
assert_equal "Good", @response.body
|
19
|
-
assert_response :success
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
#encoding: utf-8
|
2
|
-
require File.expand_path('../../test_helper', __FILE__)
|
3
|
-
|
4
|
-
class ThreadSafetyTest < integration_test_suite_parent_class
|
5
|
-
|
6
|
-
include RouteTranslator::ConfigurationHelper
|
7
|
-
|
8
|
-
def test_i18n_locale_thread_safe
|
9
|
-
config_default_locale_settings 'en'
|
10
|
-
get '/es/dummy'
|
11
|
-
assert_equal 'es', @response.body
|
12
|
-
|
13
|
-
assert_equal :en, I18n.locale
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|