js-routes 1.3.0 → 1.3.1

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
2
  SHA1:
3
- metadata.gz: 1b2b15773ea1f4c5fd8870ccda544a7386e28108
4
- data.tar.gz: ffd6b967fd16e89a1d976098da3fa00109924319
3
+ metadata.gz: ea60a5a1b545228955e4b886562999449511cd91
4
+ data.tar.gz: 72c3ef411752b3ae5f674a82df98ee09879f8ab9
5
5
  SHA512:
6
- metadata.gz: 6e5b2c94c2c60924ab690669b61c95075e7bcc3ef576cd8284ee1a7d30aa63427a8826079eece47629cfe31bcafbde00ee63bae5b9f0d39f91a505ae4561c2f6
7
- data.tar.gz: 69f1daf6f674da744d13dd6440af0a70399cfdfe3ecd29a3203c6ec9447e5367baaad19b998c85403c982cfbc6dc04e61f16a55ce796f493c47d69a43932265f
6
+ metadata.gz: 7a8a4432e8eaf2dd39aaa4276adbba282b1d982f72646dd5693bfa1627f03c753d1c1b920489f7c42f5ff431957f3509fbefe3626e877a1779586ba611514e3b
7
+ data.tar.gz: a31e1fb5b3e7b66f1ed4f1f2712dc3f9e583db041bd60813090de72a909eb881bc2df425ae435c9bebb232208b674f0f86000ac099b670e6281b106f0338d2e2
@@ -1,5 +1,9 @@
1
1
  ## master
2
2
 
3
+ ## v1.3.0
4
+
5
+ * Introduce the special _options key. Fixes #86
6
+
3
7
  ## v1.2.9
4
8
 
5
9
  * Fixed deprecation varning on Sprockets 3.7
@@ -42,28 +42,34 @@ 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
+
45
48
  initializer 'js-routes.dependent_on_routes', initializer_args do
46
49
  case sprockets_version
47
- when -> (v) { v2.match?('', v) }
48
- if Rails.application.assets.respond_to?(:register_preprocessor)
49
- routes = Rails.root.join('config', 'routes.rb').to_s
50
- Rails.application.assets.register_preprocessor 'application/javascript', :'js-routes_dependent_on_routes' do |ctx, data|
51
- ctx.depend_on(routes) if ctx.logical_path == 'js-routes'
52
- data
53
- end
54
- end
55
- when -> (v) { v3.match?('', v) }
50
+ when -> (v) { v2.match?('', v) },
51
+ -> (v) { v3.match?('', v) },
52
+ -> (v) { v37.match?('', v) }
53
+
54
+ # It seems rails 3.2 is not working if
55
+ # `Rails.application.config.assets.configure` is used for
56
+ # registering preprocessor
57
+ if is_running_rails_32
58
+ Rails.application.assets.register_preprocessor(
59
+ "application/javascript",
60
+ JsRoutesSprocketsExtension,
61
+ )
62
+ else
63
+ # Other rails version, assumed newer
56
64
  Rails.application.config.assets.configure do |config|
57
- routes = Rails.root.join('config', 'routes.rb').to_s
58
- config.register_preprocessor 'application/javascript', :'js-routes_dependent_on_routes' do |ctx, data|
59
- ctx.depend_on(routes) if ctx.logical_path == 'js-routes'
60
- data
61
- end
65
+ config.register_preprocessor(
66
+ "application/javascript",
67
+ JsRoutesSprocketsExtension,
68
+ )
62
69
  end
63
- when -> (v) { v37.match?('', v) }
64
- Sprockets.register_preprocessor 'application/javascript', JsRoutesSprocketsExtension
65
- else
66
- raise StandardError, "Sprockets version #{sprockets_version} is not supported"
70
+ end
71
+ else
72
+ raise StandardError, "Sprockets version #{sprockets_version} is not supported"
67
73
  end
68
74
  end
69
75
  end
@@ -1,3 +1,3 @@
1
1
  class JsRoutes
2
- VERSION = "1.3.0"
2
+ VERSION = "1.3.1"
3
3
  end
@@ -112,8 +112,14 @@ Based on Rails routes of APP_CLASS
112
112
  property = object;
