js-routes 1.1.1 → 1.1.2

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: 7f0198d8ff6f861e2cee2326141e2bb1cbfd974c
4
- data.tar.gz: 1052236ee191127a860aae5a71d22a1b0c7b8613
3
+ metadata.gz: 3c2993fd7d6c758d98b5f7024ab7c21e2be8f600
4
+ data.tar.gz: d89427d56039f4f6922d4b508672fccd2aaf1497
5
5
  SHA512:
6
- metadata.gz: 6894424f650a910ba90b4a8ff1700bf564b320cfe7d124dfe3026a67c988d07ce06e745f8861de83e6c1add80a5bb71a91ecfa329e6523cfff13a344873253d2
7
- data.tar.gz: af3bd894e3936bc2cf1621e0f4b19980887df8d8a3ee3dab99949290328d02ab70b845ea2e09021df951c299ce0d26110e9309fd7bb017497b8702b3574ab52c
6
+ metadata.gz: 85c514ad1542f4d924611c822475b8e667bc4fcc851ddc0239af229bdab77a99c0a625a452af0900050dd90d517cb3696de9e6c26539ba7701f51d960df3b68e
7
+ data.tar.gz: ee8810fec35db2da1c0f025663d994eea6d700e45cd4fb3a7c32ac9da2ab68719614dd9cdbccbad6f5ed4e8ebf9a7d9b6fdcc2175b474861387c8d48473ff564
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## master
2
2
 
3
+ ## v1.1.1
4
+
5
+ * Bugfix regression in serialisation on blank strings caused by [#155](https://github.com/railsware/js-routes/pull/155/files)
6
+
3
7
  ## v1.1.0
4
8
 
5
9
  * Ensure routes are loaded, prior to generating them [#148](https://github.com/railsware/js-routes/pull/148)
@@ -1,3 +1,3 @@
1
1
  class JsRoutes
2
- VERSION = "1.1.1"
2
+ VERSION = "1.1.2"
3
3
  end
data/lib/routes.js CHANGED
@@ -46,13 +46,15 @@ Based on Rails routes of APP_CLASS
46
46
  for (key in object) {
47
47
  if (!hasProp.call(object, key)) continue;
48
48
  prop = object[key];
49
- if (!(prop != null)) {
50
- continue;
49
+ if ((prop == null) && (prefix != null)) {
50
+ prop = "";
51
51
  }
52
- if (prefix != null) {
53
- key = prefix + "[" + key + "]";
52
+ if (prop != null) {
53
+ if (prefix != null) {
54
+ key = prefix + "[" + key + "]";
55
+ }
56
+ s.push(this.default_serializer(prop, key));
54
57
  }
55
- s.push(this.default_serializer(prop, key));
56
58
  }
57
59
  break;
58
60
  default:
@@ -211,7 +213,7 @@ Based on Rails routes of APP_CLASS
211
213
  case NodeTypes.CAT:
212
214
  left_part = this.visit(left, parameters, optional);
213
215
  right_part = this.visit(right, parameters, optional);
214
- if (optional && !(left_part && right_part)) {
216
+ if (optional && (((left[0] === NodeTypes.SYMBOL || left[0] === NodeTypes.CAT) && !left_part) || ((right[0] === NodeTypes.SYMBOL || right[0] === NodeTypes.CAT) && !right_part))) {
215
217
  return "";
216
218
  }
217
219
  return "" + left_part + right_part;
data/lib/routes.js.coffee CHANGED
@@ -26,9 +26,13 @@ Utils =
26
26
  for element, i in object
27
27
  s.push @default_serializer(element, prefix + "[]")
28
28
  when "object"
29
- for own key, prop of object when prop?
30
- key = "#{prefix}[#{key}]" if prefix?
31
- s.push @default_serializer(prop, key)
29
+ for own key, prop of object
30
+ if !prop? and prefix?
31
+ prop = ""
32
+
33
+ if prop?
34
+ key = "#{prefix}[#{key}]" if prefix?
35
+ s.push @default_serializer(prop, key)
32
36
  else
33
37
  if object?
34
38
  s.push "#{encodeURIComponent(prefix.toString())}=#{encodeURIComponent(object.toString())}"
@@ -155,7 +159,8 @@ Utils =
155
159
  when NodeTypes.CAT
156
160
  left_part = @visit(left, parameters, optional)
157
161
  right_part = @visit(right, parameters, optional)
158
- return "" if optional and not (left_part and right_part)
162
+ return "" if optional and (((left[0] == NodeTypes.SYMBOL or left[0] == NodeTypes.CAT) and not left_part) or
163
+ ((right[0] == NodeTypes.SYMBOL or right[0] == NodeTypes.CAT) and not right_part))
159
164
  "#{left_part}#{right_part}"
160
165
  when NodeTypes.SYMBOL
161
166
  value = parameters[left]
@@ -145,9 +145,8 @@ describe JsRoutes, "compatibility with Rails" do
145
145
  expect(evaljs("Routes.search_path({q: 'hello'})")).to eq(routes.search_path(:q => 'hello'))
146
146
  end
147
147
 
148
- it "should ignore null parameters" do
149
- pending
150
- expect(evaljs("Routes.inboxes_path({hello: {world: null}})")).to eq(routes.inboxes_path(:hello => {world: nil}))
148
+ it "should support nested object null parameters" do
149
+ expect(evaljs("Routes.inboxes_path({hello: {world: null}})")).to eq(routes.inboxes_path(:hello => {:world => nil}))
151
150
  end
152
151
  end
153
152
 
@@ -183,6 +182,11 @@ describe JsRoutes, "compatibility with Rails" do
183
182
  expect(evaljs("Routes.things_path({optional_id: 5})")).to eq(routes.things_path(:optional_id => 5))
184
183
  end
185
184
 
185
+ context "on nested optional parts" do
186
+ it "should include everything that is not optional" do
187
+ expect(evaljs("Routes.classic_path({controller: 'classic', action: 'edit'})")).to eq(routes.classic_path(controller: :classic, action: :edit))
188
+ end
189
+ end
186
190
  end
187
191
  end
188
192
 
data/spec/spec_helper.rb CHANGED
@@ -97,6 +97,8 @@ def draw_routes
97
97
  resources :things
98
98
  end
99
99
 
100
+ get "/:controller(/:action(/:id))" => "classic#classic", :as => :classic
101
+
100
102
  get "/other_optional/(:optional_id)" => "foo#foo", :as => :foo
101
103
 
102
104
  get 'books/*section/:title' => 'books#show', :as => :book
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.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bogdan Gusiev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-10 00:00:00.000000000 Z
11
+ date: 2015-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties