js-routes 1.4.9 → 2.2.0

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.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.eslintrc.js +15 -0
  3. data/.gitignore +5 -0
  4. data/.nvmrc +1 -0
  5. data/.travis.yml +2 -1
  6. data/CHANGELOG.md +85 -0
  7. data/Rakefile +5 -2
  8. data/Readme.md +274 -98
  9. data/VERSION_2_UPGRADE.md +66 -0
  10. data/js-routes.gemspec +8 -5
  11. data/lib/js_routes/engine.rb +0 -1
  12. data/lib/js_routes/generators/middleware.rb +33 -0
  13. data/lib/js_routes/generators/webpacker.rb +32 -0
  14. data/lib/js_routes/middleware.rb +36 -0
  15. data/lib/js_routes/version.rb +1 -1
  16. data/lib/js_routes.rb +341 -171
  17. data/lib/routes.d.ts +79 -0
  18. data/lib/routes.js +501 -519
  19. data/lib/routes.ts +737 -0
  20. data/lib/tasks/js_routes.rake +8 -2
  21. data/lib/templates/erb.js +11 -0
  22. data/lib/templates/initializer.rb +5 -0
  23. data/lib/templates/routes.js.erb +1 -0
  24. data/package.json +37 -0
  25. data/spec/dummy/app/assets/config/manifest.js +2 -0
  26. data/spec/js_routes/default_serializer_spec.rb +19 -3
  27. data/spec/js_routes/{amd_compatibility_spec.rb → module_types/amd_spec.rb} +7 -14
  28. data/spec/js_routes/module_types/cjs_spec.rb +15 -0
  29. data/spec/js_routes/module_types/dts/routes.spec.d.ts +114 -0
  30. data/spec/js_routes/module_types/dts/test.spec.ts +56 -0
  31. data/spec/js_routes/module_types/dts_spec.rb +111 -0
  32. data/spec/js_routes/module_types/esm_spec.rb +45 -0
  33. data/spec/js_routes/module_types/nil_spec.rb +86 -0
  34. data/spec/js_routes/{generated_javascript_spec.rb → module_types/umd_spec.rb} +33 -27
  35. data/spec/js_routes/options_spec.rb +67 -56
  36. data/spec/js_routes/rails_routes_compatibility_spec.rb +69 -25
  37. data/spec/js_routes/zzz_last_post_rails_init_spec.rb +4 -4
  38. data/spec/spec_helper.rb +34 -17
  39. data/spec/support/routes.rb +10 -4
  40. data/spec/tsconfig.json +4 -0
  41. data/tsconfig.json +28 -0
  42. data/yarn.lock +2145 -0
  43. metadata +42 -22
  44. data/lib/routes.js.coffee +0 -411
@@ -2,10 +2,18 @@ require 'spec_helper'
2
2
 
3
3
  describe JsRoutes, "options" do
4
4
 
5
+ let(:generated_js) do
6
+ JsRoutes.generate({
7
+ module_type: nil,
8
+ namespace: 'Routes',
9
+ **_options
10
+ })
11
+ end
12
+
5
13
  before(:each) do
6
14
  evaljs(_presetup) if _presetup
7
15
  with_warnings(_warnings) do
8
- evaljs(JsRoutes.generate(_options))
16
+ evaljs(generated_js)
9
17
  App.routes.default_url_options = _options[:default_url_options] || {}
10
18
  end
11
19
  end
@@ -37,9 +45,10 @@ describe JsRoutes, "options" do
37
45
  let(:_presetup){ %q(var myCustomSerializer = 1) }
38
46
  let(:_options) { {:serializer => "myCustomSerializer"} }
39
47
 
40
- it "should set configurable serializer" do
41
- # expect to use default
42
- expect(evaljs(%q(Routes.inboxes_path({a: 1})))).to eql("/inboxes?a=1")
48
+ it "should throw error" do
49
+ expect {
50
+ evaljs(%q(Routes.inboxes_path({a: 1})))
51
+ }.to raise_error(js_error_class)
43
52
  end
44
53
  end
45
54
 
@@ -86,6 +95,18 @@ describe JsRoutes, "options" do
86
95
  expect(evaljs("Routes.inboxes_path")).to be_nil
87
96
  end
88
97
 
