js-routes 2.2.3 → 2.2.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.eslintrc.js +1 -1
  3. data/.github/workflows/ci.yml +36 -0
  4. data/Appraisals +2 -4
  5. data/CHANGELOG.md +7 -0
  6. data/Readme.md +50 -43
  7. data/gemfiles/rails50_sprockets_3.gemfile +1 -1
  8. data/gemfiles/rails51_sprockets_3.gemfile +1 -1
  9. data/gemfiles/rails52_sprockets_3.gemfile +1 -1
  10. data/gemfiles/rails70_sprockets_4.gemfile +8 -0
  11. data/lib/js_routes/engine.rb +6 -1
  12. data/lib/js_routes/generators/middleware.rb +1 -1
  13. data/lib/js_routes/instance.rb +2 -2
  14. data/lib/js_routes/middleware.rb +6 -2
  15. data/lib/js_routes/version.rb +1 -1
  16. data/lib/routes.d.ts +2 -0
  17. data/lib/routes.js +23 -5
  18. data/lib/routes.ts +34 -17
  19. data/package.json +7 -6
  20. data/spec/js_routes/default_serializer_spec.rb +5 -5
  21. data/spec/js_routes/module_types/amd_spec.rb +3 -3
  22. data/spec/js_routes/module_types/cjs_spec.rb +1 -1
  23. data/spec/js_routes/module_types/dts/routes.spec.d.ts +2 -0
  24. data/spec/js_routes/module_types/dts_spec.rb +1 -1
  25. data/spec/js_routes/module_types/esm_spec.rb +2 -2
  26. data/spec/js_routes/module_types/nil_spec.rb +7 -7
  27. data/spec/js_routes/module_types/umd_spec.rb +1 -1
  28. data/spec/js_routes/options_spec.rb +81 -81
  29. data/spec/js_routes/rails_routes_compatibility_spec.rb +127 -138
  30. data/spec/js_routes/route_specification_spec.rb +40 -0
  31. data/spec/js_routes/zzz_last_post_rails_init_spec.rb +8 -2
  32. data/spec/spec_helper.rb +5 -5
  33. data/yarn.lock +760 -448
  34. metadata +6 -10
  35. data/.travis.yml +0 -67
  36. data/gemfiles/rails40_sprockets_2.gemfile +0 -8
  37. data/gemfiles/rails40_sprockets_3.gemfile +0 -8
  38. data/gemfiles/rails41_sprockets_2.gemfile +0 -8
  39. data/gemfiles/rails41_sprockets_3.gemfile +0 -8
  40. data/gemfiles/rails42_sprockets_2.gemfile +0 -8
  41. data/gemfiles/rails42_sprockets_3.gemfile +0 -8
@@ -3,7 +3,7 @@ require "spec_helper"
3
3
  describe JsRoutes, "compatibility with AMD/require.js" do
4
4
 
5
5
  before(:each) do
6
- evaljs("var global = this;", {force: true})
6
+ evaljs("var global = this;", force: true)
7
7
  evaljs("global.GlobalCheck = {};")
8
8
  evaljs("global.define = function (requirs, callback) { global.GlobalCheck['js-routes'] = callback.call(this); return global.GlobalCheck['js-routes']; };")
9
9
  evaljs("global.define.amd = { jQuery: true };")
@@ -25,11 +25,11 @@ describe JsRoutes, "compatibility with AMD/require.js" do
25
25
  };
26
26
  EOF
27
27
  evaljs(strRequire)
28
- evaljs(JsRoutes.generate({module_type: 'AMD'}))
28
+ evaljs(JsRoutes.generate(module_type: 'AMD'))
29
29
  end
30
30
 
31
31
  it "should working from require" do
32
- expect(evaljs("require(['js-routes'], function(r){ return r.inboxes_path(); })")).to eq(test_routes.inboxes_path())
32
+ expectjs("require(['js-routes'], function(r){ return r.inboxes_path(); })").to eq(test_routes.inboxes_path())
33
33
  end
34
34
 
35
35
  end
@@ -10,6 +10,6 @@ describe JsRoutes, "compatibility with CJS" do
10
10
  end
11
11
 
12
12
  it "should define module exports" do
13
- expect(evaljs("module.exports.inboxes_path()")).to eq(test_routes.inboxes_path())
13
+ expectjs("module.exports.inboxes_path()").to eq(test_routes.inboxes_path())
14
14
  end
15
15
  end
@@ -53,6 +53,7 @@ declare type KeywordUrlOptions = Optional<{
53
53
  port: string | number;
54
54
  anchor: string;
55
55
  trailing_slash: boolean;
56
+ params: RouteParameters;
56
57
  }>;
