js-routes 2.2.3 → 2.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Readme.md +1 -1
- data/lib/js_routes/generators/middleware.rb +1 -1
- data/lib/js_routes/instance.rb +1 -1
- data/lib/js_routes/middleware.rb +6 -2
- data/lib/js_routes/version.rb +1 -1
- data/lib/routes.d.ts +1 -0
- data/lib/routes.js +13 -2
- data/lib/routes.ts +12 -2
- data/spec/js_routes/default_serializer_spec.rb +4 -4
- data/spec/js_routes/module_types/amd_spec.rb +1 -1
- data/spec/js_routes/module_types/cjs_spec.rb +1 -1
- data/spec/js_routes/module_types/dts/routes.spec.d.ts +1 -0
- data/spec/js_routes/module_types/esm_spec.rb +2 -2
- data/spec/js_routes/module_types/nil_spec.rb +7 -7
- data/spec/js_routes/options_spec.rb +79 -79
- data/spec/js_routes/rails_routes_compatibility_spec.rb +123 -136
- data/spec/js_routes/route_specification_spec.rb +40 -0
- data/spec/spec_helper.rb +4 -0
- metadata +3 -2
@@ -10,11 +10,11 @@ describe JsRoutes, "compatibility with Rails" do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
it "should generate collection routing" do
|
13
|
-
|
13
|
+
expectjs("Routes.inboxes_path()").to eq(test_routes.inboxes_path())
|
14
14
|
end
|
15
15
|
|
16
16
|
it "should generate member routing" do
|
17
|
-
|
17
|
+
expectjs("Routes.inbox_path(1)").to eq(test_routes.inbox_path(1))
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should raise error if required argument is not passed", :aggregate_failures do
|
@@ -27,8 +27,8 @@ describe JsRoutes, "compatibility with Rails" do
|
|
27
27
|
expect { evaljs("Routes.book_title_path()") }
|
28
28
|
.to raise_error(/Route missing required keys: title/)
|
29
29
|
|
30
|
-
|
31
|
-
|
30
|
+
expectjs("try {Routes.thing_path()} catch (e) { e.name }") .to eq('ParametersMissing')
|
31
|
+
expectjs("try {Routes.thing_path()} catch (e) { e.keys }") .to eq(['id'])
|
32
32
|
end
|
33
33
|
|
34
34
|
it "should produce error stacktraces including function names" do
|
@@ -45,129 +45,145 @@ describe JsRoutes, "compatibility with Rails" do
|
|
45
45
|
end
|
46
46
|
|
47
47
|
it "should support 0 as a member parameter" do
|
48
|
-
|
48
|
+
expectjs("Routes.inbox_path(0)").to eq(test_routes.inbox_path(0))
|
49
49
|
end
|
50
50
|
|
51
51
|
it "should generate nested routing with one parameter" do
|
52
|
-
|
52
|
+
expectjs("Routes.inbox_messages_path(1)").to eq(test_routes.inbox_messages_path(1))
|
53
53
|
end
|
54
54
|
|
55
55
|
it "should generate nested routing" do
|
56
|
-
|
56
|
+
expectjs("Routes.inbox_message_path(1,2)").to eq(test_routes.inbox_message_path(1, 2))
|
57
57
|
end
|
58
58
|
|
59
59
|
it "should generate routing with format" do
|
60
|
-
|
60
|
+
expectjs("Routes.inbox_path(1, {format: 'json'})").to eq(test_routes.inbox_path(1, :format => "json"))
|
61
61
|
end
|
62
62
|
|
63
63
|
it "should support routes with reserved javascript words as parameters" do
|
64
|
-
|
64
|
+
expectjs("Routes.object_path(1, 2)").to eq(test_routes.object_path(1,2))
|
65
65
|
end
|
66
66
|
|
67
67
|
it "should support routes with trailing_slash" do
|
68
|
-
|
68
|
+
expectjs("Routes.inbox_path(1, {trailing_slash: true})").to eq(test_routes.inbox_path(1, trailing_slash: true))
|
69
69
|
end
|
70
70
|
|
71
71
|
it "should support url anchor given as parameter" do
|
72
|
-
|
72
|
+
expectjs("Routes.inbox_path(1, {anchor: 'hello'})").to eq(test_routes.inbox_path(1, :anchor => "hello"))
|
73
73
|
end
|
74
74
|
|
75
75
|
it "should support url anchor and get parameters" do
|
76
|
-
|
76
|
+
expectjs("Routes.inbox_path(1, {expanded: true, anchor: 'hello'})").to eq(test_routes.inbox_path(1, :expanded => true, :anchor => "hello"))
|
77
77
|
end
|
78
78
|
|
79
79
|
it "should support required parameters given as options hash" do
|
80
|
-
|
80
|
+
expectjs("Routes.search_path({q: 'hello'})").to eq(test_routes.search_path(:q => 'hello'))
|
81
81
|
end
|
82
82
|
|
83
83
|
it "should use irregular ActiveSupport pluralizations" do
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
84
|
+
expectjs("Routes.budgies_path()").to eq(test_routes.budgies_path)
|
85
|
+
expectjs("Routes.budgie_path(1)").to eq(test_routes.budgie_path(1))
|
86
|
+
expectjs("Routes.budgy_path").to eq(nil)
|
87
|
+
expectjs("Routes.budgie_descendents_path(1)").to eq(test_routes.budgie_descendents_path(1))
|
88
88
|
end
|
89
89
|
|
90
90
|
it "should support route with parameters containing symbols that need URI-encoding", :aggregate_failures do
|
91
|
-
|
92
|
-
|
93
|
-
|
91
|
+
expectjs("Routes.inbox_path('#hello')").to eq(test_routes.inbox_path('#hello'))
|
92
|
+
expectjs("Routes.inbox_path('some param')").to eq(test_routes.inbox_path('some param'))
|
93
|
+
expectjs("Routes.inbox_path('some param with more & more encode symbols')").to eq(test_routes.inbox_path('some param with more & more encode symbols'))
|
94
94
|
end
|
95
95
|
it "should support route with parameters containing symbols not need URI-encoding", :aggregate_failures do
|
96
|
-
|
97
|
-
|
96
|
+
expectjs("Routes.inbox_path(':some_id')").to eq(test_routes.inbox_path(':some_id'))
|
97
|
+
expectjs("Routes.inbox_path('.+')").to eq(test_routes.inbox_path('.+'))
|
98
98
|
end
|
99
99
|
|
100
100
|
describe "when route has defaults" do
|
101
101
|
it "should support route default format" do
|
102
|
-
|
102
|
+
expectjs("Routes.api_purchases_path()").to eq(test_routes.api_purchases_path)
|
103
103
|
end
|
104
104
|
|
105
105
|
it 'should support route default subdomain' do
|
106
|
-
|
106
|
+
expectjs("Routes.backend_root_path()").to eq(test_routes.backend_root_path)
|
107
107
|
end
|
108
108
|
|
109
109
|
it "should support default format override" do
|
110
|
-
|
110
|
+
expectjs("Routes.api_purchases_path({format: 'xml'})").to eq(test_routes.api_purchases_path(format: 'xml'))
|
111
111
|
end
|
112
112
|
|
113
113
|
it "should support default format override by passing it in args" do
|
114
|
-
|
114
|
+
expectjs("Routes.api_purchases_path('xml')").to eq(test_routes.api_purchases_path('xml'))
|
115
115
|
end
|
116
116
|
|
117
117
|
it "doesn't apply defaults to path" do
|
118
|
-
|
119
|
-
|
118
|
+
expectjs("Routes.with_defaults_path()").to eq(test_routes.with_defaults_path)
|
119
|
+
expectjs("Routes.with_defaults_path({format: 'json'})").to eq(test_routes.with_defaults_path(format: 'json'))
|
120
120
|
end
|
121
121
|
end
|
122
122
|
|
123
123
|
context "with rails engines" do
|
124
124
|
it "should support simple route" do
|
125
|
-
|
125
|
+
expectjs("Routes.blog_app_posts_path()").to eq(blog_routes.posts_path())
|
126
126
|
end
|
127
127
|
|
128
128
|
it "should support root route" do
|
129
|
-
|
129
|
+
expectjs("Routes.blog_app_path()").to eq(test_routes.blog_app_path())
|
130
130
|
end
|
131
131
|
|
132
132
|
it "should support route with parameters" do
|
133
|
-
|
133
|
+
expectjs("Routes.blog_app_post_path(1)").to eq(blog_routes.post_path(1))
|
134
134
|
end
|
135
135
|
it "should support root path" do
|
136
|
-
|
136
|
+
expectjs("Routes.blog_app_root_path()").to eq(blog_routes.root_path)
|
137
137
|
end
|
138
138
|
it "should support single route mapping" do
|
139
|
-
|
139
|
+
expectjs("Routes.support_path({page: 3})").to eq(test_routes.support_path(:page => 3))
|
140
140
|
end
|
141
141
|
|
142
142
|
it 'works' do
|
143
|
-
|
144
|
-
|
143
|
+
expectjs("Routes.planner_manage_path({locale: 'ua'})").to eq(planner_routes.manage_path(locale: 'ua'))
|
144
|
+
expectjs("Routes.planner_manage_path()").to eq(planner_routes.manage_path)
|
145
145
|
end
|
146
146
|
end
|
147
147
|
|
148
148
|
it "shouldn't require the format" do
|
149
|
-
|
149
|
+
expectjs("Routes.json_only_path({format: 'json'})").to eq(test_routes.json_only_path(:format => 'json'))
|
150
150
|
end
|
151
151
|
|
152
152
|
it "should serialize object with empty string value" do
|
153
|
-
|
153
|
+
expectjs("Routes.inboxes_path({a: '', b: 1})").to eq(test_routes.inboxes_path(:a => '', :b => 1))
|
154
154
|
end
|
155
155
|
|
156
156
|
it "should support utf-8 route" do
|
157
|
-
|
157
|
+
expectjs("Routes.hello_path()").to eq(test_routes.hello_path)
|
158
158
|
end
|
159
159
|
|
160
160
|
it "should support root_path" do
|
161
|
-
|
161
|
+
expectjs("Routes.root_path()").to eq(test_routes.root_path)
|
162
|
+
end
|
163
|
+
|
164
|
+
describe "params parameter" do
|
165
|
+
it "works" do
|
166
|
+
expectjs("Routes.inboxes_path({params: {key: 'value'}})").to eq(test_routes.inboxes_path(params: {key: 'value'}))
|
167
|
+
end
|
168
|
+
|
169
|
+
it "allows keyword key as a query parameter" do
|
170
|
+
expectjs("Routes.inboxes_path({params: {anchor: 'a', params: 'p'}})").to eq(test_routes.inboxes_path(params: {anchor: 'a', params: 'p'}))
|
171
|
+
end
|
172
|
+
|
173
|
+
it "throws when value is not an object" do
|
174
|
+
expect {
|
175
|
+
evaljs("Routes.inboxes_path({params: 1})")
|
176
|
+
}.to raise_error(js_error_class)
|
177
|
+
end
|
162
178
|
end
|
163
179
|
|
164
180
|
describe "get parameters" do
|
165
181
|
it "should support simple get parameters" do
|
166
|
-
|
182
|
+
expectjs("Routes.inbox_path(1, {format: 'json', lang: 'ua', q: 'hello'})").to eq(test_routes.inbox_path(1, :lang => "ua", :q => "hello", :format => "json"))
|
167
183
|
end
|
168
184
|
|
169
185
|
it "should support array get parameters" do
|
170
|
-
|
186
|
+
expectjs("Routes.inbox_path(1, {hello: ['world', 'mars']})").to eq(test_routes.inbox_path(1, :hello => [:world, :mars]))
|
171
187
|
end
|
172
188
|
|
173
189
|
context "object without prototype" do
|
@@ -177,94 +193,94 @@ describe JsRoutes, "compatibility with Rails" do
|
|
177
193
|
end
|
178
194
|
|
179
195
|
it "should still work correctly" do
|
180
|
-
|
196
|
+
expectjs("Routes.inbox_path(inbox, params)").to eq(
|
181
197
|
test_routes.inbox_path(1, q: "hello")
|
182
198
|
)
|
183
199
|
end
|
184
200
|
end
|
185
201
|
|
186
202
|
it "should support nested get parameters" do
|
187
|
-
|
203
|
+
expectjs("Routes.inbox_path(1, {format: 'json', env: 'test', search: { category_ids: [2,5], q: 'hello'}})").to eq(
|
188
204
|
test_routes.inbox_path(1, :env => 'test', :search => {:category_ids => [2,5], :q => "hello"}, :format => "json")
|
189
205
|
)
|
190
206
|
end
|
191
207
|
|
192
208
|
it "should support null and undefined parameters" do
|
193
|
-
|
209
|
+
expectjs("Routes.inboxes_path({uri: null, key: undefined})").to eq(test_routes.inboxes_path(:uri => nil, :key => nil))
|
194
210
|
end
|
195
211
|
|
196
212
|
it "should escape get parameters" do
|
197
|
-
|
213
|
+
expectjs("Routes.inboxes_path({uri: 'http://example.com'})").to eq(test_routes.inboxes_path(:uri => 'http://example.com'))
|
198
214
|
end
|
199
215
|
|
200
216
|
it "should support nested object null parameters" do
|
201
|
-
|
217
|
+
expectjs("Routes.inboxes_path({hello: {world: null}})").to eq(test_routes.inboxes_path(:hello => {:world => nil}))
|
202
218
|
end
|
203
219
|
end
|
204
220
|
|
205
221
|
|
206
222
|
context "routes globbing" do
|
207
223
|
it "should be supported as parameters" do
|
208
|
-
|
224
|
+
expectjs("Routes.book_path('thrillers', 1)").to eq(test_routes.book_path('thrillers', 1))
|
209
225
|
end
|
210
226
|
|
211
227
|
it "should support routes globbing as array" do
|
212
|
-
|
228
|
+
expectjs("Routes.book_path(['thrillers'], 1)").to eq(test_routes.book_path(['thrillers'], 1))
|
213
229
|
end
|
214
230
|
|
215
231
|
it "should support routes globbing as array" do
|
216
|
-
|
232
|
+
expectjs("Routes.book_path([1, 2, 3], 1)").to eq(test_routes.book_path([1, 2, 3], 1))
|
217
233
|
end
|
218
234
|
|
219
235
|
it "should support routes globbing with slash" do
|
220
|
-
|
236
|
+
expectjs("Routes.book_path('a_test/b_test/c_test', 1)").to eq(test_routes.book_path('a_test/b_test/c_test', 1))
|
221
237
|
end
|
222
238
|
|
223
239
|
it "should support routes globbing as hash" do
|
224
|
-
|
240
|
+
expectjs("Routes.book_path('a%b', 1)").to eq(test_routes.book_path('a%b', 1))
|
225
241
|
end
|
226
242
|
|
227
243
|
it "should support routes globbing as array with optional params" do
|
228
|
-
|
244
|
+
expectjs("Routes.book_path([1, 2, 3, 5], 1, {c: '1'})").to eq(test_routes.book_path([1, 2, 3, 5], 1, { :c => "1" }))
|
229
245
|
end
|
230
246
|
|
231
247
|
it "should support routes globbing in book_title route as array" do
|
232
|
-
|
248
|
+
expectjs("Routes.book_title_path('john', ['thrillers', 'comedian'])").to eq(test_routes.book_title_path('john', ['thrillers', 'comedian']))
|
233
249
|
end
|
234
250
|
|
235
251
|
it "should support routes globbing in book_title route as array with optional params" do
|
236
|
-
|
252
|
+
expectjs("Routes.book_title_path('john', ['thrillers', 'comedian'], {some_key: 'some_value'})").to eq(test_routes.book_title_path('john', ['thrillers', 'comedian'], {:some_key => 'some_value'}))
|
237
253
|
end
|
238
254
|
end
|
239
255
|
|
240
256
|
context "using optional path fragments" do
|
241
257
|
context "including not optional parts" do
|
242
258
|
it "should include everything that is not optional" do
|
243
|
-
|
259
|
+
expectjs("Routes.foo_path()").to eq(test_routes.foo_path)
|
244
260
|
end
|
245
261
|
end
|
246
262
|
|
247
263
|
context "but not including them" do
|
248
264
|
it "should not include the optional parts" do
|
249
|
-
|
250
|
-
|
265
|
+
expectjs("Routes.things_path()").to eq(test_routes.things_path)
|
266
|
+
expectjs("Routes.things_path({ q: 'hello' })").to eq(test_routes.things_path(q: 'hello'))
|
251
267
|
end
|
252
268
|
|
253
269
|
it "treats false as absent optional part" do
|
254
270
|
pending("https://github.com/rails/rails/issues/42280")
|
255
|
-
|
271
|
+
expectjs("Routes.things_path(false)").to eq(test_routes.things_path(false))
|
256
272
|
end
|
257
273
|
|
258
274
|
it "treats false as absent optional part when default is specified" do
|
259
|
-
|
275
|
+
expectjs("Routes.campaigns_path(false)").to eq(test_routes.campaigns_path(false))
|
260
276
|
end
|
261
277
|
|
262
278
|
it "should not require the optional parts as arguments" do
|
263
|
-
|
279
|
+
expectjs("Routes.thing_path(null, 5)").to eq(test_routes.thing_path(nil, 5))
|
264
280
|
end
|
265
281
|
|
266
282
|
it "should treat undefined as non-given optional part" do
|
267
|
-
|
283
|
+
expectjs("Routes.thing_path(5, {optional_id: undefined})").to eq(test_routes.thing_path(5, :optional_id => nil))
|
268
284
|
end
|
269
285
|
|
270
286
|
it "should raise error when passing non-full list of arguments and some query params" do
|
@@ -273,15 +289,15 @@ describe JsRoutes, "compatibility with Rails" do
|
|
273
289
|
end
|
274
290
|
|
275
291
|
it "should treat null as non-given optional part" do
|
276
|
-
|
292
|
+
expectjs("Routes.thing_path(5, {optional_id: null})").to eq(test_routes.thing_path(5, :optional_id => nil))
|
277
293
|
end
|
278
294
|
|
279
295
|
it "should work when passing required params in options" do
|
280
|
-
|
296
|
+
expectjs("Routes.thing_deep_path({second_required: 1, third_required: 2})").to eq(test_routes.thing_deep_path(second_required: 1, third_required: 2))
|
281
297
|
end
|
282
298
|
|
283
299
|
it "should skip leading and trailing optional parts" do
|
284
|
-
|
300
|
+
expectjs("Routes.thing_deep_path(1, 2)").to eq(test_routes.thing_deep_path(1, 2))
|
285
301
|
end
|
286
302
|
end
|
287
303
|
|
@@ -291,30 +307,30 @@ describe JsRoutes, "compatibility with Rails" do
|
|
291
307
|
end
|
292
308
|
|
293
309
|
it "should include the optional parts" do
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
310
|
+
expectjs("Routes.things_path({optional_id: 5})").to eq(test_routes.things_path(:optional_id => 5))
|
311
|
+
expectjs("Routes.things_path(5)").to eq(test_routes.things_path(5))
|
312
|
+
expectjs("Routes.thing_deep_path(1, { third_required: 3, second_required: 2 })").to eq(test_routes.thing_deep_path(1, third_required: 3, second_required: 2))
|
313
|
+
expectjs("Routes.thing_deep_path(1, { third_required: 3, second_required: 2, forth_optional: 4 })").to eq(test_routes.thing_deep_path(1, third_required: 3, second_required: 2, forth_optional: 4))
|
314
|
+
expectjs("Routes.thing_deep_path(2, { third_required: 3, first_optional: 1 })").to eq(test_routes.thing_deep_path(2, third_required: 3, first_optional: 1))
|
315
|
+
expectjs("Routes.thing_deep_path(3, { first_optional: 1, second_required: 2 })").to eq(test_routes.thing_deep_path(3, first_optional: 1, second_required: 2))
|
316
|
+
expectjs("Routes.thing_deep_path(3, { first_optional: 1, second_required: 2, forth_optional: 4 })").to eq(test_routes.thing_deep_path(3, first_optional: 1, second_required: 2, forth_optional: 4))
|
317
|
+
expectjs("Routes.thing_deep_path(4, { first_optional: 1, second_required: 2, third_required: 3 })").to eq(test_routes.thing_deep_path(4, first_optional: 1, second_required: 2, third_required: 3))
|
318
|
+
expectjs("Routes.thing_deep_path(2, 3)").to eq(test_routes.thing_deep_path(2, 3))
|
319
|
+
expectjs("Routes.thing_deep_path(1, 2, { third_required: 3 })").to eq(test_routes.thing_deep_path(1, 2, third_required: 3))
|
320
|
+
expectjs("Routes.thing_deep_path(1,2, {third_required: 3, q: 'bogdan'})").to eq(test_routes.thing_deep_path(1,2, {third_required: 3, q: 'bogdan'}))
|
321
|
+
expectjs("Routes.thing_deep_path(1, 2, { forth_optional: 4, third_required: 3 })").to eq(test_routes.thing_deep_path(1, 2, forth_optional: 4, third_required: 3))
|
322
|
+
expectjs("Routes.thing_deep_path(1, 3, { second_required: 2 })").to eq(test_routes.thing_deep_path(1, 3, second_required: 2))
|
323
|
+
expectjs("Routes.thing_deep_path(1, 4, { second_required: 2, third_required: 3 })").to eq(test_routes.thing_deep_path(1, 4, second_required: 2, third_required: 3))
|
324
|
+
expectjs("Routes.thing_deep_path(2, 3, { first_optional: 1 })").to eq(test_routes.thing_deep_path(2, 3, first_optional: 1))
|
325
|
+
expectjs("Routes.thing_deep_path(2, 3, { first_optional: 1, forth_optional: 4 })").to eq(test_routes.thing_deep_path(2, 3, first_optional: 1, forth_optional: 4))
|
326
|
+
expectjs("Routes.thing_deep_path(2, 4, { first_optional: 1, third_required: 3 })").to eq(test_routes.thing_deep_path(2, 4, first_optional: 1, third_required: 3))
|
327
|
+
expectjs("Routes.thing_deep_path(3, 4, { first_optional: 1, second_required: 2 })").to eq(test_routes.thing_deep_path(3, 4, first_optional: 1, second_required: 2))
|
328
|
+
expectjs("Routes.thing_deep_path(1, 2, 3)").to eq(test_routes.thing_deep_path(1, 2, 3))
|
329
|
+
expectjs("Routes.thing_deep_path(1, 2, 3, { forth_optional: 4 })").to eq(test_routes.thing_deep_path(1, 2, 3, forth_optional: 4))
|
330
|
+
expectjs("Routes.thing_deep_path(1, 2, 4, { third_required: 3 })").to eq(test_routes.thing_deep_path(1, 2, 4, third_required: 3))
|
331
|
+
expectjs("Routes.thing_deep_path(1, 3, 4, { second_required: 2 })").to eq(test_routes.thing_deep_path(1, 3, 4, second_required: 2))
|
332
|
+
expectjs("Routes.thing_deep_path(2, 3, 4, { first_optional: 1 })").to eq(test_routes.thing_deep_path(2, 3, 4, first_optional: 1))
|
333
|
+
expectjs("Routes.thing_deep_path(1, 2, 3, 4)").to eq(test_routes.thing_deep_path(1, 2, 3, 4))
|
318
334
|
|
319
335
|
end
|
320
336
|
|
@@ -322,7 +338,7 @@ describe JsRoutes, "compatibility with Rails" do
|
|
322
338
|
if Rails.version <= "5.0.0"
|
323
339
|
# this type of routing is deprecated
|
324
340
|
it "should include everything that is not optional" do
|
325
|
-
|
341
|
+
expectjs("Routes.classic_path({controller: 'classic', action: 'edit'})").to eq(test_routes.classic_path(controller: :classic, action: :edit))
|
326
342
|
end
|
327
343
|
end
|
328
344
|
end
|
@@ -361,7 +377,7 @@ describe JsRoutes, "compatibility with Rails" do
|
|
361
377
|
evaljs("Array.prototype.indexOf = null")
|
362
378
|
end
|
363
379
|
it "should still work correctly" do
|
364
|
-
|
380
|
+
expectjs("Routes.inboxes_path()").to eq(test_routes.inboxes_path())
|
365
381
|
end
|
366
382
|
end
|
367
383
|
|
@@ -382,98 +398,69 @@ describe JsRoutes, "compatibility with Rails" do
|
|
382
398
|
}.to raise_error(js_error_class)
|
383
399
|
end
|
384
400
|
it "should support 0 as a to_param option" do
|
385
|
-
|
401
|
+
expectjs("Routes.inbox_path({to_param: 0})").to eq(test_routes.inbox_path(Struct.new(:to_param).new('0')))
|
386
402
|
end
|
387
403
|
|
388
404
|
it "should check for options special key" do
|
389
|
-
|
405
|
+
expectjs("Routes.inbox_path({id: 7, q: 'hello', _options: true})").to eq(test_routes.inbox_path(id: 7, q: 'hello'))
|
390
406
|
expect {
|
391
407
|
evaljs("Routes.inbox_path({to_param: 7, _options: true})")
|
392
408
|
}.to raise_error(js_error_class)
|
393
|
-
|
409
|
+
expectjs("Routes.inbox_message_path(5, {id: 7, q: 'hello', _options: true})").to eq(test_routes.inbox_message_path(5, id: 7, q: 'hello'))
|
394
410
|
end
|
395
411
|
|
396
412
|
it "should support 0 as an id option" do
|
397
|
-
|
413
|
+
expectjs("Routes.inbox_path({id: 0})").to eq(test_routes.inbox_path(0))
|
398
414
|
end
|
399
415
|
|
400
416
|
it "should use id property of the object in path" do
|
401
|
-
|
417
|
+
expectjs("Routes.inbox_path({id: 1})").to eq(test_routes.inbox_path(1))
|
402
418
|
end
|
403
419
|
|
404
420
|
it "should prefer to_param property over id property" do
|
405
|
-
|
421
|
+
expectjs("Routes.inbox_path({id: 1, to_param: 'my'})").to eq(test_routes.inbox_path(inbox))
|
406
422
|
end
|
407
423
|
|
408
424
|
it "should call to_param if it is a function" do
|
409
|
-
|
425
|
+
expectjs("Routes.inbox_path({id: 1, to_param: function(){ return 'my';}})").to eq(test_routes.inbox_path(inbox))
|
410
426
|
end
|
411
427
|
|
412
428
|
it "should call id if it is a function" do
|
413
|
-
|
429
|
+
expectjs("Routes.inbox_path({id: function() { return 1;}})").to eq(test_routes.inbox_path(1))
|
414
430
|
end
|
415
431
|
|
416
432
|
it "should support options argument" do
|
417
|
-
|
433
|
+
expectjs(
|
418
434
|
"Routes.inbox_message_path({id:1, to_param: 'my'}, {id:2}, {custom: true, format: 'json'})"
|
419
|
-
)
|
435
|
+
).to eq(test_routes.inbox_message_path(inbox, 2, :custom => true, :format => "json"))
|
420
436
|
end
|
421
437
|
|
422
438
|
it "supports camel case property name" do
|
423
|
-
|
439
|
+
expectjs("Routes.inbox_path({id: 1, toParam: 'my'})").to eq(test_routes.inbox_path(inbox))
|
424
440
|
end
|
425
441
|
|
426
442
|
it "supports camel case method name" do
|
427
|
-
|
443
|
+
expectjs("Routes.inbox_path({id: 1, toParam: function(){ return 'my';}})").to eq(test_routes.inbox_path(inbox))
|
428
444
|
end
|
429
445
|
|
430
446
|
context "when globbing" do
|
431
447
|
it "should prefer to_param property over id property" do
|
432
|
-
|
448
|
+
expectjs("Routes.book_path({id: 1, to_param: 'my'}, 1)").to eq(test_routes.book_path(inbox, 1))
|
433
449
|
end
|
434
450
|
|
435
451
|
it "should call to_param if it is a function" do
|
436
|
-
|
452
|
+
expectjs("Routes.book_path({id: 1, to_param: function(){ return 'my';}}, 1)").to eq(test_routes.book_path(inbox, 1))
|
437
453
|
end
|
438
454
|
|
439
455
|
it "should call id if it is a function" do
|
440
|
-
|
456
|
+
expectjs("Routes.book_path({id: function() { return 'technical';}}, 1)").to eq(test_routes.book_path('technical', 1))
|
441
457
|
end
|
442
458
|
|
443
459
|
it "should support options argument" do
|
444
|
-
|
460
|
+
expectjs(
|
445
461
|
"Routes.book_path({id:1, to_param: 'my'}, {id:2}, {custom: true, format: 'json'})"
|
446
|
-
)
|
462
|
+
).to eq(test_routes.book_path(inbox, 2, :custom => true, :format => "json"))
|
447
463
|
end
|
448
464
|
end
|
449
|
-
|
450
|
-
end
|
451
|
-
|
452
|
-
context "when specs" do
|
453
|
-
it "should show inbox spec" do
|
454
|
-
expect(evaljs("Routes.inbox_path.toString()")).to eq('/inboxes/:id(.:format)')
|
455
|
-
end
|
456
|
-
|
457
|
-
it "should show inbox spec convert to string" do
|
458
|
-
expect(evaljs("'' + Routes.inbox_path")).to eq('/inboxes/:id(.:format)')
|
459
|
-
end
|
460
|
-
|
461
|
-
it "should show inbox message spec" do
|
462
|
-
expect(evaljs("Routes.inbox_message_path.toString()")).to eq('/inboxes/:inbox_id/messages/:id(.:format)')
|
463
|
-
end
|
464
|
-
|
465
|
-
it "should show inbox message spec convert to string" do
|
466
|
-
expect(evaljs("'' + Routes.inbox_message_path")).to eq('/inboxes/:inbox_id/messages/:id(.:format)')
|
467
|
-
end
|
468
|
-
end
|
469
|
-
|
470
|
-
describe "requiredParams" do
|
471
|
-
it "should show inbox spec" do
|
472
|
-
expect(evaljs("Routes.inbox_path.requiredParams()").to_a).to eq(["id"])
|
473
|
-
end
|
474
|
-
|
475
|
-
it "should show inbox message spec" do
|
476
|
-
expect(evaljs("Routes.inbox_message_path.requiredParams()").to_a).to eq(["inbox_id", "id"])
|
477
|
-
end
|
478
465
|
end
|
479
466
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
|
2
|
+
require "spec_helper"
|
3
|
+
|
4
|
+
describe JsRoutes, "compatibility with Rails" do
|
5
|
+
|
6
|
+
let(:generated_js) do
|
7
|
+
JsRoutes.generate({module_type: nil, namespace: 'Routes'})
|
8
|
+
end
|
9
|
+
before(:each) do
|
10
|
+
evaljs(generated_js)
|
11
|
+
end
|
12
|
+
|
13
|
+
context "when specs" do
|
14
|
+
it "should show inbox spec" do
|
15
|
+
expectjs("Routes.inbox_path.toString()").to eq('/inboxes/:id(.:format)')
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should show inbox spec convert to string" do
|
19
|
+
expectjs("'' + Routes.inbox_path").to eq('/inboxes/:id(.:format)')
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should show inbox message spec" do
|
23
|
+
expectjs("Routes.inbox_message_path.toString()").to eq('/inboxes/:inbox_id/messages/:id(.:format)')
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should show inbox message spec convert to string" do
|
27
|
+
expectjs("'' + Routes.inbox_message_path").to eq('/inboxes/:inbox_id/messages/:id(.:format)')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "requiredParams" do
|
32
|
+
it "should show inbox spec" do
|
33
|
+
expect(evaljs("Routes.inbox_path.requiredParams()").to_a).to eq(["id"])
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should show inbox message spec" do
|
37
|
+
expect(evaljs("Routes.inbox_message_path.requiredParams()").to_a).to eq(["inbox_id", "id"])
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: js-routes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bogdan Gusiev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-05-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -200,6 +200,7 @@ files:
|
|
200
200
|
- spec/js_routes/module_types/umd_spec.rb
|
201
201
|
- spec/js_routes/options_spec.rb
|
202
202
|
- spec/js_routes/rails_routes_compatibility_spec.rb
|
203
|
+
- spec/js_routes/route_specification_spec.rb
|
203
204
|
- spec/js_routes/zzz_last_post_rails_init_spec.rb
|
204
205
|
- spec/spec_helper.rb
|
205
206
|
- spec/support/routes.rb
|