113
113
  if (this.get_object_type(object) === "object") {
114
114
  if ("to_param" in object) {
115
+ if (object.to_param == null) {
116
+ throw new ParameterMissing("Route parameter missing: to_param");
117
+ }
115
118
  property = object.to_param;
116
119
  } else if ("id" in object) {
120
+ if (object.id == null) {
121
+ throw new ParameterMissing("Route parameter missing: id");
122
+ }
117
123
  property = object.id;
118
124
  } else {
119
125
  property = object;
@@ -64,7 +64,7 @@ Utils =
64
64
 
65
65
  extract_options: (number_of_params, args) ->
66
66
  last_el = args[args.length - 1]
67
- if (args.length > number_of_params and last_el == undefined) or(last_el? and "object" is @get_object_type(last_el) and !@looks_like_serialized_model(last_el))
67
+ if (args.length > number_of_params and last_el == undefined) or (last_el? and "object" is @get_object_type(last_el) and !@looks_like_serialized_model(last_el))
68
68
  options = args.pop() || {}
69
69
  delete options[SpecialOptionsKey]
70
70
  options
@@ -82,8 +82,10 @@ Utils =
82
82
  property = object
83
83
  if @get_object_type(object) is "object"
84
84
  if "to_param" of object
85
+ throw new ParameterMissing("Route parameter missing: to_param") unless object.to_param?
85
86
  property = object.to_param
86
87
  else if "id" of object
88
+ throw new ParameterMissing("Route parameter missing: id") unless object.id?
87
89
  property = object.id
88
90
  else
89
91
  property = object
@@ -61,7 +61,7 @@ describe JsRoutes, "compatibility with Rails" do
61
61
  it 'should support route default subdomain' do
62
62
  # root inside namespace is broken
63
63
  # https://github.com/rails/rails/pull/23235
64
- pending if Rails.version == '5.0.0'
64
+ pending if Rails.version >= '5.0.0' && Rails.version <= "5.0.1"
65
65
  expect(evaljs("Routes.backend_root_path()")).to eq(routes.backend_root_path)
66
66
  end
67
67
 
@@ -207,8 +207,11 @@ describe JsRoutes, "compatibility with Rails" do
207
207
  end
208
208
 
209
209
  context "on nested optional parts" do
210
- it "should include everything that is not optional" do
211
- expect(evaljs("Routes.classic_path({controller: 'classic', action: 'edit'})")).to eq(routes.classic_path(controller: :classic, action: :edit))
210
+ if Rails.version <= "5.0.0"
211
+ # this type of routing is deprecated
212
+ it "should include everything that is not optional" do
213
+ expect(evaljs("Routes.classic_path({controller: 'classic', action: 'edit'})")).to eq(routes.classic_path(controller: :classic, action: :edit))
214
+ end
212
215
  end
213
216
  end
214
217
  end
@@ -232,6 +235,18 @@ describe JsRoutes, "compatibility with Rails" do
232
235
  evaljs("Routes.inbox_path(1,2)")
233
236
  }.to raise_error(js_error_class)
234
237
  end
238
+
239
+ it "should throw Exceptions if when pass id with null" do
240
+ expect {
241
+ evaljs("Routes.inbox_path({id: null})")
242
+ }.to raise_error(js_error_class)
243
+ end
244
+
245
+ it "should throw Exceptions if when pass to_param with null" do
246
+ expect {
247
+ evaljs("Routes.inbox_path({to_param: null})")
248
+ }.to raise_error(js_error_class)
249
+ end
235
250
  end
236
251
 
237
252
  context "when javascript engine without Array#indexOf is used" do
@@ -29,7 +29,9 @@ def draw_routes
29
29
  resources :things
30
30
  end
31
31
 
32
- get "/:controller(/:action(/:id))" => "classic#classic", :as => :classic
32
+ if Rails.version < "5.0.0"
33
+ get "/:controller(/:action(/:id))" => "classic#classic", :as => :classic
34
+ end
33
35
 
34
36
  get "/other_optional/(:optional_id)" => "foo#foo", :as => :foo
35
37
  get '/other_optional(/*optional_id)' => 'foo#foo', :as => :foo_all
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.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bogdan Gusiev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-17 00:00:00.000000000 Z
11
+ date: 2016-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -188,7 +188,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
188
188
  version: '0'
189
189
  requirements: []
190
190
  rubyforge_project:
191
- rubygems_version: 2.5.1
191
+ rubygems_version: 2.6.7
192
192
  signing_key:
193
193
  specification_version: 4
194
194
  summary: Brings Rails named routes to javascript