57
58
  declare type RouteOptions = KeywordUrlOptions & RouteParameters;
58
59
  declare type PartsTable = Record<string, {
@@ -63,6 +64,7 @@ declare type ModuleType = "CJS" | "AMD" | "UMD" | "ESM" | "DTS" | "NIL";
63
64
  declare const RubyVariables: {
64
65
  PREFIX: string;
65
66
  DEPRECATED_GLOBBING_BEHAVIOR: boolean;
67
+ DEPRECATED_FALSE_PARAMETER_BEHAVIOR: boolean;
66
68
  SPECIAL_OPTIONS_KEY: string;
67
69
  DEFAULT_URL_OPTIONS: RouteParameters;
68
70
  SERIALIZER: Serializer;
@@ -12,7 +12,7 @@ describe JsRoutes, "compatibility with DTS" do
12
12
  end
13
13
 
14
14
  let(:generated_js) do
15
- JsRoutes.generate({**OPTIONS, **extra_options})
15
+ JsRoutes.generate(**OPTIONS, **extra_options)
16
16
  end
17
17
 
18
18
  context "when file is generated" do
@@ -13,7 +13,7 @@ describe JsRoutes, "compatibility with ESM" do
13
13
  end
14
14
 
15
15
  it "defines route helpers" do
16
- expect(evaljs("inboxes_path()")).to eq(test_routes.inboxes_path())
16
+ expectjs("inboxes_path()").to eq(test_routes.inboxes_path())
17
17
  end
18
18
 
19
19
  it "exports route helpers" do
@@ -33,7 +33,7 @@ DOC
33
33
  end
34
34
 
35
35
  it "defines utility methods" do
36
- expect(evaljs("serialize({a: 1, b: 2})")).to eq({a: 1, b: 2}.to_param)
36
+ expectjs("serialize({a: 1, b: 2})").to eq({a: 1, b: 2}.to_param)
37
37
  end
38
38
 
39
39
  describe "compiled javascript asset" do
@@ -36,7 +36,7 @@ describe JsRoutes, "compatibility with NIL (legacy browser)" do
36
36
  end
37
37
 
38
38
  it "should be possible" do
39
- expect(evaljs("r.inboxes_path()")).to eq(test_routes.inboxes_path())
39
+ expectjs("r.inboxes_path()").to eq(test_routes.inboxes_path())
40
40
  end
41
41
  end
42
42
 
@@ -50,8 +50,8 @@ describe JsRoutes, "compatibility with NIL (legacy browser)" do
50
50
  evaljs(generated_js)
51
51
  end
52
52
  it "should use this namespace for routing" do
53
- expect(evaljs("window.Routes")).to be_nil
54
- expect(evaljs("window.PHM.inboxes_path")).not_to be_nil
53
+ expectjs("window.Routes").to be_nil
54
+ expectjs("window.PHM.inboxes_path").not_to be_nil
55
55
  end
56
56
 
57
57
  describe "is nested" do
@@ -60,7 +60,7 @@ describe JsRoutes, "compatibility with NIL (legacy browser)" do
60
60
  let(:_options) { {namespace: "PHM.Routes"} }
61
61
 
62
62
  it "should use this namespace for routing" do
63
- expect(evaljs("PHM.Routes.inboxes_path")).not_to be_nil
63
+ expectjs("PHM.Routes.inboxes_path").not_to be_nil
64
64
  end
65
65
  end
66
66
 
@@ -68,7 +68,7 @@ describe JsRoutes, "compatibility with NIL (legacy browser)" do
68
68
  let(:_options) { {namespace: "PHM.Routes"} }
69
69
 
70
70
  it "should initialize namespace" do
71
- expect(evaljs("window.PHM.Routes.inboxes_path")).not_to be_nil
71
+ expectjs("window.PHM.Routes.inboxes_path").not_to be_nil
72
72
  end
73
73
  end
74
74
 
@@ -77,8 +77,8 @@ describe JsRoutes, "compatibility with NIL (legacy browser)" do
77
77
  let(:_options) { {namespace: "PHM.Routes"} }
78
78
 
79
79
  it "should not overwrite existing parts" do
80
- expect(evaljs("window.PHM.Utils")).not_to be_nil
81
- expect(evaljs("window.PHM.Routes.inboxes_path")).not_to be_nil
80
+ expectjs("window.PHM.Utils").not_to be_nil
81
+ expectjs("window.PHM.Routes.inboxes_path").not_to be_nil
82
82
  end
83
83
  end
84
84
  end
@@ -67,7 +67,7 @@ DOC
67
67
 
68
68
  before(:each) do
69
69
  FileUtils.rm_f(name)
70
- JsRoutes.generate!({:file => name})
70
+ JsRoutes.generate!(file: name)
71
71
  end
72
72
 
73
73
  after(:each) do
@@ -3,11 +3,11 @@ require 'spec_helper'
3
3
  describe JsRoutes, "options" do
4
4
 
5
5
  let(:generated_js) do
6
- JsRoutes.generate({
6
+ JsRoutes.generate(
7
7
  module_type: nil,
8
8
  namespace: 'Routes',
9
9
  **_options
10
- })
10
+ )
11
11
  end
12
12
 
13
13
  before(:each) do
@@ -37,7 +37,7 @@ describe JsRoutes, "options" do
37
37
  it "should set configurable serializer" do
38
38
  # expect the nonsense serializer above to have appened foo=bar
39
39
  # to the end of the path
40
- expect(evaljs(%q(Routes.inboxes_path()))).to eql("/inboxes?foo=bar")
40
+ expectjs(%q(Routes.inboxes_path())).to eql("/inboxes?foo=bar")
41
41
  end
42
42
  end
43
43
 
@@ -57,7 +57,7 @@ describe JsRoutes, "options" do
57
57
 
58
58
  it "uses JS serializer" do
59
59
  evaljs("Routes.configure({serializer: function (object, prefix) { return 'bar=baz'; }})")
60
- expect(evaljs(%q(Routes.inboxes_path({a: 1})))).to eql("/inboxes?bar=baz")
60
+ expectjs(%q(Routes.inboxes_path({a: 1}))).to eql("/inboxes?bar=baz")
61
61
  end
62
62
  end
63
63
  end
@@ -67,18 +67,18 @@ describe JsRoutes, "options" do
67
67
  let(:_options) { {:exclude => /^admin_/} }
68
68
 
69
69
  it "should exclude specified routes from file" do
70
- expect(evaljs("Routes.admin_users_path")).to be_nil
70
+ expectjs("Routes.admin_users_path").to be_nil
71
71
  end
72
72
 
73
73
  it "should not exclude routes not under specified pattern" do
74
- expect(evaljs("Routes.inboxes_path()")).not_to be_nil
74
+ expectjs("Routes.inboxes_path()").not_to be_nil
75
75
  end
76
76
 
77
77
  context "for rails engine" do
78
78
  let(:_options) { {:exclude => /^blog_app_posts/} }
79
79
 
80
80
  it "should exclude specified engine route" do
81
- expect(evaljs("Routes.blog_app_posts_path")).to be_nil
81
+ expectjs("Routes.blog_app_posts_path").to be_nil
82
82
  end
83
83
  end
84
84
  end
@@ -88,22 +88,22 @@ describe JsRoutes, "options" do
88
88
  let(:_options) { {:include => /^admin_/} }
89
89
 
90
90
  it "should exclude specified routes from file" do
91
- expect(evaljs("Routes.admin_users_path()")).not_to be_nil
91
+ expectjs("Routes.admin_users_path()").not_to be_nil
92
92
  end
93
93
 
94
94
  it "should not exclude routes not under specified pattern" do
95
- expect(evaljs("Routes.inboxes_path")).to be_nil
95
+ expectjs("Routes.inboxes_path").to be_nil
96
96
  end
97
97
 
98
98
  context "with camel_case option" do
99
99
  let(:_options) { {include: /^admin_/, camel_case: true} }
100
100
 
101
101
  it "should exclude specified routes from file" do
102
- expect(evaljs("Routes.adminUsersPath()")).not_to be_nil
102
+ expectjs("Routes.adminUsersPath()").not_to be_nil
103
103
  end
104
104
 
105
105
  it "should not exclude routes not under specified pattern" do
106
- expect(evaljs("Routes.inboxesPath")).to be_nil
106
+ expectjs("Routes.inboxesPath").to be_nil
107
107
  end
108
108
  end
109
109
 
@@ -111,7 +111,7 @@ describe JsRoutes, "options" do
111
111
  let(:_options) { {:include => /^blog_app_posts/} }
112
112
 
113
113
  it "should include specified engine route" do
114
- expect(evaljs("Routes.blog_app_posts_path()")).not_to be_nil
114
+ expectjs("Routes.blog_app_posts_path()").not_to be_nil
115
115
  end
116
116
  end
117
117
  end
@@ -121,13 +121,13 @@ describe JsRoutes, "options" do
121
121
  let(:_options) { {:prefix => "/myprefix/" } }
122
122
 
123
123
  it "should render routing with prefix" do
124
- expect(evaljs("Routes.inbox_path(1)")).to eq("/myprefix#{test_routes.inbox_path(1)}")
124
+ expectjs("Routes.inbox_path(1)").to eq("/myprefix#{test_routes.inbox_path(1)}")
125
125
  end
126
126
 
127
127
  it "should render routing with prefix set in JavaScript" do
128
128
  evaljs("Routes.configure({prefix: '/newprefix/'})")
129
- expect(evaljs("Routes.config().prefix")).to eq("/newprefix/")
130
- expect(evaljs("Routes.inbox_path(1)")).to eq("/newprefix#{test_routes.inbox_path(1)}")
129
+ expectjs("Routes.config().prefix").to eq("/newprefix/")
130
+ expectjs("Routes.inbox_path(1)").to eq("/newprefix#{test_routes.inbox_path(1)}")
131
131
  end
132
132
 
133
133
  end
@@ -137,7 +137,7 @@ describe JsRoutes, "options" do
137
137
  let(:_options) { {:prefix => "http://localhost:3000" } }
138
138
 
139
139
  it "should render routing with prefix" do
140
- expect(evaljs("Routes.inbox_path(1)")).to eq(_options[:prefix] + test_routes.inbox_path(1))
140
+ expectjs("Routes.inbox_path(1)").to eq(_options[:prefix] + test_routes.inbox_path(1))
141
141
  end
142
142
  end
143
143
 
@@ -146,12 +146,12 @@ describe JsRoutes, "options" do
146
146
  let(:_options) { {:prefix => "/myprefix" } }
147
147
 
148
148
  it "should render routing with prefix" do
149
- expect(evaljs("Routes.inbox_path(1)")).to eq("/myprefix#{test_routes.inbox_path(1)}")
149
+ expectjs("Routes.inbox_path(1)").to eq("/myprefix#{test_routes.inbox_path(1)}")
150
150
  end
151
151
 
152
152
  it "should render routing with prefix set in JavaScript" do
153
153
  evaljs("Routes.configure({prefix: '/newprefix/'})")
154
- expect(evaljs("Routes.inbox_path(1)")).to eq("/newprefix#{test_routes.inbox_path(1)}")
154
+ expectjs("Routes.inbox_path(1)").to eq("/newprefix#{test_routes.inbox_path(1)}")
155
155
  end
156
156
 
157
157
  end
@@ -162,30 +162,30 @@ describe JsRoutes, "options" do
162
162
 
163
163
  if Rails.version >= "5"
164
164
  it "should render routing with default_format" do
165
- expect(evaljs("Routes.inbox_path(1)")).to eq(test_routes.inbox_path(1))
165
+ expectjs("Routes.inbox_path(1)").to eq(test_routes.inbox_path(1))
166
166
  end
167
167
 
168
168
  it "should render routing with default_format and zero object" do
169
- expect(evaljs("Routes.inbox_path(0)")).to eq(test_routes.inbox_path(0))
169
+ expectjs("Routes.inbox_path(0)").to eq(test_routes.inbox_path(0))
170
170
  end
171
171
  end
172
172
 
173
173
  it "should override default_format when spefified implicitly" do
174
- expect(evaljs("Routes.inbox_path(1, {format: 'xml'})")).to eq(test_routes.inbox_path(1, :format => "xml"))
174
+ expectjs("Routes.inbox_path(1, {format: 'xml'})").to eq(test_routes.inbox_path(1, :format => "xml"))
175
175
  end
176
176
 
177
177
  it "should override nullify implicitly when specified implicitly" do
178
- expect(evaljs("Routes.inbox_path(1, {format: null})")).to eq(test_routes.inbox_path(1, format: nil))
178
+ expectjs("Routes.inbox_path(1, {format: null})").to eq(test_routes.inbox_path(1, format: nil))
179
179
  end
180
180
 
181
181
  it "shouldn't require the format" do
182
- expect(evaljs("Routes.json_only_path()")).to eq(test_routes.json_only_path)
182
+ expectjs("Routes.json_only_path()").to eq(test_routes.json_only_path)
183
183
  end
184
184
  end
185
185
 
186
186
  it "shouldn't include the format when {:format => false} is specified" do
187
- expect(evaljs("Routes.no_format_path()")).to eq(test_routes.no_format_path())
188
- expect(evaljs("Routes.no_format_path({format: 'json'})")).to eq(test_routes.no_format_path(format: 'json'))
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
189
  end
190
190
 
191
191
  describe "default_url_options" do
@@ -193,21 +193,21 @@ describe JsRoutes, "options" do
193
193
  context "provided by the default_url_options" do
194
194
  let(:_options) { { :default_url_options => { :optional_id => "12", :format => "json" } } }
195
195
  it "should use this options to fill optional parameters" do
196
- expect(evaljs("Routes.things_path()")).to eq(test_routes.things_path(12))
196
+ expectjs("Routes.things_path()").to eq(test_routes.things_path(12))
197
197
  end
198
198
  end
199
199
 
200
200
  context "provided inline by the method parameters" do
201
201
  let(:options) { { :default_url_options => { :optional_id => "12" } } }
202
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))
203
+ expectjs("Routes.things_path({ optional_id: 34 })").to eq(test_routes.things_path(optional_id: 34))
204
204
  end