98
+ context "with camel_case option" do
99
+ let(:_options) { {include: /^admin_/, camel_case: true} }
100
+
101
+ it "should exclude specified routes from file" do
102
+ expect(evaljs("Routes.adminUsersPath()")).not_to be_nil
103
+ end
104
+
105
+ it "should not exclude routes not under specified pattern" do
106
+ expect(evaljs("Routes.inboxesPath")).to be_nil
107
+ end
108
+ end
109
+
89
110
  context "for rails engine" do
90
111
  let(:_options) { {:include => /^blog_app_posts/} }
91
112
 
@@ -167,56 +188,19 @@ describe JsRoutes, "options" do
167
188
  expect(evaljs("Routes.no_format_path({format: 'json'})")).to eq(test_routes.no_format_path(format: 'json'))
168
189
  end
169
190
 
170
- describe "namespace option" do
171
- let(:_options) { {:namespace => "PHM"} }
172
- it "should use this namespace for routing" do
173
- expect(evaljs("window.Routes")).to be_nil
174
- expect(evaljs("PHM.inbox_path")).not_to be_nil
175
- end
176
-
177
- context "is nil" do
178
- let(:_options) { {:namespace => nil} }
179
- it "should use this namespace for routing" do
180
- evaljs("window.zz = #{JsRoutes.generate(namespace: nil)}")
181
- expect(evaljs("window.Routes")).to be_nil
182
- expect(evaljs("window.zz.inbox_path")).not_to be_nil
183
- end
184
-
185
- end
186
-
187
- describe "is nested" do
188
- context "and defined on client" do
189
- let(:_presetup) { "window.PHM = {}" }
190
- let(:_options) { {:namespace => "PHM.Routes"} }
191
- it "should use this namespace for routing" do
192
- expect(evaljs("PHM.Routes.inbox_path")).not_to be_nil
193
- end
194
- end
195
-
196
- context "but undefined on client" do
197
- let(:_options) { {:namespace => "PHM.Routes"} }
198
- it "should initialize namespace" do
199
- expect(evaljs("window.PHM.Routes.inbox_path")).not_to be_nil
200
- end
201
- end
202
-
203
- context "and some parts are defined" do
204
- let(:_presetup) { "window.PHM = { Utils: {} };" }
205
- let(:_options) { {:namespace => "PHM.Routes"} }
206
- it "should not overwrite existing parts" do
207
- expect(evaljs("window.PHM.Utils")).not_to be_nil
208
- expect(evaljs("window.PHM.Routes.inbox_path")).not_to be_nil
209
- end
210
- end
211
- end
212
- end
213
-
214
191
  describe "default_url_options" do
215
192
  context "with optional route parts" do
216
- context "provided" do
193
+ context "provided by the default_url_options" do
217
194
  let(:_options) { { :default_url_options => { :optional_id => "12", :format => "json" } } }
218
- it "should use this opions to fill optional parameters" do
219
- expect(evaljs("Routes.things_path()")).to eq(test_routes.things_path)
195
+ it "should use this options to fill optional parameters" do
196
+ expect(evaljs("Routes.things_path()")).to eq(test_routes.things_path(12))
197
+ end
198
+ end
199
+
200
+ context "provided inline by the method parameters" do
201
+ let(:options) { { :default_url_options => { :optional_id => "12" } } }
202
+ it "should overwrite the default_url_options" do
203
+ expect(evaljs("Routes.things_path({ optional_id: 34 })")).to eq(test_routes.things_path(optional_id: 34))
220
204
  end
221
205
  end
222
206
 
@@ -229,12 +213,25 @@ describe JsRoutes, "options" do
229
213
  end
230
214
 
231
215
  context "with required route parts" do
232
- let(:_options) { {:default_url_options => {:inbox_id => "12"}} }
233
- it "should use this opions to fill optional parameters" do
216
+ let(:_options) { { :default_url_options => { :inbox_id => "12" } } }
217
+ it "should use this options to fill optional parameters" do
234
218
  expect(evaljs("Routes.inbox_messages_path()")).to eq(test_routes.inbox_messages_path)
235
219
  end
236
220
  end
237
221
 
222
+ context "with optional and required route parts" do
223
+ let(:_options) { {:default_url_options => { :optional_id => "12" } } }
224
+ it "should use this options to fill the optional parameters" do
225
+ expect(evaljs("Routes.thing_path(1)")).to eq test_routes.thing_path(1, { optional_id: "12" })
226
+ end
227
+
228
+ context "when passing options that do not have defaults" do
229
+ it "should use this options to fill the optional parameters" do
230
+ expect(evaljs("Routes.thing_path(1, { format: 'json' })")).to eq test_routes.thing_path(1, { optional_id: "12", format: "json" } ) # test_routes.thing_path needs optional_id here to generate the correct route. Not sure why.
231
+ end
232
+ end
233
+ end
234
+
238
235
  context "when overwritten on JS level" do
