route_localize 0.0.6 → 0.0.7

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: 71415733575cefeedeb8338523cae61f714d1ad0
4
- data.tar.gz: 9474346a55e1550a207bbafef139d1f67d951526
3
+ metadata.gz: ac33fb44a9d0ae4cb2d20a38e66c3e5b01938b7b
4
+ data.tar.gz: 8377b6a2ca45e7e5d14afebf1322b33ebba48b40
5
5
  SHA512:
6
- metadata.gz: c4c0e481b655d884aa36ed9f57b5e1775bd476a31ff1db28039ba775c51414abb458297d52aa5aac81ef64adfdcd9e6584835b8e52b9cf3df54976a0cb83b17d
7
- data.tar.gz: cb3d42d8a54da22d5f5fc627e2fd1e82479dfc8289d8398702934c6b907ffc9ef33dbe8870cc1d1bb01bf873130ed31039eb04d84133c1d815ae7d6c9abd1f9f
6
+ metadata.gz: c7d9a28eed03ce3429a45d240acd304c215761608b5494e5c1a0bb2aac9bd7c00120d52775de6fda8d37379c016b5de09a3169526281f766e0268059a5a7eb13
7
+ data.tar.gz: e9fd2c544fd8fd7eb98dfc401849fe222cb6073189f96a24412446887c7c7e0a717c71c59546d8efefeb8d3bbb606135bdfd4761f1e33c055666caec2ffc4880
data/README.md CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  Rails 4 engine to translate routes using locale files and subdomains.
4
4
 
5
+
5
6
  ## Install
6
7
 
7
8
  In your Rails application's `Gemfile` add:
@@ -16,6 +17,7 @@ Install the plugin by running:
16
17
  $ bundle
17
18
  ```
18
19
 
20
+
19
21
  ## Usage
20
22
 
21
23
  In your `config/routes.rb`, localize the routes you want by surrounding them with a scope. For example:
@@ -64,6 +66,7 @@ You can then use the `locale_switch_url` helper in your views:
64
66
  <%= link_to "en", locale_switch_url("en") %>
65
67
  ```
66
68
 
69
+
67
70
  ### Change the parameters in your switcher
68
71
 
69
72
  If your params are different depending on the language, you can override
@@ -100,7 +103,17 @@ Then you would need to add this inside your controller:
100
103
 
101
104
  ## Caveats
102
105
 
103
- - Tests are missing for the `locale_switch_url`.
106
+ - Tests are missing for the `locale_switch_url` helper.
107
+ - Rails' `url_for` cannot find the translation, prefer to use the `_path` and
108
+ `_url` methods instead. If you can't, one way around is to use
109
+ `RouteLocalize.translate_path`.
110
+
111
+ For example :
112
+
113
+ ```ruby
114
+ url = url_for(controller: 'trees', action: 'index')
115
+ url = RouteLocalize.translate_path(url, I18n.locale)
116
+ ```
104
117
 
105
118
 
106
119
  ## Development
@@ -14,26 +14,14 @@ module RouteLocalize
14
14
 
15
15
  locales = defaults.delete(:localize)
16
16
  locales.each do |locale|
17
- # Name
18
- locale_as = "#{as}_#{locale}"
19
- locale_as = nil if route_set.named_routes.routes[locale_as.to_sym]
20
-
21
- # Path
22
- locale_conditions = conditions.dup
23
- locale_conditions[:path_info] = translate_path(locale_conditions[:path_info], locale)
24
- locale_conditions[:subdomain] = locale.to_s
25
- locale_conditions[:required_defaults] = locale_conditions[:required_defaults].reject { |l| l == :localize }
26
-
27
- # Other arguments
28
- locale_defaults = defaults.merge(subdomain: locale.to_s)
29
-
30
- yield app, locale_conditions, requirements, locale_defaults, locale_as, anchor
17
+ yield *route_args_for_locale(locale, app, conditions, requirements, defaults, as, anchor, route_set)
31
18
  end
32
19
 
33
20
  define_locale_helpers(as, route_set.named_routes.module)
34
21
  else
35
22
  yield app, conditions, requirements, defaults, as, anchor