205
205
  end
206
206
 
207
207
  context "not provided" do
208
208
  let(:_options) { { :default_url_options => { :format => "json" } } }
209
209
  it "breaks" do
210
- expect(evaljs("Routes.foo_all_path()")).to eq(test_routes.foo_all_path)
210
+ expectjs("Routes.foo_all_path()").to eq(test_routes.foo_all_path)
211
211
  end
212
212
  end
213
213
  end
@@ -215,19 +215,19 @@ describe JsRoutes, "options" do
215
215
  context "with required route parts" do
216
216
  let(:_options) { { :default_url_options => { :inbox_id => "12" } } }
217
217
  it "should use this options to fill optional parameters" do
218
- expect(evaljs("Routes.inbox_messages_path()")).to eq(test_routes.inbox_messages_path)
218
+ expectjs("Routes.inbox_messages_path()").to eq(test_routes.inbox_messages_path)
219
219
  end
220
220
  end
221
221
 
222
222
  context "with optional and required route parts" do
223
223
  let(:_options) { {:default_url_options => { :optional_id => "12" } } }
224
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" })
225
+ expectjs("Routes.thing_path(1)").to eq test_routes.thing_path(1, { optional_id: "12" })
226
226
  end
227
227
 
228
228
  context "when passing options that do not have defaults" do
