@@ -348,6 +348,15 @@ defmodule Mongo.RepoTest do
348
348
|> Map . put ( :title , "updated" )
349
349
|> MyRepo . update ( )
350
350
end
351
+
352
+ test "updates a document without changes" do
353
+ { :ok , post } =
354
+ Post . new ( )
355
+ |> Map . put ( :title , "test" )
356
+ |> MyRepo . insert ( )
357
+
358
+ { :ok , % Post { title: "test" } } = MyRepo . update ( post )
359
+ end
351
360
end
352
361
353
362
describe "update!/1" do
@@ -362,6 +371,15 @@ defmodule Mongo.RepoTest do
362
371
|> Map . put ( :title , "updated" )
363
372
|> MyRepo . update! ( )
364
373
end
374
+
375
+ test "updates a document without changes" do
376
+ { :ok , post } =
377
+ Post . new ( )
378
+ |> Map . put ( :title , "test" )
379
+ |> MyRepo . insert ( )
380
+
381
+ % Post { title: "test" } = MyRepo . update! ( post )
382
+ end
365
383
end
366
384
367
385
describe "insert_or_update/1" do
@@ -388,6 +406,18 @@ defmodule Mongo.RepoTest do
388
406
assert Map . get ( post , :_id ) == Map . get ( updated , :_id )
389
407
assert updated . title == "updated"
390
408
end
409
+
410
+ test "updates a document without changes if it does already exist" do
411
+ { :ok , post } =
412
+ Post . new ( )
413
+ |> Map . put ( :title , "test" )
414
+ |> MyRepo . insert_or_update ( )
415
+
416
+ { :ok , updated } = MyRepo . insert_or_update ( post )
417
+
418
+ assert Map . get ( post , :_id ) == Map . get ( updated , :_id )
419
+ assert updated . title == "test"
420
+ end
391
421
end
392
422
393
423
describe "insert_or_update!/1" do
@@ -414,6 +444,18 @@ defmodule Mongo.RepoTest do
414
444
assert Map . get ( post , :_id ) == Map . get ( updated , :_id )
415
445
assert updated . title == "updated"
416
446
end
447
+
448
+ test "updates a document without changes if it does already exist" do
449
+ post =
450
+ Post . new ( )
451
+ |> Map . put ( :title , "test" )
452
+ |> MyRepo . insert_or_update! ( )
453
+
454
+ updated = MyRepo . insert_or_update! ( post )
455
+
456
+ assert Map . get ( post , :_id ) == Map . get ( updated , :_id )
457
+ assert updated . title == "test"
458
+ end
417
459
end
418
460
419
461
describe "delete/2" do
0 commit comments