From b374ef03df3820692cc44a7e6dac78f621cc3d4d Mon Sep 17 00:00:00 2001 From: Lok Chun Wai Date: Mon, 17 Jul 2023 16:48:37 +0800 Subject: [PATCH 1/2] Fix formatter --- .formatter.exs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.formatter.exs b/.formatter.exs index 55947e8..40e324d 100644 --- a/.formatter.exs +++ b/.formatter.exs @@ -1,8 +1,10 @@ # Used by "mix format" [ inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"], + import: [:ecto], locals_without_parens: [ defenum: :*, - value: :* + value: :*, + default: 1, ] ] From 583fde8f1846d98694c6cf2f7946acc1d0df18d0 Mon Sep 17 00:00:00 2001 From: Lok Chun Wai Date: Mon, 17 Jul 2023 17:08:35 +0800 Subject: [PATCH 2/2] Fix export formatter --- .formatter.exs | 7 +++++-- test/changeset_test.exs | 20 ++++++++++++-------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/.formatter.exs b/.formatter.exs index 40e324d..639b089 100644 --- a/.formatter.exs +++ b/.formatter.exs @@ -1,10 +1,13 @@ # Used by "mix format" [ inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"], - import: [:ecto], + import_deps: [:ecto], locals_without_parens: [ defenum: :*, value: :*, - default: 1, + default: 1 + ], + export: [ + locals_without_parens: [value: :*, default: 1] ] ] diff --git a/test/changeset_test.exs b/test/changeset_test.exs index e2ab0b9..d101138 100644 --- a/test/changeset_test.exs +++ b/test/changeset_test.exs @@ -25,9 +25,8 @@ defmodule EctoTest do end end - test "ecto type type/0" do - assert EctoSchema.Sample.type == :string + assert EctoSchema.Sample.type() == :string end describe "ecto type cast" do @@ -39,7 +38,7 @@ defmodule EctoTest do end test "with string value" do - assert EctoSchema.Sample.cast(EctoSchema.Sample.Red.value) == {:ok, EctoSchema.Sample.Red} + assert EctoSchema.Sample.cast(EctoSchema.Sample.Red.value()) == {:ok, EctoSchema.Sample.Red} end test "with invalid module value" do @@ -53,7 +52,7 @@ defmodule EctoTest do test "ecto type load" do # when loading from the DB, we are guaranteed to have a string version of the atom - assert EctoSchema.Sample.load(EctoSchema.Sample.Red.value) == {:ok, EctoSchema.Sample.Red} + assert EctoSchema.Sample.load(EctoSchema.Sample.Red.value()) == {:ok, EctoSchema.Sample.Red} end describe "ecto type dump" do @@ -62,7 +61,7 @@ defmodule EctoTest do # inserted into the schema struct outside of the changeset and cast # functions at runtime. test "with valid value" do - assert EctoSchema.Sample.dump(EctoSchema.Sample.Red) == {:ok, EctoSchema.Sample.Red.value} + assert EctoSchema.Sample.dump(EctoSchema.Sample.Red) == {:ok, EctoSchema.Sample.Red.value()} end test "with invalid value" do @@ -70,7 +69,6 @@ defmodule EctoTest do end end - describe "changesets" do test "with module value" do changeset = EctoSchema.changeset(%EctoSchema{}, %{color: EctoSchema.Sample.Red}) @@ -87,13 +85,19 @@ defmodule EctoTest do test "with invalid module value" do changeset = EctoSchema.changeset(%EctoSchema{}, %{color: EctoSchema.Sample.Puke}) refute changeset.valid? - assert changeset.errors == [color: {"is invalid", [type: EctoTest.EctoSchema.Sample, validation: :cast]}] + + assert changeset.errors == [ + color: {"is invalid", [type: EctoTest.EctoSchema.Sample, validation: :cast]} + ] end test "with invalid string value" do changeset = EctoSchema.changeset(%EctoSchema{}, %{color: "puke"}) refute changeset.valid? - assert changeset.errors == [color: {"is invalid", [type: EctoTest.EctoSchema.Sample, validation: :cast]}] + + assert changeset.errors == [ + color: {"is invalid", [type: EctoTest.EctoSchema.Sample, validation: :cast]} + ] end end end