229
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.
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
231
  end
232
232
  end
233
233
  end
@@ -236,7 +236,7 @@ describe JsRoutes, "options" do
236
236
  let(:_options) { { :default_url_options => { :format => "json" } } }
237
237
  it "uses JS defined value" do
238
238
  evaljs("Routes.configure({default_url_options: {format: 'xml'}})")
239
- expect(evaljs("Routes.inboxes_path()")).to eq(test_routes.inboxes_path(format: 'xml'))
239
+ expectjs("Routes.inboxes_path()").to eq(test_routes.inboxes_path(format: 'xml'))
240
240
  end
241
241
  end
242
242
  end
@@ -245,33 +245,33 @@ describe JsRoutes, "options" do
245
245
  context "with default option" do
246
246
  let(:_options) { Hash.new }
247
247
  it "should working in params" do
248
- expect(evaljs("Routes.inbox_path(1, {trailing_slash: true})")).to eq(test_routes.inbox_path(1, :trailing_slash => true))
248
+ expectjs("Routes.inbox_path(1, {trailing_slash: true})").to eq(test_routes.inbox_path(1, :trailing_slash => true))
249
249
  end
250
250
 
251
251
  it "should working with additional params" do
252
- expect(evaljs("Routes.inbox_path(1, {trailing_slash: true, test: 'params'})")).to eq(test_routes.inbox_path(1, :trailing_slash => true, :test => 'params'))
252
+ expectjs("Routes.inbox_path(1, {trailing_slash: true, test: 'params'})").to eq(test_routes.inbox_path(1, :trailing_slash => true, :test => 'params'))
253
253
  end
