js-routes 2.2.9 → 2.2.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +6 -1
  3. data/lib/js_routes/generators/base.rb +6 -1
  4. data/lib/js_routes/generators/middleware.rb +3 -2
  5. data/lib/js_routes/instance.rb +8 -0
  6. data/lib/js_routes/middleware.rb +4 -2
  7. data/lib/js_routes/route.rb +4 -2
  8. data/lib/js_routes/types.rb +10 -0
  9. data/lib/js_routes/version.rb +1 -1
  10. data/lib/js_routes.rb +5 -0
  11. metadata +8 -100
  12. data/.document +0 -5
  13. data/.eslintrc.js +0 -15
  14. data/.github/workflows/ci.yml +0 -36
  15. data/.gitignore +0 -65
  16. data/.nvmrc +0 -1
  17. data/.rspec +0 -1
  18. data/Appraisals +0 -17
  19. data/Gemfile +0 -9
  20. data/Rakefile +0 -37
  21. data/VERSION_2_UPGRADE.md +0 -66
  22. data/bin/tapioca +0 -27
  23. data/gemfiles/rails50_sprockets_3.gemfile +0 -8
  24. data/gemfiles/rails51_sprockets_3.gemfile +0 -8
  25. data/gemfiles/rails52_sprockets_3.gemfile +0 -8
  26. data/gemfiles/rails70_sprockets_4.gemfile +0 -8
  27. data/js-routes.gemspec +0 -42
  28. data/package.json +0 -38
  29. data/sorbet/config +0 -4
  30. data/sorbet/rbi/annotations/.gitattributes +0 -1
  31. data/sorbet/rbi/annotations/actionpack.rbi +0 -428
  32. data/sorbet/rbi/annotations/actionview.rbi +0 -75
  33. data/sorbet/rbi/annotations/activesupport.rbi +0 -421
  34. data/sorbet/rbi/annotations/railties.rbi +0 -61
  35. data/sorbet/rbi/gems/.gitattributes +0 -1
  36. data/sorbet/rbi/gems/actionpack@7.0.4.1.rbi +0 -303
  37. data/sorbet/rbi/gems/actionview@7.0.4.1.rbi +0 -8
  38. data/sorbet/rbi/gems/activesupport@7.0.4.1.rbi +0 -16424
  39. data/sorbet/rbi/gems/appraisal@2.4.1.rbi +0 -584
  40. data/sorbet/rbi/gems/builder@3.2.4.rbi +0 -8
  41. data/sorbet/rbi/gems/bump@0.10.0.rbi +0 -168
  42. data/sorbet/rbi/gems/byebug@11.1.3.rbi +0 -3606
  43. data/sorbet/rbi/gems/coderay@1.1.3.rbi +0 -3426
  44. data/sorbet/rbi/gems/concurrent-ruby@1.2.0.rbi +0 -11570
  45. data/sorbet/rbi/gems/crass@1.0.6.rbi +0 -8
  46. data/sorbet/rbi/gems/diff-lcs@1.5.0.rbi +0 -1083
  47. data/sorbet/rbi/gems/erubi@1.12.0.rbi +0 -145
  48. data/sorbet/rbi/gems/i18n@1.12.0.rbi +0 -2296
  49. data/sorbet/rbi/gems/libv8-node@16.10.0.0.rbi +0 -8
  50. data/sorbet/rbi/gems/loofah@2.19.1.rbi +0 -8
  51. data/sorbet/rbi/gems/method_source@1.0.0.rbi +0 -272
  52. data/sorbet/rbi/gems/mini_racer@0.6.3.rbi +0 -224
  53. data/sorbet/rbi/gems/minitest@5.17.0.rbi +0 -1457
  54. data/sorbet/rbi/gems/netrc@0.11.0.rbi +0 -158
  55. data/sorbet/rbi/gems/nokogiri@1.14.0.rbi +0 -8
  56. data/sorbet/rbi/gems/parallel@1.24.0.rbi +0 -280
  57. data/sorbet/rbi/gems/prettier_print@1.2.1.rbi +0 -951
  58. data/sorbet/rbi/gems/prism@0.24.0.rbi +0 -29744
  59. data/sorbet/rbi/gems/pry-byebug@3.10.1.rbi +0 -1150
  60. data/sorbet/rbi/gems/pry@0.14.2.rbi +0 -10075
  61. data/sorbet/rbi/gems/racc@1.6.2.rbi +0 -150
  62. data/sorbet/rbi/gems/rack-test@2.0.2.rbi +0 -8
  63. data/sorbet/rbi/gems/rack@2.2.6.2.rbi +0 -5585
  64. data/sorbet/rbi/gems/rails-dom-testing@2.0.3.rbi +0 -8
  65. data/sorbet/rbi/gems/rails-html-sanitizer@1.5.0.rbi +0 -8
  66. data/sorbet/rbi/gems/railties@7.0.4.1.rbi +0 -1959
  67. data/sorbet/rbi/gems/rake@13.0.6.rbi +0 -3072
  68. data/sorbet/rbi/gems/rbi@0.1.9.rbi +0 -3006
  69. data/sorbet/rbi/gems/rspec-core@3.12.0.rbi +0 -10868
  70. data/sorbet/rbi/gems/rspec-expectations@3.12.2.rbi +0 -8100
  71. data/sorbet/rbi/gems/rspec-mocks@3.12.3.rbi +0 -5299
  72. data/sorbet/rbi/gems/rspec-support@3.12.0.rbi +0 -1611
  73. data/sorbet/rbi/gems/rspec@3.12.0.rbi +0 -82
  74. data/sorbet/rbi/gems/spoom@1.2.4.rbi +0 -3777
  75. data/sorbet/rbi/gems/sprockets-rails@3.4.2.rbi +0 -14
  76. data/sorbet/rbi/gems/sprockets@4.2.0.rbi +0 -8
  77. data/sorbet/rbi/gems/syntax_tree@6.2.0.rbi +0 -23136
  78. data/sorbet/rbi/gems/tapioca@0.12.0.rbi +0 -3510
  79. data/sorbet/rbi/gems/thor@1.2.1.rbi +0 -3956
  80. data/sorbet/rbi/gems/tzinfo@2.0.5.rbi +0 -5914
  81. data/sorbet/rbi/gems/yard-sorbet@0.8.1.rbi +0 -428
  82. data/sorbet/rbi/gems/yard@0.9.34.rbi +0 -18332
  83. data/sorbet/rbi/gems/zeitwerk@2.6.8.rbi +0 -8
  84. data/sorbet/rbi/todo.rbi +0 -31
  85. data/sorbet/tapioca/config.yml +0 -13
  86. data/sorbet/tapioca/require.rb +0 -4
  87. data/spec/dummy/app/assets/config/manifest.js +0 -2
  88. data/spec/dummy/app/assets/javascripts/.gitkeep +0 -0
  89. data/spec/dummy/config/routes.rb +0 -55
  90. data/spec/js_routes/default_serializer_spec.rb +0 -31
  91. data/spec/js_routes/module_types/amd_spec.rb +0 -35
  92. data/spec/js_routes/module_types/cjs_spec.rb +0 -15
  93. data/spec/js_routes/module_types/dts/routes.spec.d.ts +0 -115
  94. data/spec/js_routes/module_types/dts/test.spec.ts +0 -56
  95. data/spec/js_routes/module_types/dts_spec.rb +0 -126
  96. data/spec/js_routes/module_types/esm_spec.rb +0 -45
  97. data/spec/js_routes/module_types/nil_spec.rb +0 -87
  98. data/spec/js_routes/module_types/umd_spec.rb +0 -85
  99. data/spec/js_routes/options_spec.rb +0 -508
  100. data/spec/js_routes/rails_routes_compatibility_spec.rb +0 -473
  101. data/spec/js_routes/route_specification_spec.rb +0 -37
  102. data/spec/js_routes/zzz_sprockets_spec.rb +0 -152
  103. data/spec/spec_helper.rb +0 -135
  104. data/spec/support/routes.rb +0 -81
  105. data/spec/tsconfig.json +0 -4
  106. data/tsconfig.json +0 -28
  107. data/yarn.lock +0 -2457
