route_translator 3.2.4 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/route_translator.rb +5 -5
- data/lib/route_translator/extensions/action_controller.rb +15 -21
- data/lib/route_translator/extensions/mapper.rb +6 -1
- data/lib/route_translator/host.rb +6 -10
- data/lib/route_translator/translator.rb +41 -19
- data/lib/route_translator/version.rb +1 -1
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/controllers/dummy_controller.rb +6 -0
- data/test/dummy/app/views/dummy/show.html.erb +1 -0
- data/test/dummy/config/application.rb +7 -0
- data/test/dummy/config/locales/all.yml +3 -0
- data/test/dummy/config/routes.rb +4 -1
- data/test/host_test.rb +33 -24
- data/test/integration/generated_path_test.rb +37 -0
- data/test/{integration_test.rb → integration/host_locales_test.rb} +19 -30
- data/test/integration/routing_test.rb +22 -0
- data/test/integration/thread_safety_test.rb +16 -0
- data/test/routing_test.rb +93 -65
- data/test/support/assertion_helper.rb +27 -0
- data/test/support/configuration_helper.rb +51 -0
- data/test/support/i18n_helper.rb +24 -0
- data/test/support/integration_helper.rb +6 -0
- data/test/support/routes_helper.rb +60 -0
- data/test/test_helper.rb +3 -96
- metadata +54 -24
- data/test/dummy/config/initializers/route_translator.rb +0 -4
@@ -0,0 +1,6 @@
|
|
1
|
+
require File.expand_path('../../dummy/dummy_mounted_app', __FILE__)
|
2
|
+
require File.expand_path('../../dummy/config/environment', __FILE__)
|
3
|
+
|
4
|
+
def integration_test_suite_parent_class
|
5
|
+
defined?(ActionDispatch::IntegrationTest) ? ActionDispatch::IntegrationTest : ActionController::IntegrationTest
|
6
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
|
2
|
+
module RouteTranslator
|
3
|
+
module RoutesHelper
|
4
|
+
|
5
|
+
def draw_routes(&block)
|
6
|
+
@routes.draw(&block)
|
7
|
+
if @routes.respond_to?(:install_helpers)
|
8
|
+
@routes.install_helpers
|
9
|
+
else
|
10
|
+
ActionView::Base.send(:include, @routes.url_helpers)
|
11
|
+
ActionController::Base.send(:include, @routes.url_helpers)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def path_string(route)
|
16
|
+
path = route.respond_to?(:path) ? route.path : route.to_s.split(' ')[1]
|
17
|
+
path.respond_to?(:spec) ? path.spec.to_s : path.to_s
|
18
|
+
end
|
19
|
+
|
20
|
+
def named_route(name)
|
21
|
+
@routes.routes.detect{ |r| r.name == name }
|
22
|
+
end
|
23
|
+
|
24
|
+
def formatted_root_route?
|
25
|
+
b = ActionPack::VERSION::MAJOR == 3 && ActionPack::VERSION::MINOR > 0
|
26
|
+
b ||= ActionPack::VERSION::MAJOR == 4
|
27
|
+
!b
|
28
|
+
end
|
29
|
+
|
30
|
+
def print_routes(route_set)
|
31
|
+
all_routes = route_set.routes
|
32
|
+
|
33
|
+
routes = all_routes.collect do |route|
|
34
|
+
|
35
|
+
reqs = route.requirements.dup
|
36
|
+
reqs[:to] = route.app unless route.app.class.name.to_s =~ /^ActionDispatch::Routing/
|
37
|
+
reqs = reqs.empty? ? "" : reqs.inspect
|
38
|
+
|
39
|
+
path = route.path
|
40
|
+
path = path.spec if path.respond_to?(:spec)
|
41
|
+
path = path.to_s
|
42
|
+
|
43
|
+
{:name => route.name.to_s, :verb => route.verb.to_s, :path => path, :reqs => reqs}
|
44
|
+
end
|
45
|
+
|
46
|
+
name_width = routes.map{ |r| r[:name].length }.max
|
47
|
+
verb_width = routes.map{ |r| r[:verb].length }.max
|
48
|
+
path_width = routes.map{ |r| r[:path].to_s.length }.max
|
49
|
+
|
50
|
+
puts
|
51
|
+
routes.each do |r|
|
52
|
+
puts "#{r[:name].rjust(name_width)} #{r[:verb].ljust(verb_width)} #{r[:path].to_s.ljust(path_width)} #{r[:reqs]}"
|
53
|
+
end
|
54
|
+
puts
|
55
|
+
|
56
|
+
rescue LoadError
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
#encoding: utf-8
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'minitest/autorun'
|
4
4
|
require 'minitest/mock'
|
5
|
-
require 'minitest/unit'
|
6
5
|
|
7
6
|
require 'i18n'
|
8
7
|
begin
|
@@ -27,98 +26,6 @@ module ActionDispatch
|
|
27
26
|
end
|
28
27
|
end
|
29
28
|
|
30
|
-
|
31
|
-
|
32
|
-
def draw_routes(&block)
|
33
|
-
@routes.draw(&block)
|
34
|
-
if @routes.respond_to?(:install_helpers)
|
35
|
-
@routes.install_helpers
|
36
|
-
else
|
37
|
-
ActionView::Base.send(:include, @routes.url_helpers)
|
38
|
-
ActionController::Base.send(:include, @routes.url_helpers)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def config_default_locale_settings(locale)
|
43
|
-
I18n.default_locale = locale
|
44
|
-
end
|
45
|
-
|
46
|
-
def config_force_locale(boolean)
|
47
|
-
RouteTranslator.config.force_locale = boolean
|
48
|
-
end
|
49
|
-
|
50
|
-
def config_hide_locale(boolean)
|
51
|
-
RouteTranslator.config.hide_locale = boolean
|
52
|
-
end
|
53
|
-
|
54
|
-
def config_generate_unlocalized_routes(boolean)
|
55
|
-
RouteTranslator.config.generate_unlocalized_routes = boolean
|
56
|
-
end
|
57
|
-
|
58
|
-
def config_generate_unnamed_unlocalized_routes(boolean)
|
59
|
-
RouteTranslator.config.generate_unnamed_unlocalized_routes = boolean
|
60
|
-
end
|
61
|
-
|
62
|
-
def config_host_locales(hash)
|
63
|
-
RouteTranslator.config.host_locales = hash.with_indifferent_access
|
64
|
-
end
|
65
|
-
|
66
|
-
def path_string(route)
|
67
|
-
path = route.respond_to?(:path) ? route.path : route.to_s.split(' ')[1]
|
68
|
-
path.respond_to?(:spec) ? path.spec.to_s : path.to_s
|
69
|
-
end
|
70
|
-
|
71
|
-
def named_route(name)
|
72
|
-
@routes.routes.detect{ |r| r.name == name }
|
73
|
-
end
|
74
|
-
|
75
|
-
def formatted_root_route?
|
76
|
-
b = ActionPack::VERSION::MAJOR == 3 && ActionPack::VERSION::MINOR > 0
|
77
|
-
b ||= ActionPack::VERSION::MAJOR == 4
|
78
|
-
!b
|
79
|
-
end
|
80
|
-
|
81
|
-
def print_routes(route_set)
|
82
|
-
all_routes = route_set.routes
|
83
|
-
|
84
|
-
routes = all_routes.collect do |route|
|
85
|
-
|
86
|
-
reqs = route.requirements.dup
|
87
|
-
reqs[:to] = route.app unless route.app.class.name.to_s =~ /^ActionDispatch::Routing/
|
88
|
-
reqs = reqs.empty? ? "" : reqs.inspect
|
89
|
-
|
90
|
-
{:name => route.name.to_s, :verb => route.verb.to_s, :path => route.path.try(:spec).to_s, :reqs => reqs}
|
91
|
-
end
|
92
|
-
|
93
|
-
name_width = routes.map{ |r| r[:name].length }.max
|
94
|
-
verb_width = routes.map{ |r| r[:verb].length }.max
|
95
|
-
path_width = routes.map{ |r| r[:path].to_s.length }.max
|
96
|
-
|
97
|
-
routes.each do |r|
|
98
|
-
puts "#{r[:name].rjust(name_width)} #{r[:verb].ljust(verb_width)} #{r[:path].to_s.ljust(path_width)} #{r[:reqs]}"
|
99
|
-
end
|
100
|
-
rescue LoadError
|
101
|
-
end
|
102
|
-
|
103
|
-
def assert_helpers_include(*helpers)
|
104
|
-
controller = ActionController::Base.new
|
105
|
-
view = ActionView::Base.new
|
106
|
-
helpers.each do |helper|
|
107
|
-
['url', 'path'].each do |suffix|
|
108
|
-
[controller, view].each { |obj| assert_respond_to obj, "#{helper}_#{suffix}".to_sym }
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
# Hack for compatibility between Rails 4 and Rails 3
|
114
|
-
def assert_unrecognized_route(route_path, options)
|
115
|
-
assert_raise ActionController::RoutingError do
|
116
|
-
begin
|
117
|
-
assert_routing route_path, options
|
118
|
-
rescue Minitest::Assertion => m
|
119
|
-
raise ActionController::RoutingError.new("")
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
29
|
+
Dir[File.expand_path('../support/*.rb', __FILE__)].each do |helper|
|
30
|
+
require helper
|
124
31
|
end
|
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:
|
4
|
+
version: 4.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Raul Murciano
|
@@ -9,48 +9,60 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-12-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
15
|
+
name: activesupport
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- -
|
18
|
+
- - ">="
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version:
|
21
|
-
|
20
|
+
version: '3.0'
|
21
|
+
- - "<"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: '5.0'
|
24
|
+
type: :runtime
|
22
25
|
prerelease: false
|
23
26
|
version_requirements: !ruby/object:Gem::Requirement
|
24
27
|
requirements:
|
25
|
-
- -
|
28
|
+
- - ">="
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '3.0'
|
31
|
+
- - "<"
|
26
32
|
- !ruby/object:Gem::Version
|
27
|
-
version:
|
33
|
+
version: '5.0'
|
28
34
|
- !ruby/object:Gem::Dependency
|
29
|
-
name:
|
35
|
+
name: actionpack
|
30
36
|
requirement: !ruby/object:Gem::Requirement
|
31
37
|
requirements:
|
32
|
-
- -
|
38
|
+
- - ">="
|
33
39
|
- !ruby/object:Gem::Version
|
34
|
-
version: '0'
|
35
|
-
|
40
|
+
version: '3.0'
|
41
|
+
- - "<"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '5.0'
|
44
|
+
type: :runtime
|
36
45
|
prerelease: false
|
37
46
|
version_requirements: !ruby/object:Gem::Requirement
|
38
47
|
requirements:
|
39
|
-
- -
|
48
|
+
- - ">="
|
40
49
|
- !ruby/object:Gem::Version
|
41
|
-
version: '0'
|
50
|
+
version: '3.0'
|
51
|
+
- - "<"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '5.0'
|
42
54
|
- !ruby/object:Gem::Dependency
|
43
|
-
name: pry
|
55
|
+
name: pry
|
44
56
|
requirement: !ruby/object:Gem::Requirement
|
45
57
|
requirements:
|
46
|
-
- -
|
58
|
+
- - ">="
|
47
59
|
- !ruby/object:Gem::Version
|
48
60
|
version: '0'
|
49
61
|
type: :development
|
50
62
|
prerelease: false
|
51
63
|
version_requirements: !ruby/object:Gem::Requirement
|
52
64
|
requirements:
|
53
|
-
- -
|
65
|
+
- - ">="
|
54
66
|
- !ruby/object:Gem::Version
|
55
67
|
version: '0'
|
56
68
|
description: Translates the Rails routes of your application into the languages defined
|
@@ -68,12 +80,13 @@ files:
|
|
68
80
|
- lib/route_translator/host.rb
|
69
81
|
- lib/route_translator/translator.rb
|
70
82
|
- lib/route_translator/version.rb
|
83
|
+
- test/dummy/Rakefile
|
71
84
|
- test/dummy/app/controllers/dummy_controller.rb
|
85
|
+
- test/dummy/app/views/dummy/show.html.erb
|
72
86
|
- test/dummy/config.ru
|
73
87
|
- test/dummy/config/application.rb
|
74
88
|
- test/dummy/config/boot.rb
|
75
89
|
- test/dummy/config/environment.rb
|
76
|
-
- test/dummy/config/initializers/route_translator.rb
|
77
90
|
- test/dummy/config/initializers/secret_token.rb
|
78
91
|
- test/dummy/config/initializers/session_store.rb
|
79
92
|
- test/dummy/config/locales/all.yml
|
@@ -81,9 +94,17 @@ files:
|
|
81
94
|
- test/dummy/dummy_mounted_app.rb
|
82
95
|
- test/dummy/script/rails
|
83
96
|
- test/host_test.rb
|
84
|
-
- test/
|
97
|
+
- test/integration/generated_path_test.rb
|
98
|
+
- test/integration/host_locales_test.rb
|
99
|
+
- test/integration/routing_test.rb
|
100
|
+
- test/integration/thread_safety_test.rb
|
85
101
|
- test/locales/routes.yml
|
86
102
|
- test/routing_test.rb
|
103
|
+
- test/support/assertion_helper.rb
|
104
|
+
- test/support/configuration_helper.rb
|
105
|
+
- test/support/i18n_helper.rb
|
106
|
+
- test/support/integration_helper.rb
|
107
|
+
- test/support/routes_helper.rb
|
87
108
|
- test/test_helper.rb
|
88
109
|
homepage: http://github.com/enriclluelles/route_translator
|
89
110
|
licenses: []
|
@@ -94,27 +115,28 @@ require_paths:
|
|
94
115
|
- lib
|
95
116
|
required_ruby_version: !ruby/object:Gem::Requirement
|
96
117
|
requirements:
|
97
|
-
- -
|
118
|
+
- - ">="
|
98
119
|
- !ruby/object:Gem::Version
|
99
120
|
version: '0'
|
100
121
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
122
|
requirements:
|
102
|
-
- -
|
123
|
+
- - ">="
|
103
124
|
- !ruby/object:Gem::Version
|
104
125
|
version: '0'
|
105
126
|
requirements: []
|
106
127
|
rubyforge_project:
|
107
|
-
rubygems_version: 2.
|
128
|
+
rubygems_version: 2.2.2
|
108
129
|
signing_key:
|
109
130
|
specification_version: 4
|
110
131
|
summary: Translate your Rails routes in a simple manner
|
111
132
|
test_files:
|
133
|
+
- test/dummy/Rakefile
|
112
134
|
- test/dummy/app/controllers/dummy_controller.rb
|
135
|
+
- test/dummy/app/views/dummy/show.html.erb
|
113
136
|
- test/dummy/config.ru
|
114
137
|
- test/dummy/config/application.rb
|
115
138
|
- test/dummy/config/boot.rb
|
116
139
|
- test/dummy/config/environment.rb
|
117
|
-
- test/dummy/config/initializers/route_translator.rb
|
118
140
|
- test/dummy/config/initializers/secret_token.rb
|
119
141
|
- test/dummy/config/initializers/session_store.rb
|
120
142
|
- test/dummy/config/locales/all.yml
|
@@ -122,7 +144,15 @@ test_files:
|
|
122
144
|
- test/dummy/dummy_mounted_app.rb
|
123
145
|
- test/dummy/script/rails
|
124
146
|
- test/host_test.rb
|
125
|
-
- test/
|
147
|
+
- test/integration/generated_path_test.rb
|
148
|
+
- test/integration/host_locales_test.rb
|
149
|
+
- test/integration/routing_test.rb
|
150
|
+
- test/integration/thread_safety_test.rb
|
126
151
|
- test/locales/routes.yml
|
127
152
|
- test/routing_test.rb
|
153
|
+
- test/support/assertion_helper.rb
|
154
|
+
- test/support/configuration_helper.rb
|
155
|
+
- test/support/i18n_helper.rb
|
156
|
+
- test/support/integration_helper.rb
|
157
|
+
- test/support/routes_helper.rb
|
128
158
|
- test/test_helper.rb
|