254
254
  end
255
255
 
256
256
  context "with default_url_options option" do
257
257
  let(:_options) { {:default_url_options => {:trailing_slash => true}} }
258
258
  it "should working" do
259
- expect(evaljs("Routes.inbox_path(1, {test: 'params'})")).to eq(test_routes.inbox_path(1, :trailing_slash => true, :test => 'params'))
259
+ expectjs("Routes.inbox_path(1, {test: 'params'})").to eq(test_routes.inbox_path(1, :trailing_slash => true, :test => 'params'))
260
260
  end
261
261
 
262
262
  it "should remove it by params" do
263
- expect(evaljs("Routes.inbox_path(1, {trailing_slash: false})")).to eq(test_routes.inbox_path(1, trailing_slash: false))
263
+ expectjs("Routes.inbox_path(1, {trailing_slash: false})").to eq(test_routes.inbox_path(1, trailing_slash: false))
264
264
  end
265
265
  end
266
266
 
267
267
  context "with disabled default_url_options option" do
268
268
  let(:_options) { {:default_url_options => {:trailing_slash => false}} }
269
269
  it "should not use trailing_slash" do
270
- expect(evaljs("Routes.inbox_path(1, {test: 'params'})")).to eq(test_routes.inbox_path(1, :test => 'params'))
270
+ expectjs("Routes.inbox_path(1, {test: 'params'})").to eq(test_routes.inbox_path(1, :test => 'params'))
271
271
  end