36
23
  end
24
+
37
25
  end
38
26
 
39
27
  # Create _path and _url helpers for the given path name
@@ -46,6 +34,19 @@ module RouteLocalize
46
34
  end
47
35
  end
48
36
 
37
+ # Translate a path
38
+ def translate_path(path, locale)
39
+ path = path.dup
40
+
41
+ # Remove "(.:format)" in routes or "?args" if used elsewhere
42
+ final_options = path.slice!(/(\(.+\)|\?.*)$/)
43
+
44
+ segments = path.split('/').map do |segment|
45
+ translate_segment(segment, locale)
46
+ end
47
+ "#{segments.join('/')}#{final_options}"
48
+ end
49
+
49
50
  # Translate part of a path
50
51
  def translate_segment(segment, locale)
51
52
  if segment =~ /^[a-z_0-9]+$/i
@@ -56,14 +57,23 @@ module RouteLocalize
56
57
  end
57
58
  end
58
59
 
59
- # Translate a path
60
- def translate_path(path, locale)
61
- path = path.dup
62
- final_options = path.slice!(/(\(.+\))$/) # Removes "(.:format)"
63
- segments = path.split('/').map do |segment|
64
- translate_segment(segment, locale)
65
- end
66
- "#{segments.join('/')}#{final_options}"
67
- end
68
60
 
61
+ private
62
+
63
+ def route_args_for_locale(locale, app, conditions, requirements, defaults, as, anchor, route_set)
64
+ # Name
65
+ locale_as = "#{as}_#{locale}"
66
+ locale_as = nil if route_set.named_routes.routes[locale_as.to_sym]
67
+
68
+ # Path
69
+ locale_conditions = conditions.dup
70
+ locale_conditions[:path_info] = translate_path(locale_conditions[:path_info], locale)
71
+ locale_conditions[:subdomain] = locale.to_s
72
+ locale_conditions[:required_defaults] = locale_conditions[:required_defaults].reject { |l| l == :localize }
73
+
74
+ # Other arguments
75
+ locale_defaults = defaults.merge(subdomain: locale.to_s)
76
+
77
+ [app, locale_conditions, requirements, locale_defaults, locale_as, anchor]
78
+ end
69
79
  end
@@ -3,7 +3,6 @@ module ActionDispatch
3
3
  class RouteSet
4
4
  def add_route_with_locale(app, conditions = {}, requirements = {}, defaults = {}, as = nil, anchor = true)
5
5
  RouteLocalize.translate_route(app, conditions, requirements, defaults, as, anchor, self) do |*args|
6
- # puts "#{$route} #{args.inspect}"
7
6
  add_route_without_locale *args
8
7
  end
9
8
  end
@@ -1,3 +1,3 @@
1
1
  module RouteLocalize
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -1,16 +1,25 @@
1
1
  class TreesController < ApplicationController
2
2
  def home
3
+ render text: 'home'
3
4
  end
4
5
 
5
6
  def show
7
+ render text: 'show'
6
8
  end
7
9
 
8
10
  def create
11
+ render text: 'create'
12
+ end
13
+
14
+ def edit
15
+ render text: 'edit'
9
16
  end
10
17
 
11
18
  def update
19
+ render text: 'update'
12
20
  end
13
21
 
14
22
  def index
23
+ render text: 'index'
15
24
  end
16
25
  end
@@ -0,0 +1,18 @@
1
+ # Object that acts like a routeable ActiveRecord model
2
+ class Tree
3
+ def initialize(attributes)
4
+ @attributes = attributes
5
+ end
6
+
7
+ def to_param
8
+ @attributes[:id]
9
+ end
10
+
11
+ def self.model_name
12
+ self
13
+ end
14
+
15
+ def self.singular_route_key
16
+ "tree"
17
+ end
18
+ end
@@ -38,3 +38,343 @@ RoutesTest: test_generates_named_paths_for_each_locale
38
38
  RoutesTest: test_generates_paths_depending_on_subdomain
39
39
  -------------------------------------------------------
40
40
   (0.1ms) rollback transaction