239
236
  let(:_options) { { :default_url_options => { :format => "json" } } }
240
237
  it "uses JS defined value" do
@@ -401,8 +398,14 @@ describe JsRoutes, "options" do
401
398
  host
402
399
  end
403
400
 
404
- before do
405
- jscontext.eval("window = {'location': {'protocol': '#{current_protocol}', 'hostname': '#{current_hostname}', 'port': '#{current_port}', 'host': '#{current_host}'}}")
401
+ let(:_presetup) do
402
+ window = {location: {
403
+ protocol: current_protocol,
404
+ hostname: current_hostname,
405
+ port: current_port,
406
+ host: current_host,
407
+ }}
408
+ "const window = #{ActiveSupport::JSON.encode(window)}"
406
409
  end
407
410
 
408
411
  context "without specifying a default host" do
@@ -414,7 +417,6 @@ describe JsRoutes, "options" do
414
417
  expect(evaljs("Routes.inbox_url(1)")).to eq("http://current.example.com#{test_routes.inbox_path(1)}")
415
418
  expect(evaljs("Routes.inbox_url(1, { test_key: \"test_val\" })")).to eq("http://current.example.com#{test_routes.inbox_path(1, :test_key => "test_val")}")
416
419
  expect(evaljs("Routes.new_session_url()")).to eq("https://current.example.com#{test_routes.new_session_path}")
417
-
418
420
  end
419
421
 
420
422
  it "doesn't use current when specified in the route" do
@@ -491,4 +493,13 @@ describe JsRoutes, "options" do
491
493
  expect(evaljs("Routes.posts_path()")).not_to be_nil
492
494
  end
493
495
  end
496
+
497
+ describe "documentation option" do
498
+ let(:_options) { {documentation: false} }
499
+
500
+ it "disables documentation generation" do
501
+ expect(generated_js).not_to include("@param")
502
+ expect(generated_js).not_to include("@returns")
503
+ end
504
+ end
494
505
  end
@@ -3,7 +3,7 @@ require "spec_helper"
3
3
  describe JsRoutes, "compatibility with Rails" do
4
4
 
5
5
  before(:each) do
6
- evaljs(JsRoutes.generate({}))
6
+ evaljs(JsRoutes.generate({module_type: nil, namespace: 'Routes'}))
7
7
  end
8
8
 
9
9
  it "should generate collection routing" do
@@ -16,13 +16,16 @@ describe JsRoutes, "compatibility with Rails" do
16
16
 
17
17
  it "should raise error if required argument is not passed", :aggregate_failures do
18
18
  expect { evaljs("Routes.thing_path()") }
19
- .to raise_error(/Route parameter missing: id/)
19
+ .to raise_error(/Route missing required keys: id/)
20
20
  expect { evaljs("Routes.search_path()") }
21
- .to raise_error(/Route parameter missing: q/)
21
+ .to raise_error(/Route missing required keys: q/)
22
22
  expect { evaljs("Routes.book_path()") }
23
- .to raise_error(/Route parameter missing: title/)
23
+ .to raise_error(/Route missing required keys: section, title/)
24
24
  expect { evaljs("Routes.book_title_path()") }
25
- .to raise_error(/Route parameter missing: title/)
25
+ .to raise_error(/Route missing required keys: title/)
26
+
27
+ expect( evaljs("try {Routes.thing_path()} catch (e) { e.name }") ).to eq('ParametersMissing')
28
+ expect( evaljs("try {Routes.thing_path()} catch (e) { e.keys }") ).to eq(['id'])
26
29
  end
27
30
 
28
31
  it "should produce error stacktraces including function names" do
@@ -70,7 +73,7 @@ describe JsRoutes, "compatibility with Rails" do
70
73
  expect(evaljs("Routes.inbox_path(1, {expanded: true, anchor: 'hello'})")).to eq(test_routes.inbox_path(1, :expanded => true, :anchor => "hello"))
71
74
  end
72
75
 
