js-routes 1.4.4 → 1.4.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: ac6b282ffedbbc45d553d26dfc28a36aa02539b3
4
- data.tar.gz: a229d137f55ca50b7871b43a0e39564b0824d0ab
2
+ SHA256:
3
+ metadata.gz: 1e5ccc1ef3fef13c8d626f32e06cf99593acef814a7777aea3fb3d1452e1a92c
4
+ data.tar.gz: 2a68dec293c58cd47939b8260da2a5038334d36fb72c3d967ec05088c46e039f
5
5
  SHA512:
6
- metadata.gz: 620e07c9d22b14a9ae1a5a1008eb3336e4e72d83d29033b8f29fa6a737429661637d4fdb01e21ab42599b8698eae79233153acab6ef3d6c8d17ed359b02f435b
7
- data.tar.gz: 7fb670b7f0dd3970681afcc8d33fd96687a5a0ff1f9a4e7b8c4f3deca8e197c2abb889eb0a58afcda0f36c391d86a51c7f27bc33df6d884611350937bf5437e3
6
+ metadata.gz: '098b77abe8a1b7ade8c19b9adca75d51fef15d0ba17908e1f950b664a44cf5aa95bb12f3eea26c7e7112992db559ad1cb489116e47fe0728fc7f729d8788a96a'
7
+ data.tar.gz: 492dec4811ae13841cd9a433bd313cd5677f2a31d941eea2463e940832067f2f744d79e080d8dba7e9effbe92f06b70641757919fc994118972690bff9fd2823
@@ -5,17 +5,15 @@ before_install:
5
5
  - gem install bundler # need for jruby and ruby-head
6
6
 
7
7
  rvm:
8
- - 2.0
9
- - 2.1
10
- - 2.2.5
11
8
  - 2.3.1
12
9
  - 2.4.1
10
+ - 2.5.3
11
+ - 2.6.0
13
12
  - jruby-19mode
14
13
  - ruby-head
15
14
  - jruby-head
16
15
 
17
16
  gemfile:
18
- - gemfiles/rails32.gemfile
19
17
  - gemfiles/rails40_sprockets_2.gemfile
20
18
  - gemfiles/rails40_sprockets_3.gemfile
21
19
  - gemfiles/rails41_sprockets_2.gemfile
@@ -41,19 +39,27 @@ matrix:
41
39
  - rvm: ruby-head
42
40
  - rvm: jruby-head
43
41
  exclude:
44
- - rvm: 2.0
45
- gemfile: gemfiles/rails50_sprockets_3.gemfile
46
- - rvm: 2.1
47
- gemfile: gemfiles/rails50_sprockets_3.gemfile
48
- - rvm: 2.0
49
- gemfile: gemfiles/rails51_sprockets_3.gemfile
50
- - rvm: 2.1
51
- gemfile: gemfiles/rails51_sprockets_3.gemfile
42
+ - rvm: 2.6.0
43
+ gemfile: gemfiles/rails40_sprockets_2.gemfile # Segmentation fault
44
+ - rvm: 2.6.0
45
+ gemfile: gemfiles/rails40_sprockets_3.gemfile # Segmentation fault
46
+ - rvm: 2.6.0
47
+ gemfile: gemfiles/rails41_sprockets_2.gemfile # Segmentation fault
48
+ - rvm: 2.6.0
49
+ gemfile: gemfiles/rails41_sprockets_3.gemfile # Segmentation fault
50
+ - rvm: 2.5.3
51
+ gemfile: gemfiles/rails40_sprockets_2.gemfile # Segmentation fault
52
+ - rvm: 2.5.3
53
+ gemfile: gemfiles/rails40_sprockets_3.gemfile # Segmentation fault
54
+ - rvm: 2.5.3
55
+ gemfile: gemfiles/rails41_sprockets_2.gemfile # Segmentation fault
56
+ - rvm: 2.5.3
57
+ gemfile: gemfiles/rails41_sprockets_3.gemfile # Segmentation fault
52
58
  - rvm: 2.4.1
53
- gemfile: gemfiles/rails40_sprockets_2.gemfile # Segmentation fault (core dumped) for 2.4
59
+ gemfile: gemfiles/rails40_sprockets_2.gemfile # Segmentation fault
54
60
  - rvm: 2.4.1
55
- gemfile: gemfiles/rails40_sprockets_3.gemfile # Segmentation fault (core dumped) for 2.4
61
+ gemfile: gemfiles/rails40_sprockets_3.gemfile # Segmentation fault
56
62
  - rvm: 2.4.1
57
- gemfile: gemfiles/rails41_sprockets_2.gemfile # Segmentation fault (core dumped) for 2.4
63
+ gemfile: gemfiles/rails41_sprockets_2.gemfile # Segmentation fault
58
64
  - rvm: 2.4.1