272
272
 
273
273
  it "should use it by params" do
274
- expect(evaljs("Routes.inbox_path(1, {trailing_slash: true})")).to eq(test_routes.inbox_path(1, :trailing_slash => true))
274
+ expectjs("Routes.inbox_path(1, {trailing_slash: true})").to eq(test_routes.inbox_path(1, :trailing_slash => true))
275
275
  end
276
276
  end
277
277
  end
@@ -280,18 +280,18 @@ describe JsRoutes, "options" do
280
280
  context "with default option" do
281
281
  let(:_options) { Hash.new }
282
282
  it "should use snake case routes" do
283
- expect(evaljs("Routes.inbox_path(1)")).to eq(test_routes.inbox_path(1))
284
- expect(evaljs("Routes.inboxPath")).to be_nil
283
+ expectjs("Routes.inbox_path(1)").to eq(test_routes.inbox_path(1))
284
+ expectjs("Routes.inboxPath").to be_nil
285
285
  end
286
286
  end
287
287
 
288
288
  context "with true" do
289
289
  let(:_options) { { :camel_case => true } }
290
290
  it "should generate camel case routes" do
291
- expect(evaljs("Routes.inbox_path")).to be_nil
292
- expect(evaljs("Routes.inboxPath")).not_to be_nil
293
- expect(evaljs("Routes.inboxPath(1)")).to eq(test_routes.inbox_path(1))
294
- expect(evaljs("Routes.inboxMessagesPath(10)")).to eq(test_routes.inbox_messages_path(:inbox_id => 10))
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
295
  end
296
296
  end
297
297
  end
@@ -300,8 +300,8 @@ describe JsRoutes, "options" do
300
300
  context "with default option" do
301
301
  let(:_options) { Hash.new }
302
302
  it "should generate only path links" do
303
- expect(evaljs("Routes.inbox_path(1)")).to eq(test_routes.inbox_path(1))
304
- expect(evaljs("Routes.inbox_url")).to be_nil
303
+ expectjs("Routes.inbox_path(1)").to eq(test_routes.inbox_path(1))
304
+ expectjs("Routes.inbox_url").to be_nil
305
305
  end
306
306
  end
307
307
 
@@ -310,19 +310,19 @@ describe JsRoutes, "options" do
310
310
  let(:_options) { { :url_links => true, :default_url_options => {:host => "example.com"} } }
311
311
 
312
312
  it "uses the specified host, defaults protocol to http, defaults port to 80 (leaving it blank)" do
313
- expect(evaljs("Routes.inbox_url(1)")).to eq("http://example.com#{test_routes.inbox_path(1)}")
313
+ expectjs("Routes.inbox_url(1)").to eq("http://example.com#{test_routes.inbox_path(1)}")
314
314
  end
315
315
 
316
316
  it "does not override protocol when specified in route" do
317
- expect(evaljs("Routes.new_session_url()")).to eq("https://example.com#{test_routes.new_session_path}")
317
+ expectjs("Routes.new_session_url()").to eq("https://example.com#{test_routes.new_session_path}")
318
318
  end
319
319
 
320
320
  it "does not override host when specified in route" do
321
- expect(evaljs("Routes.sso_url()")).to eq(test_routes.sso_url)
321
+ expectjs("Routes.sso_url()").to eq(test_routes.sso_url)
322
322
  end
323
323
 
324
324
  it "does not override port when specified in route" do
325
- expect(evaljs("Routes.portals_url()")).to eq("http://example.com:8080#{test_routes.portals_path}")
325
+ expectjs("Routes.portals_url()").to eq("http://example.com:8080#{test_routes.portals_path}")
326
326
  end
327
327
  end
328
328
 
@@ -330,19 +330,19 @@ describe JsRoutes, "options" do
330
330
  let(:_options) { { :url_links => true, :default_url_options => {:host => "example.com", :protocol => "ftp"} } }
331
331
 
332
332
  it "uses the specified protocol and host, defaults port to 80 (leaving it blank)" do
333
- expect(evaljs("Routes.inbox_url(1)")).to eq("ftp://example.com#{test_routes.inbox_path(1)}")
333
+ expectjs("Routes.inbox_url(1)").to eq("ftp://example.com#{test_routes.inbox_path(1)}")
334
334
  end
335
335
 
336
336
  it "does not override protocol when specified in route" do