41
+  (0.2ms) begin transaction
42
+ --------------------------------------------
43
+ RouteLocalizeTest: test_RouteLocalize_exists
44
+ --------------------------------------------
45
+  (0.0ms) rollback transaction
46
+  (0.0ms) begin transaction
47
+ --------------------------------------------------------------------------------
48
+ RoutesTest: test_generates_generic_named_paths_that_depend_on_the_current_locale
49
+ --------------------------------------------------------------------------------
50
+  (0.0ms) rollback transaction
51
+  (0.0ms) begin transaction
52
+ ------------------------------------------------------
53
+ RoutesTest: test_generates_named_paths_for_each_locale
54
+ ------------------------------------------------------
55
+  (0.0ms) rollback transaction
56
+  (0.0ms) begin transaction
57
+ -------------------------------------------------------
58
+ RoutesTest: test_generates_paths_depending_on_subdomain
59
+ -------------------------------------------------------
60
+  (0.1ms) rollback transaction
61
+  (0.2ms) begin transaction
62
+ --------------------------------------------
63
+ RouteLocalizeTest: test_RouteLocalize_exists
64
+ --------------------------------------------
65
+  (0.0ms) rollback transaction
66
+  (0.0ms) begin transaction
67
+ --------------------------------------------------------------------------------
68
+ RoutesTest: test_generates_generic_named_paths_that_depend_on_the_current_locale
69
+ --------------------------------------------------------------------------------
70
+  (0.0ms) rollback transaction
71
+  (0.0ms) begin transaction
72
+ ------------------------------------------------------
73
+ RoutesTest: test_generates_named_paths_for_each_locale
74
+ ------------------------------------------------------
75
+  (0.0ms) rollback transaction
76
+  (0.0ms) begin transaction
77
+ -------------------------------------------------------
78
+ RoutesTest: test_generates_paths_depending_on_subdomain
79
+ -------------------------------------------------------
80
+  (0.1ms) rollback transaction
81
+  (0.2ms) begin transaction
82
+ --------------------------------------------
83
+ RouteLocalizeTest: test_RouteLocalize_exists
84
+ --------------------------------------------
85
+  (0.0ms) rollback transaction
86
+  (0.0ms) begin transaction
87
+ --------------------------------------------------------------------------------
88
+ RoutesTest: test_generates_generic_named_paths_that_depend_on_the_current_locale
89
+ --------------------------------------------------------------------------------
90
+  (0.1ms) rollback transaction
91
+  (0.0ms) begin transaction
92
+ ------------------------------------------------------
93
+ RoutesTest: test_generates_named_paths_for_each_locale
94
+ ------------------------------------------------------
95
+  (0.1ms) rollback transaction
96
+  (0.0ms) begin transaction
97
+ -------------------------------------------------------
98
+ RoutesTest: test_generates_paths_depending_on_subdomain
99
+ -------------------------------------------------------
100
+  (0.0ms) rollback transaction
101
+  (0.2ms) begin transaction
102
+ --------------------------------------------
103
+ RouteLocalizeTest: test_RouteLocalize_exists
104
+ --------------------------------------------
105
+  (0.0ms) rollback transaction
106
+  (0.1ms) begin transaction
107
+ --------------------------------------------------------------------------------
108
+ RoutesTest: test_generates_generic_named_paths_that_depend_on_the_current_locale
109
+ --------------------------------------------------------------------------------
110
+  (0.1ms) rollback transaction
111
+  (0.0ms) begin transaction
112
+ ------------------------------------------------------
113
+ RoutesTest: test_generates_named_paths_for_each_locale
114
+ ------------------------------------------------------
115
+  (0.0ms) rollback transaction
116
+  (0.0ms) begin transaction
117
+ -------------------------------------------------------
118
+ RoutesTest: test_generates_paths_depending_on_subdomain
119
+ -------------------------------------------------------
120
+  (0.1ms) rollback transaction
121
+  (0.2ms) begin transaction
122
+ --------------------------------------------
123
+ RouteLocalizeTest: test_RouteLocalize_exists
124
+ --------------------------------------------
125
+  (0.1ms) rollback transaction
126
+  (0.0ms) begin transaction
127
+ --------------------------------------------------------------------------------
128
+ RoutesTest: test_generates_generic_named_paths_that_depend_on_the_current_locale
129
+ --------------------------------------------------------------------------------
130
+  (0.0ms) rollback transaction
131
+  (0.0ms) begin transaction
132
+ ------------------------------------------------------
133
+ RoutesTest: test_generates_named_paths_for_each_locale
134
+ ------------------------------------------------------
135
+  (0.0ms) rollback transaction
136
+  (0.0ms) begin transaction
137
+ -------------------------------------------------------
138
+ RoutesTest: test_generates_paths_depending_on_subdomain
139
+ -------------------------------------------------------
140
+  (0.1ms) rollback transaction
141
+  (0.2ms) begin transaction
142
+ -----------------------------------------------
143
+ RouteLocalizeHelperTest: test_locale_switch_url
144
+ -----------------------------------------------
145
+  (0.0ms) rollback transaction
146
+  (0.0ms) begin transaction
147
+ --------------------------------------------
148
+ RouteLocalizeTest: test_RouteLocalize_exists
149
+ --------------------------------------------
150
+  (0.0ms) rollback transaction
151
+  (0.0ms) begin transaction
152
+ --------------------------------------------------------------------------------
153
+ RoutesTest: test_generates_generic_named_paths_that_depend_on_the_current_locale
154
+ --------------------------------------------------------------------------------
155
+  (0.1ms) rollback transaction
156
+  (0.0ms) begin transaction
157
+ ------------------------------------------------------
158
+ RoutesTest: test_generates_named_paths_for_each_locale
159
+ ------------------------------------------------------
160
+  (0.0ms) rollback transaction
161
+  (0.1ms) begin transaction
162
+ -------------------------------------------------------
163
+ RoutesTest: test_generates_paths_depending_on_subdomain
164
+ -------------------------------------------------------
165
+  (0.1ms) rollback transaction
166
+  (0.2ms) begin transaction
167
+ -----------------------------------------------
168
+ RouteLocalizeHelperTest: test_locale_switch_url
169
+ -----------------------------------------------
170
+  (0.0ms) rollback transaction
171
+  (0.0ms) begin transaction
172
+ --------------------------------------------
173
+ RouteLocalizeTest: test_RouteLocalize_exists
174
+ --------------------------------------------
175
+  (0.0ms) rollback transaction
176
+  (0.0ms) begin transaction
177
+ --------------------------------------------------------------------------------
178
+ RoutesTest: test_generates_generic_named_paths_that_depend_on_the_current_locale
179
+ --------------------------------------------------------------------------------
180
+  (0.1ms) rollback transaction
181
+  (0.0ms) begin transaction
182
+ ------------------------------------------------------
183
+ RoutesTest: test_generates_named_paths_for_each_locale
184
+ ------------------------------------------------------
185
+  (0.1ms) rollback transaction
186
+  (0.0ms) begin transaction
187
+ -------------------------------------------------------
188
+ RoutesTest: test_generates_paths_depending_on_subdomain
189
+ -------------------------------------------------------
190
+  (0.1ms) rollback transaction
191
+  (0.2ms) begin transaction
192
+ -----------------------------------------------
193
+ RouteLocalizeHelperTest: test_locale_switch_url
194
+ -----------------------------------------------
195
+  (0.0ms) rollback transaction
196
+  (0.0ms) begin transaction
197
+ --------------------------------------------
198
+ RouteLocalizeTest: test_RouteLocalize_exists
199
+ --------------------------------------------
200
+  (0.0ms) rollback transaction
201
+  (0.0ms) begin transaction
202
+ --------------------------------------------------------------------------------
203
+ RoutesTest: test_generates_generic_named_paths_that_depend_on_the_current_locale
204
+ --------------------------------------------------------------------------------
205
+  (0.1ms) rollback transaction
206
+  (0.0ms) begin transaction
207
+ ------------------------------------------------------
208
+ RoutesTest: test_generates_named_paths_for_each_locale
209
+ ------------------------------------------------------
210
+  (0.1ms) rollback transaction
211
+  (0.0ms) begin transaction
212
+ -------------------------------------------------------
213
+ RoutesTest: test_generates_paths_depending_on_subdomain
214
+ -------------------------------------------------------
215
+  (0.1ms) rollback transaction
216
+  (0.2ms) begin transaction
217
+ -----------------------------------------------
218
+ RouteLocalizeHelperTest: test_locale_switch_url
219
+ -----------------------------------------------
220
+  (0.1ms) rollback transaction
221
+  (0.0ms) begin transaction
222
+ --------------------------------------------
223
+ RouteLocalizeTest: test_RouteLocalize_exists
224
+ --------------------------------------------
225
+  (0.0ms) rollback transaction
226
+  (0.0ms) begin transaction
227
+ --------------------------------------------------------------------------------
228
+ RoutesTest: test_generates_generic_named_paths_that_depend_on_the_current_locale
229
+ --------------------------------------------------------------------------------
230
+  (0.1ms) rollback transaction
231
+  (0.1ms) begin transaction
232
+ ------------------------------------------------------
233
+ RoutesTest: test_generates_named_paths_for_each_locale
234
+ ------------------------------------------------------
235
+  (0.1ms) rollback transaction
236
+  (0.0ms) begin transaction
237
+ -------------------------------------------------------
238
+ RoutesTest: test_generates_paths_depending_on_subdomain
239
+ -------------------------------------------------------
240
+  (0.1ms) rollback transaction
241
+  (0.1ms) begin transaction
242
+ --------------------------------------------------------------------------------
243
+ RoutesTest: test_generates_generic_named_paths_that_depend_on_the_current_locale
244
+ --------------------------------------------------------------------------------
245
+  (0.0ms) rollback transaction
246
+  (0.0ms) begin transaction
247
+ ------------------------------------------------------
248
+ RoutesTest: test_generates_named_paths_for_each_locale
249
+ ------------------------------------------------------
250
+  (0.0ms) rollback transaction
251
+  (0.0ms) begin transaction
252
+ -------------------------------------------------------
253
+ RoutesTest: test_generates_paths_depending_on_subdomain
254
+ -------------------------------------------------------
255
+  (0.1ms) rollback transaction
256
+  (0.0ms) begin transaction
257
+ --------------------------------------------
258
+ RouteLocalizeTest: test_RouteLocalize_exists
259
+ --------------------------------------------
260
+  (0.0ms) rollback transaction
261
+  (0.1ms) begin transaction
262
+ --------------------------------------------
263
+ RouteLocalizeTest: test_RouteLocalize_exists
264
+ --------------------------------------------
265
+  (0.0ms) rollback transaction
266
+  (0.0ms) begin transaction
267
+ --------------------------------------
268
+ RouteLocalizeTest: test_translate_path
269
+ --------------------------------------
270
+  (0.0ms) rollback transaction
271
+  (0.1ms) begin transaction
272
+ --------------------------------------------------------------------------------
273
+ RoutesTest: test_generates_generic_named_paths_that_depend_on_the_current_locale
274
+ --------------------------------------------------------------------------------
275
+  (0.1ms) rollback transaction
276
+  (0.0ms) begin transaction
277
+ ------------------------------------------------------
278
+ RoutesTest: test_generates_named_paths_for_each_locale
279
+ ------------------------------------------------------
280
+  (0.0ms) rollback transaction
281
+  (0.0ms) begin transaction
282
+ -------------------------------------------------------
283
+ RoutesTest: test_generates_paths_depending_on_subdomain
284
+ -------------------------------------------------------
285
+  (0.1ms) rollback transaction
286
+  (0.0ms) begin transaction
287
+ --------------------------------------------
288
+ RouteLocalizeTest: test_RouteLocalize_exists
289
+ --------------------------------------------
290
+  (0.0ms) rollback transaction
291
+  (0.0ms) begin transaction
292
+ --------------------------------------
293
+ RouteLocalizeTest: test_translate_path
294
+ --------------------------------------
295
+  (0.0ms) rollback transaction
296
+  (0.1ms) begin transaction
297
+ --------------------------------------------
298
+ RouteLocalizeTest: test_RouteLocalize_exists
299
+ --------------------------------------------
300
+  (0.0ms) rollback transaction
301
+  (0.0ms) begin transaction
302
+ --------------------------------------
303
+ RouteLocalizeTest: test_translate_path
304
+ --------------------------------------
305
+  (0.0ms) rollback transaction
306
+  (0.1ms) begin transaction
307
+ --------------------------------------------
308
+ RouteLocalizeTest: test_RouteLocalize_exists
309
+ --------------------------------------------
310
+  (0.0ms) rollback transaction
311
+  (0.0ms) begin transaction
312
+ --------------------------------------
313
+ RouteLocalizeTest: test_translate_path
314
+ --------------------------------------
315
+  (0.0ms) rollback transaction
316
+  (0.1ms) begin transaction
317
+ --------------------------------------------
318
+ RouteLocalizeTest: test_RouteLocalize_exists
319
+ --------------------------------------------
320
+  (0.0ms) rollback transaction
321
+  (0.0ms) begin transaction
322
+ --------------------------------------
323
+ RouteLocalizeTest: test_translate_path
324
+ --------------------------------------
325
+  (0.0ms) rollback transaction
326
+  (0.1ms) begin transaction
327
+ --------------------------------------------
328
+ RouteLocalizeTest: test_RouteLocalize_exists
329
+ --------------------------------------------
330
+  (0.0ms) rollback transaction
331
+  (0.0ms) begin transaction
332
+ --------------------------------------
333
+ RouteLocalizeTest: test_translate_path
334
+ --------------------------------------
335
+  (0.0ms) rollback transaction
336
+  (0.1ms) begin transaction
337
+ --------------------------------------------
338
+ RouteLocalizeTest: test_RouteLocalize_exists
339
+ --------------------------------------------
340
+  (0.0ms) rollback transaction
341
+  (0.0ms) begin transaction
342
+ --------------------------------------
343
+ RouteLocalizeTest: test_translate_path
344
+ --------------------------------------
345
+  (0.0ms) rollback transaction
346
+  (0.1ms) begin transaction
347
+ --------------------------------------------
348
+ RouteLocalizeTest: test_RouteLocalize_exists
349
+ --------------------------------------------
350
+  (0.0ms) rollback transaction
351
+  (0.0ms) begin transaction
352
+ --------------------------------------
353
+ RouteLocalizeTest: test_translate_path
354
+ --------------------------------------
355
+  (0.0ms) rollback transaction
356
+  (0.1ms) begin transaction
357
+ --------------------------------------------------------------------------------
358
+ RoutesTest: test_generates_generic_named_paths_that_depend_on_the_current_locale
359
+ --------------------------------------------------------------------------------
360
+  (0.0ms) rollback transaction
361
+  (0.0ms) begin transaction
362
+ ------------------------------------------------------
363
+ RoutesTest: test_generates_named_paths_for_each_locale
364
+ ------------------------------------------------------
365
+  (0.0ms) rollback transaction
366
+  (0.0ms) begin transaction
367
+ -------------------------------------------------------
368
+ RoutesTest: test_generates_paths_depending_on_subdomain
369
+ -------------------------------------------------------
370
+  (0.1ms) rollback transaction
371
+  (0.0ms) begin transaction
372
+ --------------------------------------------
373
+ RouteLocalizeTest: test_RouteLocalize_exists
374
+ --------------------------------------------
375
+  (0.0ms) rollback transaction
376
+  (0.0ms) begin transaction
377
+ ---------------------------------------------------------------
378
+ RouteLocalizeTest: test_translate_path_should_not_change_routes
379
+ ---------------------------------------------------------------
380
+  (0.0ms) rollback transaction
@@ -2,21 +2,7 @@
2
2
  require 'test_helper'