59
- gemfile: gemfiles/rails41_sprockets_3.gemfile # Segmentation fault (core dumped) for 2.4
65
+ gemfile: gemfiles/rails41_sprockets_3.gemfile # Segmentation fault
data/Appraisals CHANGED
@@ -1,8 +1,3 @@
1
- appraise "rails32" do
2
- gem "railties", "~> 3.2.22.5"
3
- gem 'tzinfo'
4
- end
5
-
6
1
  def define_appraisal(rails, version, sprockets)
7
2
  sprockets.each do |sprocket|
8
3
  appraise "#{rails}-sprockets-#{sprocket}" do
@@ -1,5 +1,11 @@
1
1
  ## master
2
2
 
3
+ ## v1.4.5
4
+
5
+ * Fix escaping inside route parameters and globbing #244
6
+
7
+ ## v1.4.4
8
+
3
9
  * More informative stack trace for ParameterMissing error #235
4
10
 
5
11
  ## v1.4.3
data/Readme.md CHANGED
@@ -14,7 +14,7 @@ gem "js-routes"
14
14
 
15
15
  ### Basic Setup
16
16
 
17
- Require js routes file in `application.js` or other bundle
17
+ Require JsRoutes in `application.js` or other bundle
18
18
 
19
19
  ``` js
20
20
  //= require js-routes
@@ -30,9 +30,9 @@ This cache is not flushed on server restart in development environment.
30
30
 
31
31
  **Important:** If routes.js file is not updated after some configuration change you need to run this rake task again.
32
32
 
33
- ### Advanced Setup
33
+ ### Configuration
34
34
 
35
- If you need to customize routes file create initializer, like `config/initializers/jsroutes.rb`:
35
+ You can configure JsRoutes in two main ways. Either with an initializer (e.g. `config/initializers/jsroutes.rb`):
36
36
 
37
37
  ``` ruby
38
38
  JsRoutes.setup do |config|
@@ -40,7 +40,7 @@ JsRoutes.setup do |config|
40
40
  end
41
41
  ```
42
42
 
43
- Or make a more dynamic configuration in JavaScript, but only specific options support the possibility of such configuration(see the list below):
43
+ Or dynamically in JavaScript, although not all configuration options are supported:
44
44
 
45
45
  ``` js