73
- it "should support required paramters given as options hash" do
76
+ it "should support required parameters given as options hash" do
74
77
  expect(evaljs("Routes.search_path({q: 'hello'})")).to eq(test_routes.search_path(:q => 'hello'))
75
78
  end
76
79
 
@@ -110,6 +113,7 @@ describe JsRoutes, "compatibility with Rails" do
110
113
 
111
114
  it "doesn't apply defaults to path" do
112
115
  expect(evaljs("Routes.with_defaults_path()")).to eq(test_routes.with_defaults_path)
116
+ expect(evaljs("Routes.with_defaults_path({format: 'json'})")).to eq(test_routes.with_defaults_path(format: 'json'))
113
117
  end
114
118
  end
115
119
 
@@ -131,6 +135,11 @@ describe JsRoutes, "compatibility with Rails" do
131
135
  it "should support single route mapping" do
132
136
  expect(evaljs("Routes.support_path({page: 3})")).to eq(test_routes.support_path(:page => 3))
133
137
  end
138
+
139
+ it 'works' do
140
+ expect(evaljs("Routes.planner_manage_path({locale: 'ua'})")).to eq(planner_routes.manage_path(locale: 'ua'))
141
+ expect(evaljs("Routes.planner_manage_path()")).to eq(planner_routes.manage_path)
142
+ end
134
143
  end
135
144
 
136
145
  it "shouldn't require the format" do
@@ -149,7 +158,7 @@ describe JsRoutes, "compatibility with Rails" do
149
158
  expect(evaljs("Routes.root_path()")).to eq(test_routes.root_path)
150
159
  end
151
160
 
152
- describe "get paramters" do
161
+ describe "get parameters" do
153
162
  it "should support simple get parameters" do
154
163
  expect(evaljs("Routes.inbox_path(1, {format: 'json', lang: 'ua', q: 'hello'})")).to eq(test_routes.inbox_path(1, :lang => "ua", :q => "hello", :format => "json"))
155
164
  end
@@ -158,6 +167,19 @@ describe JsRoutes, "compatibility with Rails" do
158
167
  expect(evaljs("Routes.inbox_path(1, {hello: ['world', 'mars']})")).to eq(test_routes.inbox_path(1, :hello => [:world, :mars]))
159
168
  end
160
169
 
170
+ context "object without prototype" do
171
+ before(:each) do
172
+ evaljs("let params = Object.create(null); params.q = 'hello';")
173
+ evaljs("let inbox = Object.create(null); inbox.to_param = 1;")
174
+ end
175
+
176
+ it "should still work correctly" do
177
+ expect(evaljs("Routes.inbox_path(inbox, params)")).to eq(
178
+ test_routes.inbox_path(1, q: "hello")
179
+ )
180
+ end
181
+ end
182
+
161
183
  it "should support nested get parameters" do
162
184
  expect(evaljs("Routes.inbox_path(1, {format: 'json', env: 'test', search: { category_ids: [2,5], q: 'hello'}})")).to eq(
163
185
  test_routes.inbox_path(1, :env => 'test', :search => {:category_ids => [2,5], :q => "hello"}, :format => "json")
@@ -225,6 +247,15 @@ describe JsRoutes, "compatibility with Rails" do
225
247
  expect(evaljs("Routes.things_path({ q: 'hello' })")).to eq(test_routes.things_path(q: 'hello'))
226
248
  end
227
249
 
250
+ it "treats false as absent optional part" do
251
+ pending("https://github.com/rails/rails/issues/42280")
252
+ expect(evaljs("Routes.things_path(false)")).to eq(test_routes.things_path(false))
253
+ end
254
+
255
+ it "treats false as absent optional part when default is specified" do
256
+ expect(evaljs("Routes.campaigns_path(false)")).to eq(test_routes.campaigns_path(false))
257
+ end
258
+
228
259
  it "should not require the optional parts as arguments" do
229
260
  expect(evaljs("Routes.thing_path(null, 5)")).to eq(test_routes.thing_path(nil, 5))
230
261
  end
@@ -235,7 +266,7 @@ describe JsRoutes, "compatibility with Rails" do
235
266
 
236
267
  it "should raise error when passing non-full list of arguments and some query params" do
237
268
  expect { evaljs("Routes.thing_path(5, {q: 'hello'})") }
238
- .to raise_error(/Route parameter missing: id/)
269
+ .to raise_error(/Route missing required keys: id/)
239
270
  end
240
271
 
241
272
  it "should treat null as non-given optional part" do
@@ -253,7 +284,7 @@ describe JsRoutes, "compatibility with Rails" do
253
284
 
254
285
  context "and including them" do
255
286
  it "should fail when insufficient arguments are given" do
256
- expect { evaljs("Routes.thing_deep_path(2)") }.to raise_error(/Route parameter missing: third_required/)
287
+ expect { evaljs("Routes.thing_deep_path(2)") }.to raise_error(/Route missing required keys: third_required/)
257
288
  end
258
289
 
259
290
  it "should include the optional parts" do
@@ -302,27 +333,22 @@ describe JsRoutes, "compatibility with Rails" do
302
333
  evaljs("Routes.inbox_path()")
303
334
  }.to raise_error(js_error_class)