3
3
 
4
4
  class RoutesTest < ActionDispatch::IntegrationTest
5
- fixtures :all
6
-
7
- # Mock object that acts like a routeable ActiveRecord model
8
- class FakeTree
9
- attr_reader :to_param
10
- def initialize(to_param)
11
- @to_param = to_param
12
- end
13
- def self.model_name
14
- self
15
- end
16
- def self.singular_route_key
17
- "tree"
18
- end
19
- end
5
+ # fixtures :all
20
6
 
21
7
  include ActionDispatch::Routing::UrlFor
22
8
  include Rails.application.routes.url_helpers
@@ -42,14 +28,16 @@ class RoutesTest < ActionDispatch::IntegrationTest
42
28
  assert_equal "/home", home_path
43
29
  assert_equal "/trees/planting", new_tree_path
44
30
  assert_equal "/trees/42", tree_path(42)
45
- assert_equal "http://en.example.com/trees/42", url_for(FakeTree.new(42))
31
+ assert_equal "/trees/42/edit", edit_tree_path(42)
32
+ assert_equal "http://en.example.com/trees/42", url_for(Tree.new(id: 42))
46
33
  assert_equal "/default", default_path
47
34
 
48
35
  I18n.locale = :fr
49
36
  assert_equal "/accueil", home_path