@@ -1,85 +0,0 @@
1
- require "active_support/core_ext/string/strip"
2
- require "fileutils"
3
- require 'spec_helper'
4
-
5
- describe JsRoutes, "compatibility with UMD" do
6
- describe "generated js" do
7
- subject do
8
- JsRoutes.generate(
9
- module_type: 'UMD',
10
- include: /book|inboxes|inbox_message/,
11
- )
12
- end
13
-
14
- it "should include a comment in the header" do
15
- app_class = "App"
16
-
17
- is_expected.to include("File generated by js-routes #{JsRoutes::VERSION}")
18
- is_expected.to include("Based on Rails #{Rails.version} routes of #{app_class}")
19
- end
20
-
21
- it "should call route function for each route" do
22
- is_expected.to include("inboxes_path: __jsr.r(")
23
- end
24
- it "should have correct function without arguments signature" do
25
- is_expected.to include('inboxes_path: __jsr.r({"format":{}}')
26
- end
27
- it "should have correct function with arguments signature" do
28
- is_expected.to include('inbox_message_path: __jsr.r({"inbox_id":{"r":true},"id":{"r":true},"format":{}}')
29
- end
30
- it "should have correct function signature with unordered hash" do
31
- is_expected.to include('inbox_message_attachment_path: __jsr.r({"inbox_id":{"r":true},"message_id":{"r":true},"id":{"r":true},"format":{}}')
32
- end
33
-
34
- it "should have correct function comment with options argument" do
35
- is_expected.to include(<<-DOC.rstrip)
36
- /**
37
- * Generates rails route to
38
- * /inboxes(.:format)
39
- * @param {object | undefined} options
40
- * @returns {string} route path
41
- */
42
- inboxes_path: __jsr.r
43
- DOC
44
- end
45
- it "should have correct function comment with arguments" do
46
- is_expected.to include(<<-DOC.rstrip)
47
- /**
48
- * Generates rails route to
49
- * /inboxes/:inbox_id/messages/:message_id/attachments/new(.:format)
50
- * @param {any} inbox_id
51
- * @param {any} message_id
52
- * @param {object | undefined} options
53
- * @returns {string} route path
54
- */
55
- new_inbox_message_attachment_path: __jsr.r
56
- DOC
57
- end
58
-
59
- it "routes should be sorted in alphabetical order" do
60
- expect(subject.index("book_path")).to be <= subject.index("inboxes_path")
61
- end
62
- end
63
-
64
- describe ".generate!" do
65
-
66
- let(:name) { Rails.root.join('app', 'assets', 'javascripts', 'routes.js') }
67
-
68
- before(:each) do
69
- FileUtils.rm_f(name)
70
- JsRoutes.generate!(file: name)
71
- end
72
-
73
- after(:each) do
74
- FileUtils.rm_f(name)
75
- end
76
-
77
- after(:all) do
78
- FileUtils.rm_f("#{File.dirname(__FILE__)}/../routes.js") # let(:name) is not available here
79
- end
80
-
81
- it "should not generate file before initialization" do
82
- expect(File.exist?(name)).to be_falsey
83
- end
84
- end
85
- end
@@ -1,508 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe JsRoutes, "options" do
4
-
5
- let(:generated_js) do
6
- JsRoutes.generate(
7
- module_type: nil,
8
- namespace: 'Routes',
9
- **_options
10
- )
11
- end
12
-
13
- before(:each) do
14
- evaljs(_presetup) if _presetup
15
- with_warnings(_warnings) do
16
- evaljs(generated_js)
17
- App.routes.default_url_options = _options[:default_url_options] || {}
18
- end
19
- end
20
-
21
- after(:each) do
22
- App.routes.default_url_options = {}
23
- end
24
-
25
- let(:_presetup) { nil }
26
- let(:_options) { {} }
27
- let(:_warnings) { true }
28
-
29
- describe "serializer" do
30
- context "when specified" do
31
- # define custom serializer
32
- # this is a nonsense serializer, which always returns foo=bar
33
- # for all inputs
34
- let(:_presetup){ %q(function myCustomSerializer(object, prefix) { return "foo=bar"; }) }
35
- let(:_options) { {:serializer => "myCustomSerializer"} }
36
-
37
- it "should set configurable serializer" do
38
- # expect the nonsense serializer above to have appened foo=bar
39
- # to the end of the path
40
- expectjs(%q(Routes.inboxes_path())).to eql("/inboxes?foo=bar")
41
- end
42
- end
43
-
44
- context "when specified, but not function" do
45
- let(:_presetup){ %q(var myCustomSerializer = 1) }
46
- let(:_options) { {:serializer => "myCustomSerializer"} }
47
-
48
- it "should throw error" do
49
- expect {
50
- evaljs(%q(Routes.inboxes_path({a: 1})))
51
- }.to raise_error(js_error_class)
52
- end
53
- end
54
-
55
- context "when configured in js" do
56
- let(:_options) { {:serializer =>%q(function (object, prefix) { return "foo=bar"; })} }
57
-
58
- it "uses JS serializer" do
59
- evaljs("Routes.configure({serializer: function (object, prefix) { return 'bar=baz'; }})")
60
- expectjs(%q(Routes.inboxes_path({a: 1}))).to eql("/inboxes?bar=baz")
61
- end
62
- end
63
- end
64
-
65
- context "when exclude is specified" do
66
-
67
- let(:_options) { {exclude: [/^admin_/]} }
68
-
69
- it "should exclude specified routes from file" do
70
- expectjs("Routes.admin_users_path").to be_nil
71
- end
72
-
73
- it "should not exclude routes not under specified pattern" do
74
- expectjs("Routes.inboxes_path()").not_to be_nil
75
- end
76
-
77
- context "for rails engine" do
78
- let(:_options) { {:exclude => [/^blog_app_posts/]} }
79
-
80
- it "should exclude specified engine route" do
81
- expectjs("Routes.blog_app_posts_path").to be_nil
82
- end
83
- end
84
- end
85
-
86
- context "when include is specified" do
87
-
88
- let(:_options) { {include: [/^admin_/]} }
89
-
90
- it "should exclude specified routes from file" do
91
- expectjs("Routes.admin_users_path()").not_to be_nil
92
- end
93
-
94
- it "should not exclude routes not under specified pattern" do
95
- expectjs("Routes.inboxes_path").to be_nil
96
- end
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
- expectjs("Routes.adminUsersPath()").not_to be_nil
103
- end
104
-
105
- it "should not exclude routes not under specified pattern" do
106
- expectjs("Routes.inboxesPath").to be_nil
107
- end
108
- end
109
-
110
- context "for rails engine" do
111
- let(:_options) { {include: [/^blog_app_posts/]} }
112
-
113
- it "should include specified engine route" do
114
- expectjs("Routes.blog_app_posts_path()").not_to be_nil
115
- end
116
- end
117
- end
118
-
119
- context "when prefix with trailing slash is specified" do
120
-
121
- let(:_options) { {:prefix => "/myprefix/" } }
122
-
123
- it "should render routing with prefix" do
124
- expectjs("Routes.inbox_path(1)").to eq("/myprefix#{test_routes.inbox_path(1)}")
125
- end
126
-
127
- it "should render routing with prefix set in JavaScript" do
128
- evaljs("Routes.configure({prefix: '/newprefix/'})")
129
- expectjs("Routes.config().prefix").to eq("/newprefix/")
130
- expectjs("Routes.inbox_path(1)").to eq("/newprefix#{test_routes.inbox_path(1)}")
131
- end
132
-
133
- end
134
-
135
- context "when prefix with http:// is specified" do
136
-
137
- let(:_options) { {:prefix => "http://localhost:3000" } }
138
-
139
- it "should render routing with prefix" do
140
- expectjs("Routes.inbox_path(1)").to eq(_options[:prefix] + test_routes.inbox_path(1))
141
- end
142
- end
143
-
144
- context "when prefix without trailing slash is specified" do
145
-
146
- let(:_options) { {:prefix => "/myprefix" } }
147
-
148
- it "should render routing with prefix" do
149
- expectjs("Routes.inbox_path(1)").to eq("/myprefix#{test_routes.inbox_path(1)}")
150
- end
151
-
152
- it "should render routing with prefix set in JavaScript" do
153
- evaljs("Routes.configure({prefix: '/newprefix/'})")
154
- expectjs("Routes.inbox_path(1)").to eq("/newprefix#{test_routes.inbox_path(1)}")
155
- end
156
-
157
- end
158
-
159
- context "when default format is specified" do
160
- let(:_options) { {:default_url_options => {format: "json"}} }
161
- let(:_warnings) { nil }
162
-
163
- if Rails.version >= "5"
164
- it "should render routing with default_format" do
165
- expectjs("Routes.inbox_path(1)").to eq(test_routes.inbox_path(1))
166
- end
167
-
168
- it "should render routing with default_format and zero object" do
169
- expectjs("Routes.inbox_path(0)").to eq(test_routes.inbox_path(0))
170
- end
171
- end
172
-
173
- it "should override default_format when spefified implicitly" do
174
- expectjs("Routes.inbox_path(1, {format: 'xml'})").to eq(test_routes.inbox_path(1, :format => "xml"))
175
- end
176
-
177
- it "should override nullify implicitly when specified implicitly" do
178
- expectjs("Routes.inbox_path(1, {format: null})").to eq(test_routes.inbox_path(1, format: nil))
179
- end
180
-
181
- it "shouldn't require the format" do
182
- expectjs("Routes.json_only_path()").to eq(test_routes.json_only_path)
183
- end
184
- end
185
-
186
- it "shouldn't include the format when {:format => false} is specified" do
187
- expectjs("Routes.no_format_path()").to eq(test_routes.no_format_path())
188
- expectjs("Routes.no_format_path({format: 'json'})").to eq(test_routes.no_format_path(format: 'json'))
189
- end
190
-
191
- describe "default_url_options" do
192
- context "with optional route parts" do
193
- context "provided by the default_url_options" do
194
- let(:_options) { { :default_url_options => { :optional_id => "12", :format => "json" } } }
195
- it "should use this options to fill optional parameters" do
196
- expectjs("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
- expectjs("Routes.things_path({ optional_id: 34 })").to eq(test_routes.things_path(optional_id: 34))
204
- end
205
- end
206
-
207
- context "not provided" do
208
- let(:_options) { { :default_url_options => { :format => "json" } } }
209
- it "breaks" do
210
- expectjs("Routes.foo_all_path()").to eq(test_routes.foo_all_path)
211
- end
212
- end
213
- end
214
-
215
- context "with required route parts" do
216
- let(:_options) { { :default_url_options => { :inbox_id => "12" } } }
217
- it "should use this options to fill optional parameters" do
218
- expectjs("Routes.inbox_messages_path()").to eq(test_routes.inbox_messages_path)
219
- end
220
- end
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
- expectjs("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
- expectjs("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
-
235
- context "when overwritten on JS level" do
236
- let(:_options) { { :default_url_options => { :format => "json" } } }
237
- it "uses JS defined value" do
238
- evaljs("Routes.configure({default_url_options: {format: 'xml'}})")
239
- expectjs("Routes.inboxes_path()").to eq(test_routes.inboxes_path(format: 'xml'))
240
- end
241
- end
242
- end
243
-
244
- describe "trailing_slash" do
245
- context "with default option" do
246
- let(:_options) { Hash.new }
247
- it "should working in params" do
248
- expectjs("Routes.inbox_path(1, {trailing_slash: true})").to eq(test_routes.inbox_path(1, :trailing_slash => true))
249
- end
250
-
251
- it "should working with additional params" do
252
- expectjs("Routes.inbox_path(1, {trailing_slash: true, test: 'params'})").to eq(test_routes.inbox_path(1, :trailing_slash => true, :test => 'params'))
253
- end
254
- end
255
-
256
- context "with default_url_options option" do
257
- let(:_options) { {:default_url_options => {:trailing_slash => true}} }
258
- it "should working" do
259
- expectjs("Routes.inbox_path(1, {test: 'params'})").to eq(test_routes.inbox_path(1, :trailing_slash => true, :test => 'params'))
260
- end
261
-
262
- it "should remove it by params" do
263
- expectjs("Routes.inbox_path(1, {trailing_slash: false})").to eq(test_routes.inbox_path(1, trailing_slash: false))
264
- end
265
- end
266
-
267
- context "with disabled default_url_options option" do
268
- let(:_options) { {:default_url_options => {:trailing_slash => false}} }
269
- it "should not use trailing_slash" do
270
- expectjs("Routes.inbox_path(1, {test: 'params'})").to eq(test_routes.inbox_path(1, :test => 'params'))
271
- end
272
-
273
- it "should use it by params" do
274
- expectjs("Routes.inbox_path(1, {trailing_slash: true})").to eq(test_routes.inbox_path(1, :trailing_slash => true))
275
- end
276
- end
277
- end
278
-
279
- describe "camel_case" do
280
- context "with default option" do
281
- let(:_options) { Hash.new }
282
- it "should use snake case routes" do
283
- expectjs("Routes.inbox_path(1)").to eq(test_routes.inbox_path(1))
284
- expectjs("Routes.inboxPath").to be_nil
285
- end
286
- end
287
-
288
- context "with true" do
289
- let(:_options) { { :camel_case => true } }
290
- it "should generate camel case routes" do
291
- expectjs("Routes.inbox_path").to be_nil
292
- expectjs("Routes.inboxPath").not_to be_nil
293
- expectjs("Routes.inboxPath(1)").to eq(test_routes.inbox_path(1))
294
- expectjs("Routes.inboxMessagesPath(10)").to eq(test_routes.inbox_messages_path(:inbox_id => 10))
295
- end
296
- end
297
- end
298
-
299
- describe "url_links" do
300
- context "with default option" do
301
- let(:_options) { Hash.new }
302
- it "should generate only path links" do
303
- expectjs("Routes.inbox_path(1)").to eq(test_routes.inbox_path(1))
304
- expectjs("Routes.inbox_url").to be_nil
305
- end
306
- end
307
-
308
- context "when configuring with default_url_options" do
309
- context "when only host option is specified" do
310
- let(:_options) { { :url_links => true, :default_url_options => {:host => "example.com"} } }
311
-
312
- it "uses the specified host, defaults protocol to http, defaults port to 80 (leaving it blank)" do
313
- expectjs("Routes.inbox_url(1)").to eq("http://example.com#{test_routes.inbox_path(1)}")
314
- end
315
-
316
- it "does not override protocol when specified in route" do
317
- expectjs("Routes.new_session_url()").to eq("https://example.com#{test_routes.new_session_path}")
318
- end
319
-
320
- it "does not override host when specified in route" do
321
- expectjs("Routes.sso_url()").to eq(test_routes.sso_url)
322
- end
323
-
324
- it "does not override port when specified in route" do
325
- expectjs("Routes.portals_url()").to eq("http://example.com:8080#{test_routes.portals_path}")
326
- end
327
- end
328
-
329
- context "when default host and protocol are specified" do
330
- let(:_options) { { :url_links => true, :default_url_options => {:host => "example.com", :protocol => "ftp"} } }
331
-
332
- it "uses the specified protocol and host, defaults port to 80 (leaving it blank)" do
333
- expectjs("Routes.inbox_url(1)").to eq("ftp://example.com#{test_routes.inbox_path(1)}")
334
- end
335
-
336
- it "does not override protocol when specified in route" do
337
- expectjs("Routes.new_session_url()").to eq("https://example.com#{test_routes.new_session_path}")
338
- end
339
-
340
- it "does not override host when host is specified in route" do
341
- expectjs("Routes.sso_url()").to eq("ftp://sso.example.com#{test_routes.sso_path}")
342
- end
343
-
344
- it "does not override port when specified in route" do
345
- expectjs("Routes.portals_url()").to eq("ftp://example.com:8080#{test_routes.portals_path}")
346
- end
347
- end
348
-
349
- context "when default host and port are specified" do
350
- let(:_options) { { :url_links => true, :default_url_options => {:host => "example.com", :port => 3000} } }
351
-
352
- it "uses the specified host and port, defaults protocol to http" do
353
- expectjs("Routes.inbox_url(1)").to eq("http://example.com:3000#{test_routes.inbox_path(1)}")
354
- end
355
-
356
- it "does not override protocol when specified in route" do
357
- expectjs("Routes.new_session_url()").to eq("https://example.com:3000#{test_routes.new_session_path}")
358
- end
359
-
360
- it "does not override host, protocol, or port when host is specified in route" do
361
- expectjs("Routes.sso_url()").to eq("http://sso.example.com:3000" + test_routes.sso_path)
362
- end
363
-
364
- it "does not override parts when specified in route" do
365
- expectjs("Routes.secret_root_url()").to eq(test_routes.secret_root_url)
366
- end
367
- end
368
-
369
- context "with camel_case option" do
370
- let(:_options) { { :camel_case => true, :url_links => true, :default_url_options => {:host => "example.com"} } }
371
- it "should generate path and url links" do
372
- expectjs("Routes.inboxUrl(1)").to eq("http://example.com#{test_routes.inbox_path(1)}")
373
- end
374
- end
375
-
376
- context "with prefix option" do
377
- let(:_options) { { :prefix => "/api", :url_links => true, :default_url_options => {:host => 'example.com'} } }
378
- it "should generate path and url links" do
379
- expectjs("Routes.inbox_url(1)").to eq("http://example.com/api#{test_routes.inbox_path(1)}")
380
- end
381
- end
382
-
383
- context "with compact option" do
384
- let(:_options) { { :compact => true, :url_links => true, :default_url_options => {:host => 'example.com'} } }
385
- it "does not affect url helpers" do
386
- expectjs("Routes.inbox_url(1)").to eq("http://example.com#{test_routes.inbox_path(1)}")
387
- end
388
- end
389
- end
390
-
391
- context 'when window.location is present' do
392
- let(:current_protocol) { 'http:' } # window.location.protocol includes the colon character
393
- let(:current_hostname) { 'current.example.com' }
394
- let(:current_port){ '' } # an empty string means port 80
395
- let(:current_host) do
396
- host = "#{current_hostname}"
397
- host += ":#{current_port}" unless current_port == ''
398
- host
399
- end
400
-
401
- let(:_presetup) do
402
- location = {
403
- protocol: current_protocol,
404
- hostname: current_hostname,
405
- port: current_port,
406
- host: current_host,
407
- }
408
- [
409
- "const window = this;",
410
- "window.location = #{ActiveSupport::JSON.encode(location)};",
411
- ].join("\n")
412
- end
413
-
414
- context "without specifying a default host" do
415
- let(:_options) { { :url_links => true } }
416
-
417
- it "uses the current host" do
418
- expectjs("Routes.inbox_path").not_to be_nil
419
- expectjs("Routes.inbox_url").not_to be_nil
420
- expectjs("Routes.inbox_url(1)").to eq("http://current.example.com#{test_routes.inbox_path(1)}")
421
- expectjs("Routes.inbox_url(1, { test_key: \"test_val\" })").to eq("http://current.example.com#{test_routes.inbox_path(1, :test_key => "test_val")}")
422
- expectjs("Routes.new_session_url()").to eq("https://current.example.com#{test_routes.new_session_path}")
423
- end
424
-
425
- it "doesn't use current when specified in the route" do
426
- expectjs("Routes.sso_url()").to eq(test_routes.sso_url)
427
- end
428
-
429
- it "uses host option as an argument" do
430
- expectjs("Routes.secret_root_url({host: 'another.com'})").to eq(test_routes.secret_root_url(host: 'another.com'))
431
- end
432
-
433
- it "uses port option as an argument" do
434
- expectjs("Routes.secret_root_url({host: 'localhost', port: 8080})").to eq(test_routes.secret_root_url(host: 'localhost', port: 8080))
435
- end
436
-
437
- it "uses protocol option as an argument" do
438
- expectjs("Routes.secret_root_url({host: 'localhost', protocol: 'https'})").to eq(test_routes.secret_root_url(protocol: 'https', host: 'localhost'))
439
- end
440
-
441
- it "uses subdomain option as an argument" do
442
- expectjs("Routes.secret_root_url({subdomain: 'custom'})").to eq(test_routes.secret_root_url(subdomain: 'custom'))
443
- end
444
- end
445
- end
446
-
447
- context 'when window.location is not present' do
448
- context 'without specifying a default host' do
449
- let(:_options) { { url_links: true } }
450
-
451
- it 'generates path' do
452
- expectjs("Routes.inbox_url(1)").to eq test_routes.inbox_path(1)
453
- expectjs("Routes.new_session_url()").to eq test_routes.new_session_path
454
- end
455
- end
456
- end
457
- end
458
-
459
- describe "when the compact mode is enabled" do
460
- let(:_options) { { :compact => true } }
461
- it "removes _path suffix from path helpers" do
462
- expectjs("Routes.inbox_path").to be_nil
463
- expectjs("Routes.inboxes()").to eq(test_routes.inboxes_path())
464
- expectjs("Routes.inbox(2)").to eq(test_routes.inbox_path(2))
465
- end
466
-
467
- context "with url_links option" do
468
- around(:each) do |example|
469
- ActiveSupport::Deprecation.silence do
470
- example.run
471
- end
472
- end
473
-
474
- let(:_options) { { :compact => true, :url_links => true, default_url_options: {host: 'localhost'} } }
475
- it "should not strip urls" do
476
- expectjs("Routes.inbox(1)").to eq(test_routes.inbox_path(1))
477
- expectjs("Routes.inbox_url(1)").to eq("http://localhost#{test_routes.inbox_path(1)}")
478
- end
479
- end
480
- end
481
-
482
- describe "special_options_key" do
483
- let(:_options) { { special_options_key: :__options__ } }
484
- it "can be redefined" do
485
- expect {
486
- expectjs("Routes.inbox_message_path({inbox_id: 1, id: 2, _options: true})").to eq("")
487
- }.to raise_error(js_error_class)
488
- expectjs("Routes.inbox_message_path({inbox_id: 1, id: 2, __options__: true})").to eq(test_routes.inbox_message_path(inbox_id: 1, id: 2))
489
- end
490
- end
491
-
492
- describe "when application is specified" do
493
- let(:_options) { {application: -> {BlogEngine::Engine}} }
494
-
495
- it "should include specified engine route" do
496
- expectjs("Routes.posts_path()").not_to be_nil
497
- end
498
- end
499
-
500
- describe "documentation option" do
501
- let(:_options) { {documentation: false} }
502
-
503
- it "disables documentation generation" do
504
- expect(generated_js).not_to include("@param")
505
- expect(generated_js).not_to include("@returns")
506
- end
507
- end
508
- end