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/routing_test.rb
DELETED
@@ -1,664 +0,0 @@
|
|
1
|
-
#encoding: utf-8
|
2
|
-
require File.expand_path('../test_helper', __FILE__)
|
3
|
-
|
4
|
-
class PeopleController < ActionController::Base; end
|
5
|
-
class ProductsController < ActionController::Base; end
|
6
|
-
|
7
|
-
class TranslateRoutesTest < ActionController::TestCase
|
8
|
-
|
9
|
-
include ActionDispatch::Assertions::RoutingAssertions
|
10
|
-
include RouteTranslator::AssertionHelper
|
11
|
-
include RouteTranslator::ConfigurationHelper
|
12
|
-
include RouteTranslator::I18nHelper
|
13
|
-
include RouteTranslator::RoutesHelper
|
14
|
-
|
15
|
-
def setup
|
16
|
-
setup_config
|
17
|
-
setup_i18n
|
18
|
-
@routes = ActionDispatch::Routing::RouteSet.new
|
19
|
-
end
|
20
|
-
|
21
|
-
def teardown
|
22
|
-
teardown_i18n
|
23
|
-
teardown_config
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_unnamed_root_route
|
27
|
-
draw_routes do
|
28
|
-
localized do
|
29
|
-
root :to => 'people#index'
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
assert_routing '/', :controller => 'people', :action => 'index', :locale => 'en'
|
34
|
-
assert_routing '/es', :controller => 'people', :action => 'index', :locale => 'es'
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_params
|
38
|
-
draw_routes do
|
39
|
-
localized do
|
40
|
-
resources :products
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
assert_routing '/es/productos/product_slug', :controller => 'products', :action => 'show', :locale => 'es', :id => 'product_slug'
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_optional_segments
|
48
|
-
draw_routes do
|
49
|
-
localized do
|
50
|
-
get 'products(/:optional_param)/:non_optional_param', :to => 'products#index'
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
assert_routing '/es/productos/a', :controller => 'products', :action => 'index', :locale => 'es', :non_optional_param => 'a'
|
55
|
-
assert_routing '/es/productos/a/b', :controller => 'products', :action => 'index', :locale => 'es', :non_optional_param => 'b', :optional_param => 'a'
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_translations_after_optional_segments
|
59
|
-
draw_routes do
|
60
|
-
localized do
|
61
|
-
get '(/:optional_param)/products', :to => 'products#index'
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
assert_routing '/es/productos', :controller => 'products', :action => 'index', :locale => 'es'
|
66
|
-
assert_routing '/es/a/productos', :controller => 'products', :action => 'index', :locale => 'es', :optional_param => 'a'
|
67
|
-
end
|
68
|
-
|
69
|
-
def test_dynamic_segments_dont_get_translated
|
70
|
-
draw_routes do
|
71
|
-
localized do
|
72
|
-
get 'products/:tr_param', :to => 'products#index', :constraints => { :tr_param => /\w/ }
|
73
|
-
end
|
74
|
-
end
|
75
|
-
assert_routing '/es/productos/a', :controller => 'products', :action => 'index', :locale => 'es', :tr_param => 'a'
|
76
|
-
end
|
77
|
-
|
78
|
-
def test_wildcards_dont_get_translated
|
79
|
-
draw_routes do
|
80
|
-
localized do
|
81
|
-
get 'products/*tr_param', :to => 'products#index'
|
82
|
-
end
|
83
|
-
end
|
84
|
-
assert_routing '/es/productos/a/b', :controller => 'products', :action => 'index', :locale => 'es', :tr_param => 'a/b'
|
85
|
-
end
|
86
|
-
|
87
|
-
def test_resources
|
88
|
-
config_default_locale_settings 'es'
|
89
|
-
|
90
|
-
draw_routes do
|
91
|
-
localized do
|
92
|
-
resources :products
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
assert_routing '/en/products', :controller => 'products', :action => 'index', :locale => 'en'
|
97
|
-
assert_routing '/productos', :controller => 'products', :action => 'index', :locale => 'es'
|
98
|
-
assert_routing({:path => '/productos/1', :method => "GET"}, {:controller => 'products', :action => 'show', :id => '1', :locale => 'es'})
|
99
|
-
assert_routing({:path => '/productos/1', :method => "PUT"}, {:controller => 'products', :action => 'update', :id => '1', :locale => 'es'})
|
100
|
-
end
|
101
|
-
|
102
|
-
def test_utf8_characters
|
103
|
-
draw_routes do
|
104
|
-
localized do
|
105
|
-
get 'people', :to => 'people#index'
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
assert_routing URI.escape('/ru/люди'), :controller => 'people', :action => 'index', :locale => 'ru'
|
110
|
-
end
|
111
|
-
|
112
|
-
def test_resources_with_only
|
113
|
-
config_default_locale_settings 'es'
|
114
|
-
|
115
|
-
draw_routes do
|
116
|
-
localized do
|
117
|
-
resources :products, :only => [:index, :show]
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
assert_routing '/en/products', :controller => 'products', :action => 'index', :locale => 'en'
|
122
|
-
assert_routing '/productos', :controller => 'products', :action => 'index', :locale => 'es'
|
123
|
-
assert_routing({:path => '/productos/1', :method => "GET"}, {:controller => 'products', :action => 'show', :id => '1', :locale => 'es'})
|
124
|
-
assert_unrecognized_route({:path => '/productos/1', :method => "PUT"}, {:controller => 'products', :action => 'update', :id => '1', :locale => 'es'})
|
125
|
-
end
|
126
|
-
|
127
|
-
def test_unnamed_root_route_without_prefix
|
128
|
-
config_default_locale_settings 'es'
|
129
|
-
|
130
|
-
draw_routes do
|
131
|
-
localized do
|
132
|
-
root :to => 'people#index'
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
assert_routing '/', :controller => 'people', :action => 'index', :locale => 'es'
|
137
|
-
assert_routing '/en', :controller => 'people', :action => 'index', :locale => 'en'
|
138
|
-
assert_unrecognized_route '/es', :controller => 'people', :action => 'index', :locale => 'es'
|
139
|
-
end
|
140
|
-
|
141
|
-
def test_unnamed_untranslated_route
|
142
|
-
draw_routes do
|
143
|
-
localized do
|
144
|
-
get 'foo', :to => 'people#index'
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
assert_routing '/es/foo', :controller => 'people', :action => 'index', :locale => 'es'
|
149
|
-
assert_routing '/foo', :controller => 'people', :action => 'index', :locale => 'en'
|
150
|
-
end
|
151
|
-
|
152
|
-
def test_unnamed_translated_route_on_default_locale
|
153
|
-
config_default_locale_settings 'es'
|
154
|
-
|
155
|
-
@routes.draw { get 'people', :to => 'people#index' }
|
156
|
-
draw_routes do
|
157
|
-
localized do
|
158
|
-
get 'people', :to => 'people#index'
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
|
163
|
-
assert_routing '/en/people', :controller => 'people', :action => 'index', :locale => 'en'
|
164
|
-
assert_routing '/gente', :controller => 'people', :action => 'index', :locale => 'es'
|
165
|
-
end
|
166
|
-
|
167
|
-
def test_unnamed_translated_route_on_non_default_locale
|
168
|
-
draw_routes do
|
169
|
-
localized do
|
170
|
-
get 'people', :to => 'people#index'
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
assert_routing '/es/gente', :controller => 'people', :action => 'index', :locale => 'es'
|
175
|
-
assert_routing '/people', :controller => 'people', :action => 'index', :locale => 'en'
|
176
|
-
end
|
177
|
-
|
178
|
-
def test_named_translated_route_with_prefix_must_have_locale_as_static_segment
|
179
|
-
draw_routes do
|
180
|
-
localized do
|
181
|
-
get 'people', :to => 'people#index'
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
# we check the string representation of the route,
|
186
|
-
# if it stores locale as a dynamic segment it would be represented as: "/:locale/gente"
|
187
|
-
assert_equal "/es/gente(.:format)", path_string(named_route('people_es'))
|
188
|
-
end
|
189
|
-
|
190
|
-
def test_named_empty_route_without_prefix
|
191
|
-
config_default_locale_settings 'es'
|
192
|
-
draw_routes do
|
193
|
-
localized do
|
194
|
-
root :to => 'people#index', :as => 'people'
|
195
|
-
end
|
196
|
-
end
|
197
|
-
|
198
|
-
assert_routing '/en', :controller => 'people', :action => 'index', :locale => 'en'
|
199
|
-
assert_routing '/', :controller => 'people', :action => 'index', :locale => 'es'
|
200
|
-
assert_routing '', :controller => 'people', :action => 'index', :locale => 'es'
|
201
|
-
end
|
202
|
-
|
203
|
-
def test_named_root_route_without_prefix
|
204
|
-
config_default_locale_settings 'es'
|
205
|
-
|
206
|
-
draw_routes do
|
207
|
-
localized do
|
208
|
-
root :to => 'people#index'
|
209
|
-
end
|
210
|
-
end
|
211
|
-
|
212
|
-
assert_routing '/', :controller => 'people', :action => 'index', :locale => 'es'
|
213
|
-
assert_routing '/en', :controller => 'people', :action => 'index', :locale => 'en'
|
214
|
-
assert_unrecognized_route '/es', :controller => 'people', :action => 'index', :locale => 'es'
|
215
|
-
end
|
216
|
-
|
217
|
-
def test_named_untranslated_route_without_prefix
|
218
|
-
config_default_locale_settings 'es'
|
219
|
-
|
220
|
-
draw_routes do
|
221
|
-
localized do
|
222
|
-
get 'foo', :to => 'people#index', :as => 'people'
|
223
|
-
end
|
224
|
-
end
|
225
|
-
|
226
|
-
assert_routing '/en/foo', :controller => 'people', :action => 'index', :locale => 'en'
|
227
|
-
assert_routing '/foo', :controller => 'people', :action => 'index', :locale => 'es'
|
228
|
-
|
229
|
-
assert_helpers_include :people_en, :people_es, :people
|
230
|
-
end
|
231
|
-
|
232
|
-
def test_named_translated_route_on_default_locale_without_prefix
|
233
|
-
config_default_locale_settings 'es'
|
234
|
-
|
235
|
-
draw_routes do
|
236
|
-
localized do
|
237
|
-
get 'people', :to => 'people#index', :as => 'people'
|
238
|
-
end
|
239
|
-
end
|
240
|
-
|
241
|
-
assert_routing '/en/people', :controller => 'people', :action => 'index', :locale => 'en'
|
242
|
-
assert_routing 'gente', :controller => 'people', :action => 'index', :locale => 'es'
|
243
|
-
|
244
|
-
|
245
|
-
assert_helpers_include :people_en, :people_es, :people
|
246
|
-
end
|
247
|
-
|
248
|
-
def test_named_translated_route_on_non_default_locale_without_prefix
|
249
|
-
draw_routes do
|
250
|
-
localized do
|
251
|
-
get 'people', :to => 'people#index', :as => 'people'
|
252
|
-
end
|
253
|
-
end
|
254
|
-
|
255
|
-
assert_routing '/people', :controller => 'people', :action => 'index', :locale => 'en'
|
256
|
-
assert_routing '/es/gente', :controller => 'people', :action => 'index', :locale => 'es'
|
257
|
-
|
258
|
-
assert_helpers_include :people_en, :people_es, :people
|
259
|
-
end
|
260
|
-
|
261
|
-
def test_formatted_root_route
|
262
|
-
draw_routes do
|
263
|
-
localized do
|
264
|
-
root :to => 'people#index', :as => 'root'
|
265
|
-
end
|
266
|
-
end
|
267
|
-
|
268
|
-
if formatted_root_route?
|
269
|
-
assert_equal '/(.:format)', path_string(named_route('root_en'))
|
270
|
-
assert_equal '/es(.:format)', path_string(named_route('root_es'))
|
271
|
-
else
|
272
|
-
assert_equal '/', path_string(named_route('root_en'))
|
273
|
-
assert_equal '/es', path_string(named_route('root_es'))
|
274
|
-
end
|
275
|
-
end
|
276
|
-
|
277
|
-
def test_route_with_mandatory_format
|
278
|
-
draw_routes do
|
279
|
-
localized do
|
280
|
-
get 'people.:format', :to => 'people#index'
|
281
|
-
end
|
282
|
-
end
|
283
|
-
|
284
|
-
assert_routing '/es/gente.xml', :controller => 'people', :action => 'index', :format => 'xml', :locale => 'es'
|
285
|
-
assert_routing '/people.xml', :controller => 'people', :action => 'index', :format => 'xml', :locale => 'en'
|
286
|
-
end
|
287
|
-
|
288
|
-
def test_route_with_optional_format
|
289
|
-
draw_routes do
|
290
|
-
localized do
|
291
|
-
get 'people(.:format)', :to => 'people#index'
|
292
|
-
end
|
293
|
-
end
|
294
|
-
|
295
|
-
assert_routing '/es/gente', :controller => 'people', :action => 'index', :locale => 'es'
|
296
|
-
assert_routing '/people', :controller => 'people', :action => 'index', :locale => 'en'
|
297
|
-
assert_routing '/es/gente.xml', :controller => 'people', :action => 'index', :format => 'xml', :locale => 'es'
|
298
|
-
assert_routing '/people.xml', :controller => 'people', :action => 'index', :format => 'xml', :locale => 'en'
|
299
|
-
end
|
300
|
-
|
301
|
-
def test_i18n_based_translations_setting_locales
|
302
|
-
draw_routes do
|
303
|
-
localized do
|
304
|
-
get 'people', :to => 'people#index', :as => 'people'
|
305
|
-
end
|
306
|
-
end
|
307
|
-
|
308
|
-
assert_routing '/es/gente', :controller => 'people', :action => 'index', :locale => 'es'
|
309
|
-
assert_routing '/people', :controller => 'people', :action => 'index', :locale => 'en'
|
310
|
-
|
311
|
-
|
312
|
-
assert_helpers_include :people_en, :people_es, :people
|
313
|
-
end
|
314
|
-
|
315
|
-
def test_translations_depend_on_available_locales
|
316
|
-
available_locales = I18n.available_locales
|
317
|
-
begin
|
318
|
-
I18n.available_locales = [:es, :en, :fr]
|
319
|
-
|
320
|
-
draw_routes do
|
321
|
-
localized do
|
322
|
-
get 'people', :to => 'people#index', :as => 'people'
|
323
|
-
end
|
324
|
-
end
|
325
|
-
|
326
|
-
assert_routing '/fr/people', :controller => 'people', :action => 'index', :locale => 'fr'
|
327
|
-
assert_routing '/es/gente', :controller => 'people', :action => 'index', :locale => 'es'
|
328
|
-
assert_routing '/people', :controller => 'people', :action => 'index', :locale => 'en'
|
329
|
-
|
330
|
-
assert_helpers_include :people_fr, :people_en, :people_es, :people
|
331
|
-
ensure
|
332
|
-
I18n.available_locales = available_locales
|
333
|
-
end
|
334
|
-
end
|
335
|
-
|
336
|
-
def test_2_localized_blocks
|
337
|
-
draw_routes do
|
338
|
-
localized do
|
339
|
-
get 'people', :to => 'people#index', :as => 'people'
|
340
|
-
end
|
341
|
-
localized do
|
342
|
-
get 'products', :to => 'products#index', :as => 'products'
|
343
|
-
end
|
344
|
-
end
|
345
|
-
|
346
|
-
assert_routing '/es/gente', :controller => 'people', :action => 'index', :locale => 'es'
|
347
|
-
assert_routing '/es/productos', :controller => 'products', :action => 'index', :locale => 'es'
|
348
|
-
end
|
349
|
-
|
350
|
-
def test_not_localizing_routes_outside_blocks
|
351
|
-
config_default_locale_settings 'en'
|
352
|
-
draw_routes do
|
353
|
-
localized do
|
354
|
-
get 'people', :to => 'people#index', :as => 'people'
|
355
|
-
end
|
356
|
-
get 'products', :to => 'products#index', :as => 'products'
|
357
|
-
end
|
358
|
-
|
359
|
-
assert_routing '/es/gente', :controller => 'people', :action => 'index', :locale => 'es'
|
360
|
-
assert_routing '/products', :controller => 'products', :action => 'index'
|
361
|
-
assert_unrecognized_route '/es/productos', :controller => 'products', :action => 'index', :locale => 'es'
|
362
|
-
end
|
363
|
-
|
364
|
-
def test_force_locale
|
365
|
-
config_force_locale true
|
366
|
-
|
367
|
-
draw_routes do
|
368
|
-
localized do
|
369
|
-
get 'people', :to => 'people#index', :as => 'people'
|
370
|
-
end
|
371
|
-
end
|
372
|
-
|
373
|
-
assert_routing '/en/people', :controller => 'people', :action => 'index', :locale => 'en'
|
374
|
-
assert_unrecognized_route '/people', :controller => 'people', :action => 'index'
|
375
|
-
assert_equal '/en/people', @routes.url_helpers.people_en_path
|
376
|
-
assert_equal '/en/people', @routes.url_helpers.people_path
|
377
|
-
I18n.with_locale :es do
|
378
|
-
# The dynamic route maps to the current locale
|
379
|
-
assert_equal '/es/gente', @routes.url_helpers.people_path
|
380
|
-
end
|
381
|
-
end
|
382
|
-
|
383
|
-
def test_generate_unlocalized_routes
|
384
|
-
config_generate_unlocalized_routes true
|
385
|
-
|
386
|
-
draw_routes do
|
387
|
-
localized do
|
388
|
-
get 'people', :to => 'people#index', :as => 'people'
|
389
|
-
end
|
390
|
-
end
|
391
|
-
|
392
|
-
assert_routing '/en/people', :controller => 'people', :action => 'index', :locale => 'en'
|
393
|
-
assert_routing '/people', :controller => 'people', :action => 'index'
|
394
|
-
assert_equal '/en/people', @routes.url_helpers.people_en_path
|
395
|
-
assert_equal '/people', @routes.url_helpers.people_path
|
396
|
-
|
397
|
-
I18n.with_locale :es do
|
398
|
-
# The dynamic route maps to the default locale, not the current
|
399
|
-
assert_equal '/people', @routes.url_helpers.people_path
|
400
|
-
end
|
401
|
-
end
|
402
|
-
|
403
|
-
def test_generate_unnamed_unlocalized_routes
|
404
|
-
config_generate_unnamed_unlocalized_routes true
|
405
|
-
|
406
|
-
draw_routes do
|
407
|
-
localized do
|
408
|
-
get 'people', :to => 'people#index', :as => 'people'
|
409
|
-
end
|
410
|
-
end
|
411
|
-
|
412
|
-
assert_routing '/en/people', :controller => 'people', :action => 'index', :locale => 'en'
|
413
|
-
assert_routing '/people', :controller => 'people', :action => 'index'
|
414
|
-
assert_equal '/en/people', @routes.url_helpers.people_en_path
|
415
|
-
assert_equal '/en/people', @routes.url_helpers.people_path
|
416
|
-
|
417
|
-
I18n.with_locale :es do
|
418
|
-
# The dynamic route maps to the current locale
|
419
|
-
assert_equal '/es/gente', @routes.url_helpers.people_path
|
420
|
-
end
|
421
|
-
end
|
422
|
-
|
423
|
-
def test_blank_localized_routes
|
424
|
-
draw_routes do
|
425
|
-
localized do
|
426
|
-
get 'people/blank', :to => 'people#index', :as => 'people'
|
427
|
-
end
|
428
|
-
end
|
429
|
-
|
430
|
-
I18n.with_locale :en do
|
431
|
-
assert_routing '/people/blank', :controller => 'people', :action => 'index', :locale => 'en'
|
432
|
-
assert_equal '/people/blank', @routes.url_helpers.people_en_path
|
433
|
-
end
|
434
|
-
|
435
|
-
I18n.with_locale :es do
|
436
|
-
assert_routing '/es/gente', :controller => 'people', :action => 'index', :locale => 'es'
|
437
|
-
assert_equal '/es/gente', @routes.url_helpers.people_es_path
|
438
|
-
end
|
439
|
-
end
|
440
|
-
|
441
|
-
def test_path_helper_arguments
|
442
|
-
config_default_locale_settings 'es'
|
443
|
-
I18n.with_locale :es do
|
444
|
-
config_host_locales({ '*.es' => 'es', '*.com' => 'en' })
|
445
|
-
|
446
|
-
draw_routes do
|
447
|
-
localized do
|
448
|
-
resources :products
|
449
|
-
end
|
450
|
-
end
|
451
|
-
|
452
|
-
assert_equal '/productos', @routes.url_helpers.products_path
|
453
|
-
assert_equal '/productos/some_product', @routes.url_helpers.product_path('some_product')
|
454
|
-
assert_equal '/productos/some_product?some=param', @routes.url_helpers.product_path('some_product', :some => 'param')
|
455
|
-
assert_equal '/en/products', @routes.url_helpers.products_path(:locale => 'en')
|
456
|
-
assert_equal '/en/products/some_product', @routes.url_helpers.product_path('some_product', :locale => 'en')
|
457
|
-
assert_equal '/en/products/some_product?some=param', @routes.url_helpers.product_path('some_product', :locale => 'en', :some => 'param')
|
458
|
-
end
|
459
|
-
end
|
460
|
-
|
461
|
-
def test_dont_add_locale_to_routes_if_local_param_present
|
462
|
-
config_default_locale_settings 'es'
|
463
|
-
config_force_locale true
|
464
|
-
|
465
|
-
draw_routes do
|
466
|
-
scope 'segment/:locale' do
|
467
|
-
localized do
|
468
|
-
resources :products
|
469
|
-
end
|
470
|
-
end
|
471
|
-
end
|
472
|
-
|
473
|
-
assert_routing '/segment/es/productos/product_slug', :controller => 'products', :action => 'show', :locale => 'es', :id => 'product_slug'
|
474
|
-
assert_routing '/segment/en/products/product_slug', :controller => 'products', :action => 'show', :locale => 'en', :id => 'product_slug'
|
475
|
-
end
|
476
|
-
|
477
|
-
def test_config_hide_locale
|
478
|
-
config_hide_locale true
|
479
|
-
|
480
|
-
draw_routes do
|
481
|
-
localized do
|
482
|
-
resources :people
|
483
|
-
end
|
484
|
-
end
|
485
|
-
|
486
|
-
assert_routing '/gente', :controller => 'people', :action => 'index', :locale => 'es'
|
487
|
-
assert_routing '/people', :controller => 'people', :action => 'index', :locale => 'en'
|
488
|
-
end
|
489
|
-
|
490
|
-
def test_host_locales
|
491
|
-
config_host_locales({ '*.es' => 'es', '*.com' => 'en' })
|
492
|
-
|
493
|
-
draw_routes do
|
494
|
-
localized do
|
495
|
-
resources :people
|
496
|
-
end
|
497
|
-
root :to => 'people#index'
|
498
|
-
end
|
499
|
-
|
500
|
-
assert_recognizes({:controller => 'people', :action => 'index', :locale => 'es'}, { :path => 'http://testapp.es/gente', :method => :get })
|
501
|
-
assert_recognizes({:controller => 'people', :action => 'index', :locale => 'es'}, { :path => 'http://testapp.es/es/gente', :method => :get })
|
502
|
-
assert_recognizes({:controller => 'people', :action => 'index'}, { :path => 'http://testapp.es/', :method => :get })
|
503
|
-
|
504
|
-
assert_recognizes({:controller => 'people', :action => 'index', :locale => 'en'}, { :path => 'http://testapp.com/people', :method => :get })
|
505
|
-
assert_recognizes({:controller => 'people', :action => 'index'}, { :path => 'http://testapp.com/', :method => :get })
|
506
|
-
end
|
507
|
-
|
508
|
-
|
509
|
-
def test_action_controller_gets_locale_setter
|
510
|
-
ActionController::Base.instance_methods.include?('set_locale_from_url')
|
511
|
-
end
|
512
|
-
|
513
|
-
def test_action_controller_gets_locale_suffix_helper
|
514
|
-
ActionController::Base.instance_methods.include?('locale_suffix')
|
515
|
-
end
|
516
|
-
|
517
|
-
def test_action_view_gets_locale_suffix_helper
|
518
|
-
ActionView::Base.instance_methods.include?('locale_suffix')
|
519
|
-
end
|
520
|
-
|
521
|
-
# See https://github.com/enriclluelles/route_translator/issues/69
|
522
|
-
def test_no_side_effects
|
523
|
-
draw_routes do
|
524
|
-
localized do
|
525
|
-
resources :people
|
526
|
-
end
|
527
|
-
|
528
|
-
scope "(:locale)", :locale => /(en|es)/ do
|
529
|
-
get '*id' => 'products#show', :as => 'product'
|
530
|
-
end
|
531
|
-
end
|
532
|
-
|
533
|
-
assert_routing '/es/gente', :controller => 'people', :action => 'index', :locale => 'es'
|
534
|
-
assert_routing '/people', :controller => 'people', :action => 'index', :locale => 'en'
|
535
|
-
|
536
|
-
assert_routing '/es/path/to/a/product', :controller => 'products', :action => 'show', :locale => 'es', :id => 'path/to/a/product'
|
537
|
-
assert_routing '/path/to/another/product', :controller => 'products', :action => 'show', :id => 'path/to/another/product'
|
538
|
-
end
|
539
|
-
|
540
|
-
def test_config_available_locales
|
541
|
-
config_available_locales [:en, :ru]
|
542
|
-
|
543
|
-
draw_routes do
|
544
|
-
localized do
|
545
|
-
resources :people
|
546
|
-
end
|
547
|
-
end
|
548
|
-
|
549
|
-
assert_routing URI.escape('/ru/люди'), :controller => 'people', :action => 'index', :locale => 'ru'
|
550
|
-
assert_routing '/people', :controller => 'people', :action => 'index', :locale => 'en'
|
551
|
-
assert_unrecognized_route '/es/gente', :controller => 'people', :action => 'index', :locale => 'es'
|
552
|
-
|
553
|
-
config_available_locales nil
|
554
|
-
end
|
555
|
-
|
556
|
-
def test_config_available_locales_handles_strings
|
557
|
-
config_available_locales %w( en ru )
|
558
|
-
|
559
|
-
draw_routes do
|
560
|
-
localized do
|
561
|
-
resources :people
|
562
|
-
end
|
563
|
-
end
|
564
|
-
|
565
|
-
assert_routing URI.escape('/ru/люди'), :controller => 'people', :action => 'index', :locale => 'ru'
|
566
|
-
assert_routing '/people', :controller => 'people', :action => 'index', :locale => 'en'
|
567
|
-
assert_unrecognized_route '/es/gente', :controller => 'people', :action => 'index', :locale => 'es'
|
568
|
-
|
569
|
-
config_available_locales nil
|
570
|
-
end
|
571
|
-
|
572
|
-
def test_disable_fallback_does_not_draw_non_default_routes
|
573
|
-
config_disable_fallback(true)
|
574
|
-
|
575
|
-
draw_routes do
|
576
|
-
localized do
|
577
|
-
get 'tr_param', :to => 'people#index', :as => 'people'
|
578
|
-
end
|
579
|
-
end
|
580
|
-
|
581
|
-
config_disable_fallback(false)
|
582
|
-
|
583
|
-
assert_routing '/tr_param', :controller => 'people', :action => 'index', :locale => 'en'
|
584
|
-
assert_routing '/es/tr_parametro', :controller => 'people', :action => 'index', :locale => 'es'
|
585
|
-
assert_unrecognized_route '/ru/tr_param', :controller => 'people', :action => 'index', :locale => 'ru'
|
586
|
-
end
|
587
|
-
|
588
|
-
def test_action_controller_test_case_reads_default_urls
|
589
|
-
test_case_reads_default_urls(ActionController::TestCase)
|
590
|
-
end
|
591
|
-
|
592
|
-
def test_action_view_test_case_reads_default_urls
|
593
|
-
test_case_reads_default_urls(ActionView::TestCase)
|
594
|
-
end
|
595
|
-
|
596
|
-
def test_action_mailer_test_case_reads_default_urls
|
597
|
-
test_case_reads_default_urls(ActionMailer::TestCase)
|
598
|
-
end
|
599
|
-
|
600
|
-
private
|
601
|
-
|
602
|
-
def test_case_reads_default_urls(klass)
|
603
|
-
config_default_locale_settings 'en'
|
604
|
-
|
605
|
-
draw_routes do
|
606
|
-
localized do
|
607
|
-
resources :person
|
608
|
-
end
|
609
|
-
end
|
610
|
-
|
611
|
-
test_case = klass.new(nil)
|
612
|
-
|
613
|
-
# Not localized
|
614
|
-
assert test_case.respond_to?(:people_path)
|
615
|
-
assert test_case.respond_to?(:new_person_path)
|
616
|
-
|
617
|
-
# Localized
|
618
|
-
assert test_case.respond_to?(:people_en_path)
|
619
|
-
assert test_case.respond_to?(:new_person_en_path)
|
620
|
-
end
|
621
|
-
|
622
|
-
end
|
623
|
-
|
624
|
-
class ProductsControllerTest < ActionController::TestCase
|
625
|
-
|
626
|
-
include RouteTranslator::ConfigurationHelper
|
627
|
-
include RouteTranslator::I18nHelper
|
628
|
-
include ActionDispatch::Assertions::RoutingAssertions
|
629
|
-
include RouteTranslator::RoutesHelper
|
630
|
-
|
631
|
-
def setup
|
632
|
-
setup_config
|
633
|
-
setup_i18n
|
634
|
-
|
635
|
-
@routes = ActionDispatch::Routing::RouteSet.new
|
636
|
-
|
637
|
-
config_default_locale_settings 'es'
|
638
|
-
config_host_locales({:es => 'es'})
|
639
|
-
|
640
|
-
draw_routes do
|
641
|
-
localized do
|
642
|
-
resources :products
|
643
|
-
end
|
644
|
-
end
|
645
|
-
end
|
646
|
-
|
647
|
-
def teardown
|
648
|
-
teardown_i18n
|
649
|
-
teardown_config
|
650
|
-
end
|
651
|
-
|
652
|
-
def test_url_helpers_are_included
|
653
|
-
#doing it this way because assert_nothing_raised doesn't work on all rails versions
|
654
|
-
controller = ProductsController.new
|
655
|
-
controller.request = OpenStruct.new(:host => 'example.com') # mocking request
|
656
|
-
%w(product_path product_url product_es_path product_es_url product_native_es_path product_native_es_url).each do |method|
|
657
|
-
begin
|
658
|
-
controller.send(method)
|
659
|
-
rescue Exception => e
|
660
|
-
raise e if e.is_a?(NameError) #swallow anything that isn't a NameError
|
661
|
-
end
|
662
|
-
end
|
663
|
-
end
|
664
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
|
2
|
-
module RouteTranslator
|
3
|
-
module AssertionHelper
|
4
|
-
|
5
|
-
def assert_helpers_include(*helpers)
|
6
|
-
controller = ActionController::Base.new
|
7
|
-
view = ActionView::Base.new
|
8
|
-
helpers.each do |helper|
|
9
|
-
['url', 'path'].each do |suffix|
|
10
|
-
[controller, view].each { |obj| assert_respond_to obj, "#{helper}_#{suffix}".to_sym }
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
# Hack for compatibility between Rails 4 and Rails 3
|
16
|
-
def assert_unrecognized_route(route_path, options)
|
17
|
-
assert_raise ActionController::RoutingError do
|
18
|
-
begin
|
19
|
-
assert_routing route_path, options
|
20
|
-
rescue Minitest::Assertion => m
|
21
|
-
raise ActionController::RoutingError.new("")
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
27
|
-
end
|