File tree 1 file changed +27
-0
lines changed
1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -569,4 +569,31 @@ defmodule Ecto.Changeset.BelongsToTest do
569
569
changeset2 = % { changeset | action: :delete }
570
570
assert Relation . apply_changes ( embed , changeset2 ) == nil
571
571
end
572
+
573
+ test "changed?/2 with assocs" do
574
+ new_profile = % Profile { name: "profile" }
575
+
576
+ changeset =
577
+ % Author { }
578
+ |> Changeset . change ( )
579
+ |> Changeset . put_assoc ( :profile , new_profile )
580
+
581
+ assert Changeset . changed? ( changeset , :profile )
582
+
583
+ { :ok , existing_profile } = TestRepo . insert ( % Profile { name: "profile" } )
584
+
585
+ changeset =
586
+ % Author { }
587
+ |> Changeset . change ( )
588
+ |> Changeset . put_assoc ( :profile , existing_profile )
589
+
590
+ assert Changeset . changed? ( changeset , :profile )
591
+
592
+ changeset =
593
+ % Author { profile: existing_profile }
594
+ |> Changeset . change ( )
595
+ |> Changeset . put_assoc ( :profile , nil )
596
+
597
+ assert Changeset . changed? ( changeset , :profile )
598
+ end
572
599
end
You can’t perform that action at this time.
0 commit comments