304
335
  end
336
+
305
337
  it "should throw Exception if required parameter is not defined" do
306
338
  expect {
307
339
  evaljs("Routes.inbox_path(null)")
308
340
  }.to raise_error(js_error_class)
309
341
  end
310
342
 
311
- it "should throw Exceptions if when there is too many parameters" do
312
- expect {
313
- evaljs("Routes.inbox_path(1,2,3)")
314
- }.to raise_error(js_error_class)
315
- end
316
-
317
- it "should throw Exceptions if when pass id with null" do
343
+ it "should throw Exception if required parameter is not defined" do
318
344
  expect {
319
- evaljs("Routes.inbox_path({id: null})")
345
+ evaljs("Routes.inbox_path(undefined)")
320
346
  }.to raise_error(js_error_class)
321
347
  end
322
348
 
323
- it "should throw Exceptions if when pass to_param with null" do
349
+ it "should throw Exceptions if when there is too many parameters" do
324
350
  expect {
325
- evaljs("Routes.inbox_path({to_param: null})")
351
+ evaljs("Routes.inbox_path(1,2,3)")
326
352
  }.to raise_error(js_error_class)
327
353
  end
328
354
  end
@@ -341,8 +367,19 @@ describe JsRoutes, "compatibility with Rails" do
341
367
  let(:klass) { Struct.new(:id, :to_param) }
342
368
  let(:inbox) { klass.new(1,"my") }
343
369
 
370
+ it "should throw Exceptions if when pass id with null" do
371
+ expect {
372
+ evaljs("Routes.inbox_path({id: null})")
373
+ }.to raise_error(js_error_class)
374
+ end
375
+
376
+ it "should throw Exceptions if when pass to_param with null" do
377
+ expect {
378
+ evaljs("Routes.inbox_path({to_param: null})")
379
+ }.to raise_error(js_error_class)
380
+ end
344
381
  it "should support 0 as a to_param option" do
345
- expect(evaljs("Routes.inbox_path({to_param: 0})")).to eq(test_routes.inbox_path(0))
382
+ expect(evaljs("Routes.inbox_path({to_param: 0})")).to eq(test_routes.inbox_path(Struct.new(:to_param).new('0')))
346
383
  end
347
384
 
348
385
  it "should check for options special key" do
@@ -379,6 +416,14 @@ describe JsRoutes, "compatibility with Rails" do
379
416
  )).to eq(test_routes.inbox_message_path(inbox, 2, :custom => true, :format => "json"))
380
417
  end
381
418
 
419
+ it "supports camel case property name" do
420
+ expect(evaljs("Routes.inbox_path({id: 1, toParam: 'my'})")).to eq(test_routes.inbox_path(inbox))
421
+ end
422
+
423
+ it "supports camel case method name" do
424
+ expect(evaljs("Routes.inbox_path({id: 1, toParam: function(){ return 'my';}})")).to eq(test_routes.inbox_path(inbox))
425
+ end
426
+
382
427
  context "when globbing" do
383
428
  it "should prefer to_param property over id property" do
384
429
  expect(evaljs("Routes.book_path({id: 1, to_param: 'my'}, 1)")).to eq(test_routes.book_path(inbox, 1))
@@ -398,6 +443,7 @@ describe JsRoutes, "compatibility with Rails" do
398
443
  )).to eq(test_routes.book_path(inbox, 2, :custom => true, :format => "json"))
399
444
  end
400
445
  end
446
+
401
447
  end
402
448
 
403
449
  context "when specs" do
@@ -418,15 +464,13 @@ describe JsRoutes, "compatibility with Rails" do
418
464
  end
419
465
  end
420
466
 
421
- describe "required_params" do
467
+ describe "requiredParams" do
422
468
  it "should show inbox spec" do
423
- expect(evaljs("Routes.inbox_path.required_params").to_a).to eq(["id"])
469
+ expect(evaljs("Routes.inbox_path.requiredParams()").to_a).to eq(["id"])
424
470
  end
425
471
 
426
472
  it "should show inbox message spec" do
427
- expect(evaljs("Routes.inbox_message_path.required_params").to_a).to eq(["inbox_id", "id"])
473
+ expect(evaljs("Routes.inbox_message_path.requiredParams()").to_a).to eq(["inbox_id", "id"])
428
474
  end
429
475
  end
430
-
431
-
432
476
  end
@@ -5,7 +5,7 @@
5
5
  require 'spec_helper'
6
6
  require "fileutils"
7
7
 
8
- describe "after Rails initialization" do
8
+ describe "after Rails initialization", :slow do
9
9
  NAME = Rails.root.join('app', 'assets', 'javascripts', 'routes.js').to_s
10
10
 
11
11
  def sprockets_v3?
@@ -93,7 +93,7 @@ describe "after Rails initialization" do
93
93
  Rails.application.config.assets.initialize_on_precompile = true
94
94
  end
95
95
  it "should render some javascript" do
96
- expect(evaluate(ctx, 'js-routes.js')).to match(/routes = /)
96
+ expect(evaluate(ctx, 'js-routes.js')).to match(/Utils\.define_module/)
97
97
  end
98
98
  end
99
99
  context "and not initialize on precompile" do
@@ -101,7 +101,7 @@ describe "after Rails initialization" do
101
101
  Rails.application.config.assets.initialize_on_precompile = false
102
102
  end
103
103
  it "should raise an exception if 3 version" do
104
- expect(evaluate(ctx, 'js-routes.js')).to match(/routes = /)
104
+ expect(evaluate(ctx, 'js-routes.js')).to match(/Utils\.define_module/)
105
105
  end
106
106
  end
107
107
 
@@ -122,7 +122,7 @@ describe "after Rails initialization" do
122
122
  end
123
123
  end
124
124
 
125
- describe "JSRoutes thread safety" do
125
+ describe "JSRoutes thread safety", :slow do
126
126
  before do
127
127
  begin
128
128
  Rails.application.initialize!
data/spec/spec_helper.rb CHANGED
@@ -6,7 +6,14 @@ require 'rspec'
6
6
  require 'rails/all'
7
7
  require 'js-routes'
8
8
  require 'active_support/core_ext/hash/slice'
9
- require 'coffee-script'
9
+
10
+ unless ENV['TRAVIS_CI']
11
+ code = system("yarn build")
12
+ unless code
13
+ exit(1)
14
+ end
15
+ end
16
+
10
17
 
11
18
  if defined?(JRUBY_VERSION)
12
19
  require 'rhino'
@@ -32,8 +39,15 @@ def js_error_class
32
39
  end
33
40
  end
34
41
 
35
- def evaljs(string, force = false)
36
- jscontext(force).eval(string)
42
+ def evaljs(string, force: false, filename: 'context.js')
43
+ jscontext(force).eval(string, filename: filename)
44
+ rescue MiniRacer::ParseError => e
45
+ message = e.message
46
+ _, _, line, _ = message.split(':')
47
+ code = line && string.split("\n")[line.to_i-1]
48
+ raise "#{message}. Code: #{code.strip}";
49
+ rescue MiniRacer::RuntimeError => e
50
+ raise e
37
51
  end
38
52
 
39
53
  def test_routes
@@ -44,11 +58,21 @@ def blog_routes
44
58
  BlogEngine::Engine.routes.url_helpers
45
59
  end
46
60
 
61
+ def planner_routes
62
+ Planner::Engine.routes.url_helpers
63
+ end
64
+
47
65
  ActiveSupport::Inflector.inflections do |inflect|
48
66
  inflect.irregular "budgie", "budgies"
49
67
  end
50
68
 
51
69
 
70
+ module Planner
71
+ class Engine < Rails::Engine
72
+ isolate_namespace Planner
73
+ end
74
+ end
75
+
52
76
  module BlogEngine
53
77
  class Engine < Rails::Engine
54
78
  isolate_namespace BlogEngine