337
- expect(evaljs("Routes.new_session_url()")).to eq("https://example.com#{test_routes.new_session_path}")
337
+ expectjs("Routes.new_session_url()").to eq("https://example.com#{test_routes.new_session_path}")
338
338
  end
339
339
 
340
340
  it "does not override host when host is specified in route" do
341
- expect(evaljs("Routes.sso_url()")).to eq("ftp://sso.example.com#{test_routes.sso_path}")
341
+ expectjs("Routes.sso_url()").to eq("ftp://sso.example.com#{test_routes.sso_path}")
342
342
  end
343
343
 
344
344
  it "does not override port when specified in route" do
345
- expect(evaljs("Routes.portals_url()")).to eq("ftp://example.com:8080#{test_routes.portals_path}")
345
+ expectjs("Routes.portals_url()").to eq("ftp://example.com:8080#{test_routes.portals_path}")
346
346
  end
347
347
  end
348
348
 
@@ -350,40 +350,40 @@ describe JsRoutes, "options" do
350
350
  let(:_options) { { :url_links => true, :default_url_options => {:host => "example.com", :port => 3000} } }
351
351
 
352
352
  it "uses the specified host and port, defaults protocol to http" do
353
- expect(evaljs("Routes.inbox_url(1)")).to eq("http://example.com:3000#{test_routes.inbox_path(1)}")
353
+ expectjs("Routes.inbox_url(1)").to eq("http://example.com:3000#{test_routes.inbox_path(1)}")
354
354
  end
355
355
 
356
356
  it "does not override protocol when specified in route" do
357
- expect(evaljs("Routes.new_session_url()")).to eq("https://example.com:3000#{test_routes.new_session_path}")
357
+ expectjs("Routes.new_session_url()").to eq("https://example.com:3000#{test_routes.new_session_path}")
358
358
  end
359
359
 
360
360
  it "does not override host, protocol, or port when host is specified in route" do
361
- expect(evaljs("Routes.sso_url()")).to eq("http://sso.example.com:3000" + test_routes.sso_path)
361
+ expectjs("Routes.sso_url()").to eq("http://sso.example.com:3000" + test_routes.sso_path)
362
362
  end
363
363
 
364
364
  it "does not override parts when specified in route" do
365
- expect(evaljs("Routes.secret_root_url()")).to eq(test_routes.secret_root_url)
365
+ expectjs("Routes.secret_root_url()").to eq(test_routes.secret_root_url)
366
366
  end
367
367
  end
368
368
 
369
369
  context "with camel_case option" do
370
370
  let(:_options) { { :camel_case => true, :url_links => true, :default_url_options => {:host => "example.com"} } }
371
371
  it "should generate path and url links" do
372
- expect(evaljs("Routes.inboxUrl(1)")).to eq("http://example.com#{test_routes.inbox_path(1)}")
372
+ expectjs("Routes.inboxUrl(1)").to eq("http://example.com#{test_routes.inbox_path(1)}")
373
373
  end
374
374
  end
375
375
 
376
376
  context "with prefix option" do
377
377
  let(:_options) { { :prefix => "/api", :url_links => true, :default_url_options => {:host => 'example.com'} } }
378
378
  it "should generate path and url links" do
379
- expect(evaljs("Routes.inbox_url(1)")).to eq("http://example.com/api#{test_routes.inbox_path(1)}")
379
+ expectjs("Routes.inbox_url(1)").to eq("http://example.com/api#{test_routes.inbox_path(1)}")
380
380
  end
381
381
  end
382
382
 
383
383
  context "with compact option" do
384
384
  let(:_options) { { :compact => true, :url_links => true, :default_url_options => {:host => 'example.com'} } }
385
385
  it "does not affect url helpers" do
386
- expect(evaljs("Routes.inbox_url(1)")).to eq("http://example.com#{test_routes.inbox_path(1)}")
386
+ expectjs("Routes.inbox_url(1)").to eq("http://example.com#{test_routes.inbox_path(1)}")
387
387
  end
388
388
  end
389
389
  end
@@ -415,31 +415,31 @@ describe JsRoutes, "options" do
415
415
  let(:_options) { { :url_links => true } }
416
416
 
417
417
  it "uses the current host" do
418
- expect(evaljs("Routes.inbox_path")).not_to be_nil
419
- expect(evaljs("Routes.inbox_url")).not_to be_nil
420
- expect(evaljs("Routes.inbox_url(1)")).to eq("http://current.example.com#{test_routes.inbox_path(1)}")
421
- 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")}")
422
- expect(evaljs("Routes.new_session_url()")).to eq("https://current.example.com#{test_routes.new_session_path}")
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
423
  end
