Skip to content

Commit fedd48b

Browse files
jcoglanhulkoba
authored andcommitted
Instruct jiffy to use nil as the Elixir equivalent of the JSON null value
1 parent ad54a11 commit fedd48b

25 files changed

Lines changed: 59 additions & 59 deletions

test/elixir/lib/couch.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ defmodule Couch do
117117

118118
def process_request_body(body) do
119119
if is_map(body) do
120-
:jiffy.encode(body)
120+
:jiffy.encode(body, [:use_nil])
121121
else
122122
body
123123
end
@@ -131,7 +131,7 @@ defmodule Couch do
131131
content_type = headers[:"Content-Type"]
132132

133133
if !!content_type and String.match?(content_type, ~r/application\/json/) do
134-
body |> IO.iodata_to_binary() |> :jiffy.decode([:return_maps])
134+
body |> IO.iodata_to_binary() |> :jiffy.decode([:return_maps, :use_nil])
135135
else
136136
process_response_body(body)
137137
end

test/elixir/lib/couch/dbtest.ex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ defmodule Couch.DBTest do
9090
if prev_value != "" do
9191
url = "/_node/#{node}/_config/#{section}/#{key}"
9292
headers = ["X-Couch-Persist": "false"]
93-
body = :jiffy.encode(prev_value)
93+
body = :jiffy.encode(prev_value, [:use_nil])
9494
resp = Couch.put(url, headers: headers, body: body)
9595
assert resp.status_code == 200
9696
else
@@ -109,7 +109,7 @@ defmodule Couch.DBTest do
109109
Enum.map(resp.body["all_nodes"], fn node ->
110110
url = "/_node/#{node}/_config/#{section}/#{key}"
111111
headers = ["X-Couch-Persist": "false"]
112-
body = :jiffy.encode(value)
112+
body = :jiffy.encode(value, [:use_nil])
113113
resp = Couch.put(url, headers: headers, body: body)
114114
assert resp.status_code == 200
115115
{node, resp.body}
@@ -494,7 +494,7 @@ defmodule Couch.DBTest do
494494
Couch.put(
495495
"/_node/#{node}/_config/#{setting.section}/#{setting.key}",
496496
headers: ["X-Couch-Persist": false],
497-
body: :jiffy.encode(setting.value)
497+
body: :jiffy.encode(setting.value, [:use_nil])
498498
)
499499

500500
assert resp.status_code == 200
@@ -525,7 +525,7 @@ defmodule Couch.DBTest do
525525
Couch.put(
526526
"/_node/#{node}/_config/#{setting.section}/#{setting.key}",
527527
headers: ["X-Couch-Persist": false],
528-
body: :jiffy.encode(value)
528+
body: :jiffy.encode(value, [:use_nil])
529529
)
530530

531531
assert resp.status_code == 200

test/elixir/lib/couch_raw.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ defmodule Rawresp do
4646

4747
def process_request_body(body) do
4848
if is_map(body) do
49-
:jiffy.encode(body)
49+
:jiffy.encode(body, [:use_nil])
5050
else
5151
body
5252
end

test/elixir/test/all_docs_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ defmodule AllDocsTest do
116116
assert row["key"] == "1"
117117
assert row["id"] == "1"
118118
assert row["value"]["deleted"]
119-
assert row["doc"] == :null
119+
assert row["doc"] == nil
120120

121121
# Add conflicts
122122
conflicted_doc1 = %{

test/elixir/test/attachments_multipart_test.exs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ defmodule AttachmentMultipartTest do
152152
assert Enum.at(sections, 2).headers["Content-Disposition"] ==
153153
~s(attachment; filename="bar.txt")
154154

155-
doc = :jiffy.decode(Enum.at(sections, 0).body, [:return_maps])
155+
doc = :jiffy.decode(Enum.at(sections, 0).body, [:return_maps, :use_nil])
156156

157157
assert doc["_attachments"]["foo.txt"]["follows"] == true
158158
assert doc["_attachments"]["bar.txt"]["follows"] == true
@@ -175,7 +175,7 @@ defmodule AttachmentMultipartTest do
175175
sections = parse_multipart(resp)
176176
assert length(sections) == 2
177177

178-
doc = :jiffy.decode(Enum.at(sections, 0).body, [:return_maps])
178+
doc = :jiffy.decode(Enum.at(sections, 0).body, [:return_maps, :use_nil])
179179

180180
assert doc["_attachments"]["foo.txt"]["stub"] == true
181181
assert doc["_attachments"]["bar.txt"]["follows"] == true
@@ -206,7 +206,7 @@ defmodule AttachmentMultipartTest do
206206
assert length(inner_sections) == 2
207207
assert Enum.at(inner_sections, 0).headers["Content-Type"] == "application/json"
208208

209-
doc = :jiffy.decode(Enum.at(inner_sections, 0).body, [:return_maps])
209+
doc = :jiffy.decode(Enum.at(inner_sections, 0).body, [:return_maps, :use_nil])
210210
assert doc["_attachments"]["foo.txt"]["stub"] == true
211211
assert doc["_attachments"]["bar.txt"]["follows"] == true
212212

@@ -228,7 +228,7 @@ defmodule AttachmentMultipartTest do
228228

229229
assert length(sections) == 2
230230

231-
doc = :jiffy.decode(Enum.at(sections, 0).body, [:return_maps])
231+
doc = :jiffy.decode(Enum.at(sections, 0).body, [:return_maps, :use_nil])
232232
assert doc["_attachments"]["foo.txt"]["stub"] == true
233233
assert doc["_attachments"]["bar.txt"]["follows"] == true
234234
assert Enum.at(sections, 1).body == "this is 18 chars l"
@@ -377,7 +377,7 @@ defmodule AttachmentMultipartTest do
377377
assert length(inner_sections) == 3
378378
assert Enum.at(inner_sections, 0).headers["Content-Type"] == "application/json"
379379

380-
doc = :jiffy.decode(Enum.at(inner_sections, 0).body, [:return_maps])
380+
doc = :jiffy.decode(Enum.at(inner_sections, 0).body, [:return_maps, :use_nil])
381381
assert doc["_attachments"]["lorem.txt"]["follows"] == true
382382
assert doc["_attachments"]["lorem.txt"]["encoding"] == "gzip"
383383
assert doc["_attachments"]["data.bin"]["follows"] == true
@@ -414,7 +414,7 @@ defmodule AttachmentMultipartTest do
414414
# 2 inner sections: a document body section plus 1 attachment data section
415415
assert length(inner_sections) == 2
416416
assert Enum.at(inner_sections, 0).headers["Content-Type"] == "application/json"
417-
doc = :jiffy.decode(Enum.at(inner_sections, 0).body, [:return_maps])
417+
doc = :jiffy.decode(Enum.at(inner_sections, 0).body, [:return_maps, :use_nil])
418418
assert doc["_attachments"]["lorem.txt"]["follows"] == true
419419
assert doc["_attachments"]["lorem.txt"]["encoding"] == "gzip"
420420
assert Enum.at(inner_sections, 1).body != lorem
@@ -434,7 +434,7 @@ defmodule AttachmentMultipartTest do
434434
boundary = Enum.at(String.split(boundary_arg, "="), 1)
435435

436436
if String.starts_with?(boundary, ~s(")) do
437-
:jiffy.decode(boundary)
437+
:jiffy.decode(boundary, [:use_nil])
438438
else
439439
boundary
440440
end

test/elixir/test/changes_async_test.exs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ defmodule ChangesAsyncTest do
407407
end
408408

409409
defp parse_chunk(msg) do
410-
msg.chunk |> IO.iodata_to_binary() |> :jiffy.decode([:return_maps])
410+
msg.chunk |> IO.iodata_to_binary() |> :jiffy.decode([:return_maps, :use_nil])
411411
end
412412

413413
defp parse_event(msg) do
@@ -419,7 +419,7 @@ defmodule ChangesAsyncTest do
419419
|> Enum.map(fn p ->
420420
p
421421
|> IO.iodata_to_binary()
422-
|> :jiffy.decode([:return_maps])
422+
|> :jiffy.decode([:return_maps, :use_nil])
423423
end)
424424
end
425425

@@ -497,7 +497,7 @@ defmodule ChangesAsyncTest do
497497
body_lines
498498
|> Enum.filter(fn line -> line != "" end)
499499
|> Enum.map(fn line ->
500-
line |> IO.iodata_to_binary() |> :jiffy.decode([:return_maps])
500+
line |> IO.iodata_to_binary() |> :jiffy.decode([:return_maps, :use_nil])
501501
end)
502502
end
503503

test/elixir/test/changes_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ defmodule ChangesTest do
198198
assert Enum.member?(changes_ids, "doc1")
199199
assert Enum.member?(changes_ids, "doc3")
200200

201-
encoded_doc_ids = doc_ids.doc_ids |> :jiffy.encode()
201+
encoded_doc_ids = doc_ids.doc_ids |> :jiffy.encode([:use_nil])
202202

203203
resp =
204204
Couch.get("/#{db_name}/_changes",

test/elixir/test/config_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ defmodule ConfigTest do
2323
def set_config(context, section, key, val, status_assert) do
2424
url = "#{context[:config_url]}/#{section}/#{key}"
2525
headers = ["X-Couch-Persist": "false"]
26-
resp = Couch.put(url, headers: headers, body: :jiffy.encode(val))
26+
resp = Couch.put(url, headers: headers, body: :jiffy.encode(val, [:use_nil]))
2727

2828
if status_assert do
2929
assert resp.status_code == status_assert

test/elixir/test/design_docs_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ defmodule DesignDocsTest do
222222
result =
223223
resp.body
224224
|> IO.iodata_to_binary()
225-
|> :jiffy.decode([:return_maps])
225+
|> :jiffy.decode([:return_maps, :use_nil])
226226

227227
assert result["language"] == "javascript"
228228
end

test/elixir/test/design_options_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ defmodule DesignOptionsTest do
5050

5151
row_with_key =
5252
resp.body["rows"]
53-
|> Enum.filter(fn p -> p["key"] != :null end)
53+
|> Enum.filter(fn p -> p["key"] != nil end)
5454

5555
assert length(row_with_key) == 2
5656
end

0 commit comments

Comments
 (0)