50
37
  assert_equal "/arbres/planter", new_tree_path
51
38
  assert_equal "/arbres/42", tree_path(42)
52
- assert_equal "http://fr.example.com/arbres/42", url_for(FakeTree.new(42))
39
+ assert_equal "/arbres/42/%C3%A9diter", edit_tree_path(42)
40
+ assert_equal "http://fr.example.com/arbres/42", url_for(Tree.new(id: 42))
53
41
  assert_equal "/default", default_path
54
42
  end
55
43
 
@@ -60,14 +48,15 @@ class RoutesTest < ActionDispatch::IntegrationTest
60
48
  { subdomain: "en" })
61
49
 
62
50
  # fr
63
- assert_recognizes({ controller: "trees", action: "show", subdomain: "fr", id: "42" },
64
- "http://fr.lacolhost.com/arbres/42",
65
- { subdomain: "fr" })
66
- # FIXME
67
- # Rails always seems to generate /trees/42 instead
51
+
52
+ # FIXME : assert_routing points to /trees/42
68
53
  # assert_routing("http://fr.lacolhost.com/arbres/42",
69
54
  # { controller: "trees", action: "show", subdomain: "fr", id: "42" },
70
55
  # subdomain: "fr")
56
+
57
+ assert_recognizes({ controller: "trees", action: "show", subdomain: "fr", id: "42" },
58
+ "http://fr.lacolhost.com/arbres/42",
59
+ { subdomain: "fr" })
71
60
  end
