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 +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/js_routes/engine.rb +24 -18
- data/lib/js_routes/version.rb +1 -1
- data/lib/routes.js +6 -0
- data/lib/routes.js.coffee +3 -1
- data/spec/js_routes/rails_routes_compatibility_spec.rb +18 -3
- data/spec/support/routes.rb +3 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea60a5a1b545228955e4b886562999449511cd91
|
4
|
+
data.tar.gz: 72c3ef411752b3ae5f674a82df98ee09879f8ab9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a8a4432e8eaf2dd39aaa4276adbba282b1d982f72646dd5693bfa1627f03c753d1c1b920489f7c42f5ff431957f3509fbefe3626e877a1779586ba611514e3b
|
7
|
+
data.tar.gz: a31e1fb5b3e7b66f1ed4f1f2712dc3f9e583db041bd60813090de72a909eb881bc2df425ae435c9bebb232208b674f0f86000ac099b670e6281b106f0338d2e2
|
data/CHANGELOG.md
CHANGED
data/lib/js_routes/engine.rb
CHANGED
@@ -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
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
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
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
end
|
65
|
+
config.register_preprocessor(
|
66
|
+
"application/javascript",
|
67
|
+
JsRoutesSprocketsExtension,
|
68
|
+
)
|
62
69
|
end
|
63
|
-
|
64
|
-
|
65
|
-
|
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
|
data/lib/js_routes/version.rb
CHANGED
data/lib/routes.js
CHANGED
@@ -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;
|
data/lib/routes.js.coffee
CHANGED
@@ -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
|
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
|
-
|
211
|
-
|
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
|
data/spec/support/routes.rb
CHANGED
@@ -29,7 +29,9 @@ def draw_routes
|
|
29
29
|
resources :things
|
30
30
|
end
|
31
31
|
|
32
|
-
|
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.
|
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-
|
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.
|
191
|
+
rubygems_version: 2.6.7
|
192
192
|
signing_key:
|
193
193
|
specification_version: 4
|
194
194
|
summary: Brings Rails named routes to javascript
|