46
46
  Routes.configure({
@@ -55,10 +55,10 @@ Available options:
55
55
  * Option is configurable at JS level with `Routes.configure()`
56
56
  * Example: {:format => "json", :trailing\_slash => true, :protocol => "https", :subdomain => "api", :host => "example.com", :port => 3000}
57
57
  * Default: {}
58
- * `exclude` - Array of regexps to exclude from js routes.
58
+ * `exclude` - Array of regexps to exclude from routes.
59
59
  * Default: []
60
60
  * The regexp applies only to the name before the `_path` suffix, eg: you want to match exactly `settings_path`, the regexp should be `/^settings$/`
61
- * `include` - Array of regexps to include in js routes.
61
+ * `include` - Array of regexps to include in routes.
62
62
  * Default: []
63
63
  * The regexp applies only to the name before the `_path` suffix, eg: you want to match exactly `settings_path`, the regexp should be `/^settings$/`
64
64
  * `namespace` - global object used to access routes.
@@ -83,7 +83,7 @@ Available options:
83
83
  * Example: `jQuery.param` - use jQuery's serializer algorithm. You can attach serialize function from your favorite AJAX framework.
84
84
  * Example: `MyApp.custom_serialize` - use completely custom serializer of your application.
85
85
 
86
- * `special_options_key` - a special key that helps js-routes to destinguish serialized model from options hash
86
+ * `special_options_key` - a special key that helps JsRoutes to destinguish serialized model from options hash
87
87
  * This option is required because JS doesn't provide a difference between an object and a hash
88
88
  * Option is configurable at JS level with `Routes.configure()`
89
89
  * Default: `_options`
@@ -189,39 +189,30 @@ Routes.user_path.required_params // => ['id']
189
189
  ```
190
190
 
191
191
 
192
- ## Rails Compatibilities
192
+ ## Rails Compatibility
193
193
 
194
- JsRoutes ties to be as close as possible to rails behaviour in all aspects of routing API.
195
- Please make and issue in case of any incomtibilities found outside of described below.
194
+ JsRoutes tries to replicate the Rails routing API as closely as possible. If you find any incompatibilities (outside of what is described below), please [open an issue](https://github.com/railsware/js-routes/issues/new).
196
195
 
197
196
  ### Object and Hash distinction issue
198
197
 
199
- Sometimes the destinction between JS Hash and Object can not be found by js-routes.
198
+ Sometimes the destinction between JS Hash and Object can not be found by JsRoutes.
200
199
  In this case you would need to pass a special key to help:
201
200
 
202
201
  ``` js
203
- Routes.company_project_path({company_id: 1, id: 2}) // => Not Enough parameters
202
+ Routes.company_project_path({company_id: 1, id: 2}) // => Not enough parameters
204
203
  Routes.company_project_path({company_id: 1, id: 2, _options: true}) // => "/companies/1/projects/2"
205
204
  ```
206
205
 
207
206
 
208
207
  ## What about security?
209
208
 
210
- js-routes itself do not have security holes. It makes URLs
209
+ JsRoutes itself do not have security holes. It makes URLs
211
210
  without access protection more reachable by potential attacker.
212
211
  In order to prevent this use `:exclude` option for sensitive urls like `/admin_/`
213
212
 
214
- ## Spork
213
+ ## JsRoutes and Heroku
215
214
 
216
- When using Spork and `Spork.trap_method(Rails::Application::RoutesReloader, :reload!)` you should also do:
217
-
218
- ``` ruby
219
- Spork.trap_method(JsRoutes, :generate!)
220
- ```
221
-
222
- ## JS-Routes and heroku
223
-
224
- Heroku environment has a specific problems with setup. It is impossible to use asset pipeline in this environment. You should use "Very Advanced Setup" schema in this case.
215
+ When using this setup on Heroku, it is impossible to use the asset pipeline. You should use the "Very Advanced Setup" schema in this case.
225
216
 
226
217
  For example create routes.js.erb in assets folder with needed content:
227
218
 
@@ -236,16 +227,16 @@ This should just work.
236
227
  There are some alternatives available. Most of them has only basic feature and don't reach the level of quality I accept.
237
228
  Advantages of this one are:
238
229
 
239
- * Rails 3-5 support
230
+ * Rails 4,5,6 support
240
231
  * Rich options set
241
232
  * Full rails compatibility
242
233
  * Support Rails `#to_param` convention for seo optimized paths
243
234
  * Well tested
244
235
 
245
- #### Thanks to [Contributors](https://github.com/railsware/js-routes/contributors)
236
+ #### Thanks to [contributors](https://github.com/railsware/js-routes/contributors)
246
237
 
247
238
  #### Have fun
248
239
 
249
240
 
250
241
  ## License
251
- [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Frailsware%2Fjs-routes.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Frailsware%2Fjs-routes?ref=badge_large)
242
+ [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Frailsware%2Fjs-routes.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Frailsware%2Fjs-routes?ref=badge_large)
@@ -1,2 +1,2 @@
1
1
  <%# encoding: UTF-8 %>
2
- <%= JsRoutes.assert_usable_configuration! && JsRoutes.generate %>
2
+ <%= JsRoutes.generate %>
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
20
20
  s.require_paths = ["lib"]
21
21
  s.summary = %q{Brings Rails named routes to javascript}
22
22
 
23
- s.add_runtime_dependency(%q<railties>, [">= 3.2"])
23
+ s.add_runtime_dependency(%q<railties>, [">= 4"])
24
24
  s.add_runtime_dependency(%q<sprockets-rails>)
25
25
  s.add_development_dependency(%q<rspec>, [">= 3.0.0"])
26
26
  s.add_development_dependency(%q<bundler>, [">= 1.1.0"])
@@ -98,16 +98,6 @@ class JsRoutes
98
98
  new(opts).generate!(file_name)
99
99
  end
100
100
 
101
- # Under rails 3.1.1 and higher, perform a check to ensure that the
102
- # full environment will be available during asset compilation.
103
- # This is required to ensure routes are loaded.
104
- def assert_usable_configuration!
105
- if 3 == Rails::VERSION::MAJOR && !Rails.application.config.assets.initialize_on_precompile
106
- raise("Cannot precompile js-routes unless environment is initialized. Please set config.assets.initialize_on_precompile to true.")
107
- end
108
- true
109
- end
110
-
111
101
  def json(string)
112
102
  ActiveSupport::JSON.encode(string)
113
103
  end
@@ -130,8 +120,9 @@ class JsRoutes
130
120
  {
131
121
  "GEM_VERSION" => JsRoutes::VERSION,
132
122
  "ROUTES" => js_routes,
133
- "DEPRECATED_BEHAVIOR" => Rails.version < "4",
134
123
  "NODE_TYPES" => json(NODE_TYPES),
124
+ "RAILS_VERSION" => ActionPack.version,
125
+ "DEPRECATED_GLOBBING_BEHAVIOR" => ActionPack::VERSION::MAJOR == 4 && ActionPack::VERSION::MINOR == 0,
135
126
 
136
127
  "APP_CLASS" => application.class.to_s,
137
128
  "NAMESPACE" => json(@configuration.namespace),
@@ -150,8 +141,15 @@ class JsRoutes
150
141
  # https://github.com/railsware/js-routes/issues/7
151
142
  Rails.configuration.after_initialize do
152
143
  file_name ||= self.class.configuration['file']
153
- File.open(Rails.root.join(file_name), 'w') do |f|
154
- f.write generate
144
+ file_path = Rails.root.join(file_name)
145
+ js_content = generate
146
+
147
+ # We don't need to rewrite file if it already exist and have same content.
148
+ # It helps asset pipeline or webpack understand that file wasn't changed.
149
+ return if File.exist?(file_path) && File.read(file_path) == js_content
150
+
151
+ File.open(file_path, 'w') do |f|
152
+ f.write js_content
155
153
  end
156
154
  end
157
155
  end
@@ -42,30 +42,17 @@ class Engine < ::Rails::Engine
42
42
  raise StandardError, "Sprockets version #{sprockets_version} is not supported"
43
43
  end
44
44
 
45
- is_running_rails = defined?(Rails) && Rails.respond_to?(:version)
46
- is_running_rails_32 = is_running_rails && Rails.version.match(/3\.2/)
47
-
48
45
  initializer 'js-routes.dependent_on_routes', initializer_args do
49
46
  case sprockets_version
50
47
  when -> (v) { v2.match?('', v) },
51
48
  -> (v) { vgte3.match?('', v) }
52
49
 
53
- # It seems rails 3.2 is not working if
54
- # `Rails.application.config.assets.configure` is used for
55
- # registering preprocessor
56
- if is_running_rails_32
57
- Rails.application.assets.register_preprocessor(
50
+ # Other rails version, assumed newer
51
+ Rails.application.config.assets.configure do |config|
52
+ config.register_preprocessor(
58
53
  "application/javascript",
59
54
  SprocketsExtension,
60
55
  )
61
- else
62
- # Other rails version, assumed newer
63
- Rails.application.config.assets.configure do |config|
64
- config.register_preprocessor(
65
- "application/javascript",
66
- SprocketsExtension,
67
- )
68
- end
69
56
  end
70
57
  else
71
58
  raise StandardError, "Sprockets version #{sprockets_version} is not supported"
@@ -1,3 +1,3 @@
1
1
  class JsRoutes
2
- VERSION = "1.4.4"
2
+ VERSION = "1.4.5"
3
3
  end
@@ -1,18 +1,19 @@
1
1
  /*
2
2
  File generated by js-routes GEM_VERSION
3
- Based on Rails routes of APP_CLASS
3
+ Based on Rails RAILS_VERSION routes of APP_CLASS
4
4
  */
5
5
 
6
6
  (function() {
7
- var DeprecatedBehavior, NodeTypes, ParameterMissing, ReservedOptions, SpecialOptionsKey, Utils, root,
7
+ var DeprecatedGlobbingBehavior, NodeTypes, ParameterMissing, ReservedOptions, SpecialOptionsKey, Utils, root,
8
8
  hasProp = {}.hasOwnProperty,
9
9
  slice = [].slice;
10
10
 
11
11
  root = typeof exports !== "undefined" && exports !== null ? exports : this;
12
12
 
13
- function ParameterMissing(message, fileName, lineNumber) {
14
- var instance = new Error(message, fileName, lineNumber);
15
- if(Object.setPrototypeOf) {
13
+ ParameterMissing = function(message, fileName, lineNumber) {
14
+ var instance;
15
+ instance = new Error(message, fileName, lineNumber);
16
+ if (Object.setPrototypeOf) {
16
17
  Object.setPrototypeOf(instance, Object.getPrototypeOf(this));
17
18
  } else {
18
19
  instance.__proto__ = this.__proto__;
@@ -21,7 +22,7 @@ Based on Rails routes of APP_CLASS
21
22
  Error.captureStackTrace(instance, ParameterMissing);
22
23
  }
23
24
  return instance;
24
- }
25
+ };
25
26
 
26
27
  ParameterMissing.prototype = Object.create(Error.prototype, {
27
28
  constructor: {
@@ -32,7 +33,7 @@ Based on Rails routes of APP_CLASS
32
33
  }
33
34
  });
34
35
 
35
- if (Object.setPrototypeOf){
36
+ if (Object.setPrototypeOf) {
36
37
  Object.setPrototypeOf(ParameterMissing, Error);
37
38
  } else {
38
39
  ParameterMissing.__proto__ = Error;
@@ -40,9 +41,9 @@ Based on Rails routes of APP_CLASS
40
41
 
41
42
  NodeTypes = NODE_TYPES;
42
43
 
43
- SpecialOptionsKey = SPECIAL_OPTIONS_KEY;
44
+ DeprecatedGlobbingBehavior = DEPRECATED_GLOBBING_BEHAVIOR;
44
45
 
45
- DeprecatedBehavior = DEPRECATED_BEHAVIOR;
46
+ SpecialOptionsKey = SPECIAL_OPTIONS_KEY;
46
47
 
47
48
  ReservedOptions = ['anchor', 'trailing_slash', 'subdomain', 'host', 'port', 'protocol'];
48
49
 
@@ -202,7 +203,7 @@ Based on Rails routes of APP_CLASS
202
203
  if (actual_parameters.length > parts.length) {
203
204
  throw new Error("Too many parameters provided for path");
204
205
  }
205
- use_all_parts = DeprecatedBehavior || actual_parameters.length > required_parts.length;
206
+ use_all_parts = actual_parameters.length > required_parts.length;
206
207
  parts_options = {};
207
208
  for (key in options) {
208
209
  if (!hasProp.call(options, key)) continue;
@@ -280,9 +281,9 @@ Based on Rails routes of APP_CLASS
280
281
  return "" + left_part + right_part;
281
282
  case NodeTypes.SYMBOL:
282
283
  value = parameters[left];
284
+ delete parameters[left];
283
285
  if (value != null) {
284
- delete parameters[left];
285
- return this.path_identifier(value);
286
+ return encodeURIComponent(this.path_identifier(value));
286
287
  }
287
288
  if (optional) {
288
289
  return "";
@@ -332,10 +333,11 @@ Based on Rails routes of APP_CLASS
332
333
  route[1] = left = left.replace(/^\*/i, "");
333
334
  }
334
335
  value = parameters[left];
336
+ delete parameters[left];
335
337
  if (value == null) {
336
338
  return this.visit(route, parameters, optional);
337
339
  }
338
- parameters[left] = (function() {
340
+ value = (function() {
339
341
  switch (this.get_object_type(value)) {
340
342
  case "array":
341
343
  return value.join("/");
@@ -343,7 +345,11 @@ Based on Rails routes of APP_CLASS
343
345
  return value;
344
346
  }
345
347
  }).call(this);
346
- return this.visit(route, parameters, optional);
348
+ if (DeprecatedGlobbingBehavior) {
349
+ return this.path_identifier(value);
350
+ } else {
351
+ return encodeURI(this.path_identifier(value));
352
+ }
347
353
  },
348
354
  get_prefix: function() {
349
355
  var prefix;
@@ -1,8 +1,7 @@
1
1
  ###
2
2
  File generated by js-routes GEM_VERSION
3
- Based on Rails routes of APP_CLASS
3
+ Based on Rails RAILS_VERSION routes of APP_CLASS
4
4
  ###
5
- # root is this
6
5
  root = (exports ? this)
7
6
 
8
7
  ParameterMissing = (message, fileName, lineNumber) ->
@@ -28,8 +27,8 @@ else
28
27
  ParameterMissing.__proto__ = Error
29
28
 
30
29
  NodeTypes = NODE_TYPES
30
+ DeprecatedGlobbingBehavior = DEPRECATED_GLOBBING_BEHAVIOR
31
31
  SpecialOptionsKey = SPECIAL_OPTIONS_KEY
32
- DeprecatedBehavior = DEPRECATED_BEHAVIOR
33
32
 
34
33
  ReservedOptions = [
35
34
  'anchor'
@@ -135,7 +134,7 @@ Utils =
135
134
  if actual_parameters.length > parts.length
136
135
  throw new Error("Too many parameters provided for path")
137
136
 
138
- use_all_parts = DeprecatedBehavior or actual_parameters.length > required_parts.length
137
+ use_all_parts = actual_parameters.length > required_parts.length
139
138
  parts_options = {}
140
139
 
141
140
  for own key of options
@@ -211,9 +210,9 @@ Utils =
211
210
  "#{left_part}#{right_part}"
212
211
  when NodeTypes.SYMBOL
213
212
  value = parameters[left]
213
+ delete parameters[left]
214
214
  if value?
215
- delete parameters[left]
216
- return @path_identifier(value)
215
+ return encodeURIComponent(@path_identifier(value))
217
216
  if optional
218
217
  "" # missing parameter
219
218
  else
@@ -260,13 +259,18 @@ Utils =
260
259
  # fix for rails 4 globbing
261
260
  route[1] = left = left.replace(/^\*/i, "") if left.replace(/^\*/i, "") isnt left
262
261
  value = parameters[left]
262
+ delete parameters[left]
263
263
  return @visit(route, parameters, optional) unless value?
264
- parameters[left] = switch @get_object_type(value)
264
+ value = switch @get_object_type(value)
265
265
  when "array"
266
266
  value.join("/")
267
267
  else
268
268
  value
269
- @visit route, parameters, optional
269
+
270
+ if DeprecatedGlobbingBehavior
271
+ @path_identifier(value)
272
+ else
273
+ encodeURI(@path_identifier(value))
270
274
 
271
275
  #
272
276
  # This method check and return prefix from options
@@ -14,7 +14,7 @@ describe JsRoutes do
14
14
  app_class = "App"
15
15
 
16
16
  is_expected.to include("File generated by js-routes #{JsRoutes::VERSION}")
17
- is_expected.to include("Based on Rails routes of #{app_class}")
17
+ is_expected.to include("Based on Rails #{ActionPack.version} routes of #{app_class}")
18
18
  end
19
19
 
20
20
  it "should call route function for each route" do
@@ -6,9 +6,14 @@ describe JsRoutes, "options" do
6
6
  evaljs(_presetup) if _presetup
7
7
  with_warnings(_warnings) do
8
8
  evaljs(JsRoutes.generate(_options))
9
+ App.routes.default_url_options = _options[:default_url_options] || {}
9
10
  end
10
11
  end
11
12
 
13
+ after(:each) do
14
+ App.routes.default_url_options = {}
15
+ end
16
+
12
17
  let(:_presetup) { nil }
13
18
  let(:_options) { {} }
14
19
  let(:_warnings) { true }
@@ -134,12 +139,14 @@ describe JsRoutes, "options" do
134
139
  let(:_options) { {:default_url_options => {format: "json"}} }
135
140
  let(:_warnings) { nil }
136
141
 
137
- it "should render routing with default_format" do
138
- expect(evaljs("Routes.inbox_path(1)")).to eq(test_routes.inbox_path(1, :format => "json"))
139
- end
142
+ if Rails.version >= "5"
143
+ it "should render routing with default_format" do
144
+ expect(evaljs("Routes.inbox_path(1)")).to eq(test_routes.inbox_path(1))
145
+ end
140
146
 
141
- it "should render routing with default_format and zero object" do
142
- expect(evaljs("Routes.inbox_path(0)")).to eq(test_routes.inbox_path(0, :format => "json"))
147
+ it "should render routing with default_format and zero object" do
148
+ expect(evaljs("Routes.inbox_path(0)")).to eq(test_routes.inbox_path(0))
149
+ end
143
150
  end
144
151
 
145
152
  it "should override default_format when spefified implicitly" do
@@ -147,13 +154,11 @@ describe JsRoutes, "options" do
147
154
  end
148
155
 
149
156
  it "should override nullify implicitly when specified implicitly" do
150
- expect(evaljs("Routes.inbox_path(1, {format: null})")).to eq(test_routes.inbox_path(1))
157
+ expect(evaljs("Routes.inbox_path(1, {format: null})")).to eq(test_routes.inbox_path(1, format: nil))
151
158
  end
152
159
 
153
-
154
160
  it "shouldn't require the format" do
155
- pending if Rails.version < "4.0"
156
- expect(evaljs("Routes.json_only_path()")).to eq(test_routes.json_only_path(:format => 'json'))
161
+ expect(evaljs("Routes.json_only_path()")).to eq(test_routes.json_only_path)
157
162
  end
158
163
  end
159
164
 
@@ -201,14 +206,14 @@ describe JsRoutes, "options" do
201
206
  context "provided" do
202
207
  let(:_options) { { :default_url_options => { :optional_id => "12", :format => "json" } } }
203
208
  it "should use this opions to fill optional parameters" do
204
- expect(evaljs("Routes.things_path()")).to eq(test_routes.things_path(:optional_id => 12, :format => "json"))
209
+ expect(evaljs("Routes.things_path()")).to eq(test_routes.things_path)
205
210
  end
206
211
  end
207
212
 
208
213
  context "not provided" do
209
214
  let(:_options) { { :default_url_options => { :format => "json" } } }
210
215
  it "breaks" do
211
- expect(evaljs("Routes.foo_all_path()")).to eq(test_routes.foo_all_path(:format => "json"))
216
+ expect(evaljs("Routes.foo_all_path()")).to eq(test_routes.foo_all_path)
212
217
  end
213
218
  end
214
219
  end
@@ -216,7 +221,7 @@ describe JsRoutes, "options" do
216
221
  context "with required route parts" do
217
222
  let(:_options) { {:default_url_options => {:inbox_id => "12"}} }
218
223
  it "should use this opions to fill optional parameters" do
219
- expect(evaljs("Routes.inbox_messages_path()")).to eq(test_routes.inbox_messages_path(:inbox_id => 12))
224
+ expect(evaljs("Routes.inbox_messages_path()")).to eq(test_routes.inbox_messages_path)
220
225
  end
221
226
  end
222
227
 
@@ -248,7 +253,7 @@ describe JsRoutes, "options" do
248
253
  end
249
254
 
250
255
  it "should remove it by params" do
251
- expect(evaljs("Routes.inbox_path(1, {trailing_slash: false})")).to eq(test_routes.inbox_path(1))
256
+ expect(evaljs("Routes.inbox_path(1, {trailing_slash: false})")).to eq(test_routes.inbox_path(1, trailing_slash: false))
252
257
  end
253
258
  end
254
259
 
@@ -70,6 +70,10 @@ describe JsRoutes, "compatibility with Rails" do
70
70
  expect(evaljs("Routes.inbox_path(1, {expanded: true, anchor: 'hello'})")).to eq(test_routes.inbox_path(1, :expanded => true, :anchor => "hello"))
71
71
  end
72
72
 
73
+ it "should support required paramters given as options hash" do
74
+ expect(evaljs("Routes.search_path({q: 'hello'})")).to eq(test_routes.search_path(:q => 'hello'))
75
+ end
76
+
73
77
  it "should use irregular ActiveSupport pluralizations" do
74
78
  expect(evaljs("Routes.budgies_path()")).to eq(test_routes.budgies_path)
75
79
  expect(evaljs("Routes.budgie_path(1)")).to eq(test_routes.budgie_path(1))
@@ -111,6 +115,9 @@ describe JsRoutes, "compatibility with Rails" do
111
115
  it "should support route with parameters" do
112
116
  expect(evaljs("Routes.blog_app_post_path(1)")).to eq(blog_routes.post_path(1))
113
117
  end
118
+ it "should support route with parameters containing symbols that need URI-encoding" do
119
+ expect(evaljs("Routes.blog_app_post_path('#hello')")).to eq(blog_routes.post_path('#hello'))
120
+ end
114
121
  it "should support root path" do
115
122
  expect(evaljs("Routes.blog_app_root_path()")).to eq(blog_routes.root_path)
116
123
  end
@@ -158,6 +165,9 @@ describe JsRoutes, "compatibility with Rails" do
158
165
  expect(evaljs("Routes.inboxes_path({uri: 'http://example.com'})")).to eq(test_routes.inboxes_path(:uri => 'http://example.com'))
159
166
  end
160
167
 
168
+ it "should support nested object null parameters" do
169
+ expect(evaljs("Routes.inboxes_path({hello: {world: null}})")).to eq(test_routes.inboxes_path(:hello => {:world => nil}))
170
+ end
161
171
  end
162
172
 
163
173
 
@@ -170,14 +180,18 @@ describe JsRoutes, "compatibility with Rails" do
170
180
  expect(evaljs("Routes.book_path(['thrillers'], 1)")).to eq(test_routes.book_path(['thrillers'], 1))
171
181
  end
172
182
 
173
- it "should bee support routes globbing as array" do
183
+ it "should support routes globbing as array" do
174
184
  expect(evaljs("Routes.book_path([1, 2, 3], 1)")).to eq(test_routes.book_path([1, 2, 3], 1))
175
185
  end
176
186
 
177
- it "should bee support routes globbing as hash" do
187
+ it "should support routes globbing with slash" do
178
188
  expect(evaljs("Routes.book_path('a_test/b_test/c_test', 1)")).to eq(test_routes.book_path('a_test/b_test/c_test', 1))
179
189
  end
180
190
 
191
+ it "should support routes globbing as hash" do
192
+ expect(evaljs("Routes.book_path('a%b', 1)")).to eq(test_routes.book_path('a%b', 1))
193
+ end
194
+
181
195
  it "should support routes globbing as array with optional params" do
182
196
  expect(evaljs("Routes.book_path([1, 2, 3, 5], 1, {c: '1'})")).to eq(test_routes.book_path([1, 2, 3, 5], 1, { :c => "1" }))
183
197
  end
@@ -189,14 +203,6 @@ describe JsRoutes, "compatibility with Rails" do
189
203
  it "should support routes globbing in book_title route as array with optional params" do
190
204
  expect(evaljs("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'}))
191
205
  end
192
-
193
- it "should support required paramters given as options hash" do
194
- expect(evaljs("Routes.search_path({q: 'hello'})")).to eq(test_routes.search_path(:q => 'hello'))
195
- end
196
-
197
- it "should support nested object null parameters" do
198
- expect(evaljs("Routes.inboxes_path({hello: {world: null}})")).to eq(test_routes.inboxes_path(:hello => {:world => nil}))
199
- end
200
206
  end
201
207
 
202
208
  context "using optional path fragments" do
@@ -234,19 +240,13 @@ describe JsRoutes, "compatibility with Rails" do
234
240
  end
235
241
 
236
242
  it "should skip leading and trailing optional parts" do
237
- skip if Rails.version < '4'
238
243
  expect(evaljs("Routes.thing_deep_path(1, 2)")).to eq(test_routes.thing_deep_path(1, 2))
239
244
  end
240
245
  end
241
246
 
242
247
  context "and including them" do
243
- if Rails.version < '4'
244
- it "should fail when insufficient arguments are given" do
245
- expect { evaljs("Routes.thing_deep_path(1)")}
246
- .to raise_error('Route parameter missing: second_required')
247
- expect { evaljs("Routes.thing_deep_path(1,2)")}
248
- .to raise_error('Route parameter missing: third_required')
249
- end
248
+ it "should fail when insufficient arguments are given" do
249
+ expect { evaljs("Routes.thing_deep_path(2)") }.to raise_error('Route parameter missing: third_required')
250
250
  end
251
251
 
252
252
  it "should include the optional parts" do
@@ -258,6 +258,7 @@ describe JsRoutes, "compatibility with Rails" do
258
258
  expect(evaljs("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))
259
259
  expect(evaljs("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))
260
260
  expect(evaljs("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))
261
+ expect(evaljs("Routes.thing_deep_path(2, 3)")).to eq(test_routes.thing_deep_path(2, 3))
261
262
  expect(evaljs("Routes.thing_deep_path(1, 2, { third_required: 3 })")).to eq(test_routes.thing_deep_path(1, 2, third_required: 3))
262
263
  expect(evaljs("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'}))
263
264
  expect(evaljs("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))
@@ -43,6 +43,21 @@ describe "after Rails initialization" do
43
43
  expect(File.exists?(NAME)).to be_truthy
44
44
  end
45
45
 
46
+ it "should not rewrite routes file if nothing changed" do
47
+ routes_file_mtime = File.mtime(NAME)
48
+ JsRoutes.generate!(NAME)
49
+ expect(File.mtime(NAME)).to eq(routes_file_mtime)
50
+ end
51
+
52
+ it "should rewrite routes file if file content changed" do
53
+ # Change content of existed routes file (add space to the end of file).
54
+ File.open(NAME, 'a') { |f| f << ' ' }
55
+ routes_file_mtime = File.mtime(NAME)
56
+ sleep(1)
57
+ JsRoutes.generate!(NAME)
58
+ expect(File.mtime(NAME)).not_to eq(routes_file_mtime)
59
+ end
60
+
46
61
  context "JsRoutes::Engine" do
47
62
  TEST_ASSET_PATH = Rails.root.join('app','assets','javascripts','test.js')
48
63
 
@@ -86,11 +101,7 @@ describe "after Rails initialization" do
86
101
  Rails.application.config.assets.initialize_on_precompile = false
87
102
  end
88
103
  it "should raise an exception if 3 version" do
89
- if 3 == Rails::VERSION::MAJOR
90
- expect { evaluate(ctx, 'js-routes.js') }.to raise_error(/Cannot precompile/)
91
- else
92
- expect(evaluate(ctx, 'js-routes.js')).to match(/routes = /)
93
- end
104
+ expect(evaluate(ctx, 'js-routes.js')).to match(/routes = /)
94
105
  end
95
106
  end
96
107
 
@@ -7,8 +7,6 @@ require 'rails/all'
7
7
  require 'js-routes'
8
8
  require 'active_support/core_ext/hash/slice'
9
9
  require 'coffee-script'
10
- # fix ends_with? error for rails 3.2
11
- require 'active_support/core_ext/string/starts_ends_with' if 3 == Rails::VERSION::MAJOR
12
10
 
13
11
  if defined?(JRUBY_VERSION)
14
12
  require 'rhino'
@@ -60,13 +58,7 @@ class ::App < Rails::Application
60
58
  config.assets.enabled = true
61
59
  # initialize_on_precompile
62
60
  config.assets.initialize_on_precompile = true
63
-
64
- if 3 == Rails::VERSION::MAJOR
65
- config.paths['config/routes'] << 'spec/config/routes.rb'
66
- else
67
- config.paths['config/routes.rb'] << 'spec/config/routes.rb'
68
- end
69
-
61
+ config.paths['config/routes.rb'] << 'spec/config/routes.rb'
70
62
  config.root = File.expand_path('../dummy', __FILE__)
71
63
  end
72
64
 
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: 1.4.4
4
+ version: 1.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bogdan Gusiev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-07 00:00:00.000000000 Z
11
+ date: 2019-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '3.2'
19
+ version: '4'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '3.2'
26
+ version: '4'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: sprockets-rails
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -155,7 +155,6 @@ files:
155
155
  - Rakefile
156
156
  - Readme.md
157
157
  - app/assets/javascripts/js-routes.js.erb
158
- - gemfiles/rails32.gemfile
159
158
  - gemfiles/rails40_sprockets_2.gemfile
160
159
  - gemfiles/rails40_sprockets_3.gemfile
161
160
  - gemfiles/rails41_sprockets_2.gemfile
@@ -202,7 +201,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
202
201
  version: '0'
203
202
  requirements: []
204
203
  rubyforge_project:
205
- rubygems_version: 2.6.14
204
+ rubygems_version: 2.7.8
206
205
  signing_key:
207
206
  specification_version: 4
208
207
  summary: Brings Rails named routes to javascript
@@ -1,8 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "http://rubygems.org"
4
-
5
- gem "railties", "~> 3.2.22.5"
6
- gem "tzinfo"
7
-
8
- gemspec :path => "../"