424
424
 
425
425
  it "doesn't use current when specified in the route" do
426
- expect(evaljs("Routes.sso_url()")).to eq(test_routes.sso_url)
426
+ expectjs("Routes.sso_url()").to eq(test_routes.sso_url)
427
427
  end
428
428
 
429
429
  it "uses host option as an argument" do
430
- expect(evaljs("Routes.secret_root_url({host: 'another.com'})")).to eq(test_routes.secret_root_url(host: 'another.com'))
430
+ expectjs("Routes.secret_root_url({host: 'another.com'})").to eq(test_routes.secret_root_url(host: 'another.com'))
431
431
  end
432
432
 
433
433
  it "uses port option as an argument" do
434
- expect(evaljs("Routes.secret_root_url({host: 'localhost', port: 8080})")).to eq(test_routes.secret_root_url(host: 'localhost', port: 8080))
434
+ expectjs("Routes.secret_root_url({host: 'localhost', port: 8080})").to eq(test_routes.secret_root_url(host: 'localhost', port: 8080))
435
435
  end
436
436
 
437
437
  it "uses protocol option as an argument" do
438
- expect(evaljs("Routes.secret_root_url({host: 'localhost', protocol: 'https'})")).to eq(test_routes.secret_root_url(protocol: 'https', host: 'localhost'))
438
+ expectjs("Routes.secret_root_url({host: 'localhost', protocol: 'https'})").to eq(test_routes.secret_root_url(protocol: 'https', host: 'localhost'))
439
439
  end
440
440
 
441
441
  it "uses subdomain option as an argument" do
442
- expect(evaljs("Routes.secret_root_url({subdomain: 'custom'})")).to eq(test_routes.secret_root_url(subdomain: 'custom'))
442
+ expectjs("Routes.secret_root_url({subdomain: 'custom'})").to eq(test_routes.secret_root_url(subdomain: 'custom'))
443
443
  end
444
444
  end
445
445
  end
@@ -449,8 +449,8 @@ describe JsRoutes, "options" do
449
449
  let(:_options) { { url_links: true } }
450
450
 
451
451
  it 'generates path' do
452
- expect(evaljs("Routes.inbox_url(1)")).to eq test_routes.inbox_path(1)
453
- expect(evaljs("Routes.new_session_url()")).to eq test_routes.new_session_path
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
454
  end
455
455
  end
456
456
  end
@@ -459,9 +459,9 @@ describe JsRoutes, "options" do
459
459
  describe "when the compact mode is enabled" do
460
460
  let(:_options) { { :compact => true } }
461
461
  it "removes _path suffix from path helpers" do
462
- expect(evaljs("Routes.inbox_path")).to be_nil
463
- expect(evaljs("Routes.inboxes()")).to eq(test_routes.inboxes_path())
464
- expect(evaljs("Routes.inbox(2)")).to eq(test_routes.inbox_path(2))
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
465
  end
466
466
 
467
467
  context "with url_links option" do
@@ -473,8 +473,8 @@ describe JsRoutes, "options" do
473
473
 
474
474
  let(:_options) { { :compact => true, :url_links => true, default_url_options: {host: 'localhost'} } }
475
475
  it "should not strip urls" do
476
- expect(evaljs("Routes.inbox(1)")).to eq(test_routes.inbox_path(1))
477
- expect(evaljs("Routes.inbox_url(1)")).to eq("http://localhost#{test_routes.inbox_path(1)}")
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
478
  end
479
479
  end
480
480
  end
@@ -483,9 +483,9 @@ describe JsRoutes, "options" do
483
483
  let(:_options) { { special_options_key: :__options__ } }
484
484
  it "can be redefined" do
485
485
  expect {
486
- expect(evaljs("Routes.inbox_message_path({inbox_id: 1, id: 2, _options: true})")).to eq("")
486
+ expectjs("Routes.inbox_message_path({inbox_id: 1, id: 2, _options: true})").to eq("")
487
487
  }.to raise_error(js_error_class)
488
- expect(evaljs("Routes.inbox_message_path({inbox_id: 1, id: 2, __options__: true})")).to eq(test_routes.inbox_message_path(inbox_id: 1, id: 2))
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
489
  end
490
490
  end
491
491
 
@@ -493,7 +493,7 @@ describe JsRoutes, "options" do
493
493
  let(:_options) { {:application => BlogEngine::Engine} }
494
494
 
495
495
  it "should include specified engine route" do
496
- expect(evaljs("Routes.posts_path()")).not_to be_nil
496
+ expectjs("Routes.posts_path()").not_to be_nil
497
497
  end
498
498
  end
499
499