@@ -79,28 +103,21 @@ RSpec.configure do |config|
79
103
  c.syntax = :expect
80
104
  end
81
105
 
82
- config.before(:all) do
83
- # compile all js files begin
84
- Dir["#{File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))}/**/*.coffee"].each do |coffee|
85
- File.open(coffee.gsub(/\.coffee$/, ""), 'w') do |f|
86
- f.write(CoffeeScript.compile(File.read(coffee)).lstrip)
87
- end
88
- end
89
- # compile all js files end
106
+ config.before(:suite) do
90
107
  draw_routes
91
108
  end
92
109
 
93
110
  config.before :each do
94
- evaljs("var window = this;", true)
111
+ log = proc do |*values|
112
+ puts values.map(&:inspect).join(", ")
113
+ end
95
114
 
96
115
  if defined?(JRUBY_VERSION)
97
- jscontext[:log] = lambda do |context, value|
98
- puts value.inspect
116
+ jscontext[:"console.log"] = lambda do |context, *values|
117
+ log(*values)
99
118
  end
100
119
  else
101
- jscontext.attach("log", proc do |value|
102
- puts value.inspect
103
- end)
120
+ jscontext.attach("console.log", log)
104
121
  end
105
122
  end
106
123
  end
@@ -1,11 +1,17 @@
1
1
  def draw_routes
2
+ Planner::Engine.routes.draw do
3
+ get "/manage" => 'foo#foo', as: :manage
4
+ end
2
5
 
3
6
  BlogEngine::Engine.routes.draw do
4
7
  root to: "application#index"
5
- resources :posts
8
+ resources :posts, only: [:show, :index]
6
9
  end
7
10
  App.routes.draw do
8
11
 
12
+ mount Planner::Engine, at: "/(locale/:locale)", as: :planner
13
+
14
+ mount BlogEngine::Engine => "/blog", as: :blog_app
9
15
  get 'support(/page/:page)', to: BlogEngine::Engine, as: 'support'
10
16
 
11
17
  resources :inboxes, only: [:index, :show] do
@@ -14,6 +20,8 @@ def draw_routes
14
20
  end
15
21
  end
16
22
 
23
+ get "(/:space)/campaigns" => "foo#foo", as: :campaigns, defaults: {space: nil}
24
+
17
25
  root :to => "inboxes#index"
18
26
 
19
27
  namespace :admin do
@@ -41,8 +49,6 @@ def draw_routes
41
49
  get 'books/*section/:title' => 'books#show', :as => :book
42
50
  get 'books/:title/*section' => 'books#show', :as => :book_title
43
51
 
44
- mount BlogEngine::Engine => "/blog", :as => :blog_app
45
-
46
52
  get '/no_format' => "foo#foo", :format => false, :as => :no_format
47
53
 
48
54
  get '/json_only' => "foo#foo", :format => true, :constraints => {:format => /json/}, :as => :json_only
@@ -56,7 +62,7 @@ def draw_routes
56
62
 
57
63
  resources :portals, :port => 8080, only: [:index]
58
64
 
59
- get '/with_defaults' => 'foo#foo', defaults: { bar: 'tested', format: :json }, format: :true
65
+ get '/with_defaults' => 'foo#foo', defaults: { bar: 'tested', format: :json }, format: true
60
66
 
61
67
  namespace :api, format: true, defaults: {format: 'json'} do
62
68
  get "/purchases" => "purchases#index"
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": "../tsconfig.json",
3
+ "include": ["./**/*.spec.ts"]
4
+ }
data/tsconfig.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es2019",
4
+ "lib": ["es2020", "dom"],
5
+ "module": "commonjs",
6
+ "sourceMap": false,
7
+ "declaration": true,
8
+ "allowSyntheticDefaultImports": true,
9
+ "resolveJsonModule": false,
10
+ "strictNullChecks": true,
11
+ "noImplicitAny": true,
12
+ "noImplicitThis": true,
13
+ "strictBindCallApply": true,
14
+ "strictFunctionTypes": true,
15
+ "alwaysStrict": false,
16
+
17
+ "esModuleInterop": true,
18
+ "forceConsistentCasingInFileNames": true,
19
+ "emitDecoratorMetadata": true,
20
+ "experimentalDecorators": true
21
+
22
+ },
23
+ "ts-node": {
24
+ "files": true,
25
+ "transpileOnly": false
26
+ },
27
+ "include": ["lib/*.ts"]
28
+ }