@@ -36,27 +36,6 @@ defmodule Ecto.ChangesetTest do
3636 end
3737 end
3838
39- defmodule CustomSlug do
40- use Ecto.Type
41-
42- def type , do: :string
43- def cast ( val ) , do: { :ok , val }
44- def load ( val ) , do: { :ok , val }
45- def dump ( val ) , do: { :ok , val }
46- end
47-
48- defmodule CustomTag do
49- use Ecto.Type
50-
51- def type , do: { :array , :string }
52- def cast ( val ) when is_list ( val ) , do: { :ok , val }
53- def cast ( _ ) , do: :error
54- def load ( val ) when is_list ( val ) , do: { :ok , val }
55- def load ( _ ) , do: :error
56- def dump ( val ) when is_list ( val ) , do: { :ok , val }
57- def dump ( _ ) , do: :error
58- end
59-
6039 defmodule Email do
6140 use Ecto.Type
6241
@@ -88,14 +67,12 @@ defmodule Ecto.ChangesetTest do
8867 field :token , :integer , primary_key: true
8968 field :title , :string , default: ""
9069 field :author_email , Email
91- field :slug , CustomSlug
9270 field :body
9371 field :uuid , :binary_id
9472 field :color , :binary
9573 field :decimal , :decimal
9674 field :upvotes , :integer , default: 0
9775 field :topics , { :array , :string }
98- field :tags , CustomTag
9976 field :virtual , :string , virtual: true
10077 field :published_at , :naive_datetime
10178 field :source , :map
@@ -120,7 +97,7 @@ defmodule Ecto.ChangesetTest do
12097 end
12198
12299 defp changeset ( schema \\ % Post { } , params ) do
123- cast ( schema , params , ~w( id token title author_email slug body upvotes decimal color topics tags virtual) a )
100+ cast ( schema , params , ~w( id token title author_email body upvotes decimal color topics virtual) a )
124101 end
125102
126103 defmodule CustomError do
@@ -1073,15 +1050,7 @@ defmodule Ecto.ChangesetTest do
10731050 assert changeset . valid?
10741051 end
10751052
1076- test "validate_inclusion/3 with custom type" do
1077- changeset =
1078- changeset ( % { "slug" => "foo" } )
1079- |> validate_inclusion ( :slug , ~w( foo) )
1080- assert changeset . valid?
1081- assert changeset . errors == [ ]
1082- assert validations ( changeset ) == [ slug: { :inclusion , ~w( foo) } ]
1083-
1084- # type with custom equal function
1053+ test "validate_inclusion/3 with custom type and custom equal function" do
10851054 changeset =
10861055 changeset ( % { "author_email" => "[email protected] " } ) 10871056 |> validate_inclusion ( :author_email , [ "[email protected] " ] ) @@ -1121,16 +1090,6 @@ defmodule Ecto.ChangesetTest do
11211090 assert changeset . valid?
11221091 end
11231092
1124- test "validate_subset/3 with custom type" do
1125- changeset =
1126- changeset ( % { "tags" => [ "cute" , "animals" ] } )
1127- |> validate_subset ( :tags , ~w( cute animals) )
1128-
1129- assert changeset . valid?
1130- assert changeset . errors == [ ]
1131- assert validations ( changeset ) == [ tags: { :subset , ~w( cute animals) } ]
1132- end
1133-
11341093 test "validate_exclusion/3" do
11351094 changeset =
11361095 changeset ( % { "title" => "world" } )
@@ -1161,15 +1120,6 @@ defmodule Ecto.ChangesetTest do
11611120 assert changeset . errors == [ value: { "is reserved" , [ validation: :exclusion , enum: decimals ] } ]
11621121 end
11631122
1164- test "validate_exclusion/3 with custom type" do
1165- changeset =
1166- changeset ( % { "slug" => "sun" } )
1167- |> validate_exclusion ( :slug , ~w( moon) )
1168- assert changeset . valid?
1169- assert changeset . errors == [ ]
1170- assert validations ( changeset ) == [ slug: { :exclusion , ~w( moon) } ]
1171- end
1172-
11731123 test "validate_length/3 with string" do
11741124 changeset = changeset ( % { "title" => "world" } ) |> validate_length ( :title , min: 3 , max: 7 )
11751125 assert changeset . valid?
0 commit comments