72
61
 
73
62
  end
@@ -4,4 +4,9 @@ class RouteLocalizeTest < ActiveSupport::TestCase
4
4
  test "RouteLocalize exists" do
5
5
  assert_kind_of Module, RouteLocalize
6
6
  end
7
+
8
+ test "translate_path should not change routes" do
9
+ assert_equal "/a(:b)", RouteLocalize.translate_path("/a(:b)", "fr")
10
+ assert_equal "/a?b=c", RouteLocalize.translate_path("/a?b=c", "fr")
11
+ end
7
12
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: route_localize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sunny Ripert
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-03 00:00:00.000000000 Z
11
+ date: 2014-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -59,6 +59,7 @@ files:
59
59
  - test/dummy/app/controllers/application_controller.rb
60
60
  - test/dummy/app/controllers/trees_controller.rb
61
61
  - test/dummy/app/helpers/application_helper.rb
62
+ - test/dummy/app/models/tree.rb
62
63
  - test/dummy/app/views/layouts/application.html.erb
63
64
  - test/dummy/app/views/trees/home.html.erb
64
65
  - test/dummy/bin/bundle
@@ -123,6 +124,7 @@ test_files:
123
124
  - test/dummy/app/controllers/application_controller.rb
124
125
  - test/dummy/app/controllers/trees_controller.rb
125
126
  - test/dummy/app/helpers/application_helper.rb
127
+ - test/dummy/app/models/tree.rb
126
128
  - test/dummy/app/views/layouts/application.html.erb
127
129
  - test/dummy/app/views/trees/home.html.erb
128
130
  - test/dummy/bin/bundle