diff --git a/lib/arc_ecto/schema.ex b/lib/arc_ecto/schema.ex index 3b9a56c..df8465d 100644 --- a/lib/arc_ecto/schema.ex +++ b/lib/arc_ecto/schema.ex @@ -18,7 +18,7 @@ defmodule Arc.Ecto.Schema do end # Cast supports both atom and string keys, ensure we're matching on both. - allowed = Enum.map(allowed, fn key -> + cast_keys = Enum.map(allowed, fn key -> case key do key when is_binary(key) -> key key when is_atom(key) -> Atom.to_string(key) @@ -31,7 +31,7 @@ defmodule Arc.Ecto.Schema do %{} -> params |> Arc.Ecto.Schema.convert_params_to_binary - |> Map.take(allowed) + |> Map.take(cast_keys) |> Enum.reduce([], fn # Don't wrap nil casts in the scope object {field, nil}, fields -> [{field, nil} | fields] diff --git a/mix.exs b/mix.exs index cfcb3c1..5dd5f59 100644 --- a/mix.exs +++ b/mix.exs @@ -4,15 +4,17 @@ defmodule Arc.Ecto.Mixfile do @version "0.11.0" def project do - [app: :arc_ecto, - version: @version, - elixir: "~> 1.4", - elixirc_paths: elixirc_paths(Mix.env), - deps: deps(), - - # Hex - description: description(), - package: package()] + [ + app: :arc_ecto, + version: @version, + elixir: "~> 1.4", + elixirc_paths: elixirc_paths(Mix.env()), + deps: deps(), + + # Hex + description: description(), + package: package() + ] end # Configuration for the OTP application @@ -24,7 +26,7 @@ defmodule Arc.Ecto.Mixfile do # Specifies which paths to compile per environment. defp elixirc_paths(:test), do: ["lib", "test/support"] - defp elixirc_paths(_), do: ["lib"] + defp elixirc_paths(_), do: ["lib"] defp description do """ @@ -33,16 +35,18 @@ defmodule Arc.Ecto.Mixfile do end defp package do - [maintainers: ["Sean Stavropoulos"], - licenses: ["Apache 2.0"], - links: %{"GitHub" => "https://github.com/stavro/arc_ecto"}, - files: ~w(mix.exs README.md lib)] + [ + maintainers: ["Sean Stavropoulos"], + licenses: ["Apache 2.0"], + links: %{"GitHub" => "https://github.com/stavro/arc_ecto"}, + files: ~w(mix.exs README.md lib) + ] end defp deps do [ - {:arc, "~> 0.11.0"}, - {:ecto, "~> 2.1"}, + {:arc, "~> 0.11.0"}, + {:ecto, "~> 3.0.0"}, {:mock, "~> 0.1.1", only: :test}, {:ex_doc, ">= 0.0.0", only: :dev} ] diff --git a/mix.lock b/mix.lock index 3c832cc..aa96867 100644 --- a/mix.lock +++ b/mix.lock @@ -1,23 +1,20 @@ %{ "arc": {:hex, :arc, "0.11.0", "ac7a0cc03035317b6fef9fe94c97d7d9bd183a3e7ce1606aa0c175cfa8d1ba6d", [:mix], [{:ex_aws, "~> 2.0", [hex: :ex_aws, repo: "hexpm", optional: true]}, {:ex_aws_s3, "~> 2.0", [hex: :ex_aws_s3, repo: "hexpm", optional: true]}, {:hackney, "~> 1.0", [hex: :hackney, repo: "hexpm", optional: false]}, {:poison, "~> 2.2 or ~> 3.1", [hex: :poison, repo: "hexpm", optional: true]}, {:sweet_xml, "~> 0.6", [hex: :sweet_xml, repo: "hexpm", optional: true]}], "hexpm"}, "certifi": {:hex, :certifi, "2.4.2", "75424ff0f3baaccfd34b1214184b6ef616d89e420b258bb0a5ea7d7bc628f7f0", [:rebar3], [{:parse_trans, "~>3.3", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm"}, - "decimal": {:hex, :decimal, "1.4.0", "fac965ce71a46aab53d3a6ce45662806bdd708a4a95a65cde8a12eb0124a1333", [:mix], [], "hexpm"}, - "earmark": {:hex, :earmark, "1.0.1", "2c2cd903bfdc3de3f189bd9a8d4569a075b88a8981ded9a0d95672f6e2b63141", [:mix], [], "hexpm"}, - "ecto": {:hex, :ecto, "2.1.4", "d1ba932813ec0e0d9db481ef2c17777f1cefb11fc90fa7c142ff354972dfba7e", [:mix], [{:db_connection, "~> 1.1", [hex: :db_connection, repo: "hexpm", optional: true]}, {:decimal, "~> 1.2", [hex: :decimal, repo: "hexpm", optional: false]}, {:mariaex, "~> 0.8.0", [hex: :mariaex, repo: "hexpm", optional: true]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: true]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.13.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, repo: "hexpm", optional: true]}], "hexpm"}, - "erlcloud": {:hex, :erlcloud, "0.9.2"}, - "ex_doc": {:hex, :ex_doc, "0.13.1", "658dbfc8cc5b0fac192f0f3254efe66ee6294200804a291549e0aeb052053bba", [:mix], [{:earmark, "~> 1.0", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"}, + "decimal": {:hex, :decimal, "1.5.0", "b0433a36d0e2430e3d50291b1c65f53c37d56f83665b43d79963684865beab68", [:mix], [], "hexpm"}, + "earmark": {:hex, :earmark, "1.2.6", "b6da42b3831458d3ecc57314dff3051b080b9b2be88c2e5aa41cd642a5b044ed", [:mix], [], "hexpm"}, + "ecto": {:hex, :ecto, "3.0.0", "059250d96f17f9c10f524fcb09d058f566691343e90318a161cf62a48f3912a9", [:mix], [{:decimal, "~> 1.5", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: true]}], "hexpm"}, + "ex_doc": {:hex, :ex_doc, "0.19.1", "519bb9c19526ca51d326c060cb1778d4a9056b190086a8c6c115828eaccea6cf", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.7", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm"}, "hackney": {:hex, :hackney, "1.14.3", "b5f6f5dcc4f1fba340762738759209e21914516df6be440d85772542d4a5e412", [:rebar3], [{:certifi, "2.4.2", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "6.0.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.4", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm"}, - "httpoison": {:hex, :httpoison, "0.13.0", "bfaf44d9f133a6599886720f3937a7699466d23bb0cd7a88b6ba011f53c6f562", [:mix], [{:hackney, "~> 1.8", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm"}, "idna": {:hex, :idna, "6.0.0", "689c46cbcdf3524c44d5f3dde8001f364cd7608a99556d8fbd8239a5798d4c10", [:rebar3], [{:unicode_util_compat, "0.4.1", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm"}, - "jsx": {:hex, :jsx, "2.1.1"}, - "lhttpc": {:hex, :lhttpc, "1.3.0"}, - "meck": {:hex, :meck, "0.8.3", "4628a1334c69610c5bd558b04dc78d723d8ec5445c123856de34c77f462b5ee5", [:rebar], [], "hexpm"}, + "makeup": {:hex, :makeup, "0.5.5", "9e08dfc45280c5684d771ad58159f718a7b5788596099bdfb0284597d368a882", [:mix], [{:nimble_parsec, "~> 0.4", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm"}, + "makeup_elixir": {:hex, :makeup_elixir, "0.10.0", "0f09c2ddf352887a956d84f8f7e702111122ca32fbbc84c2f0569b8b65cbf7fa", [:mix], [{:makeup, "~> 0.5.5", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm"}, + "meck": {:hex, :meck, "0.8.12", "1f7b1a9f5d12c511848fec26bbefd09a21e1432eadb8982d9a8aceb9891a3cf2", [:rebar3], [], "hexpm"}, "metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm"}, "mimerl": {:hex, :mimerl, "1.0.2", "993f9b0e084083405ed8252b99460c4f0563e41729ab42d9074fd5e52439be88", [:rebar3], [], "hexpm"}, - "mock": {:hex, :mock, "0.1.1", "e21469ca27ba32aa7b18b61699db26f7a778171b21c0e5deb6f1218a53278574", [:mix], [{:meck, "~> 0.8.2", [hex: :meck, repo: "hexpm", optional: false]}], "hexpm"}, - "mogrify": {:hex, :mogrify, "0.1.0"}, + "mock": {:hex, :mock, "0.1.3", "657937b03f88fce89b3f7d6becc9f1ec1ac19c71081aeb32117db9bc4d9b3980", [:mix], [{:meck, "~> 0.8.2", [hex: :meck, repo: "hexpm", optional: false]}], "hexpm"}, + "nimble_parsec": {:hex, :nimble_parsec, "0.4.0", "ee261bb53214943679422be70f1658fff573c5d0b0a1ecd0f18738944f818efe", [:mix], [], "hexpm"}, "parse_trans": {:hex, :parse_trans, "3.3.0", "09765507a3c7590a784615cfd421d101aec25098d50b89d7aa1d66646bc571c1", [:rebar3], [], "hexpm"}, - "poolboy": {:hex, :poolboy, "1.5.1", "6b46163901cfd0a1b43d692657ed9d7e599853b3b21b95ae5ae0a777cf9b6ca8", [:rebar], [], "hexpm"}, "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.4", "f0eafff810d2041e93f915ef59899c923f4568f4585904d010387ed74988e77b", [:make, :mix, :rebar3], [], "hexpm"}, "unicode_util_compat": {:hex, :unicode_util_compat, "0.4.1", "d869e4c68901dd9531385bb0c8c40444ebf624e60b6962d95952775cac5e90cd", [:rebar3], [], "hexpm"}, } diff --git a/test/definition_test.exs b/test/definition_test.exs index ef1a062..5ac4dda 100644 --- a/test/definition_test.exs +++ b/test/definition_test.exs @@ -2,7 +2,7 @@ defmodule ArcTest.Ecto.Definition do use ExUnit.Case test "defines Definition.Type module" do - assert DummyDefinitionTwo.Type.type == Arc.Ecto.Type.type + assert DummyDefinitionTwo.Type.type() == Arc.Ecto.Type.type() end test "falls back to pre-defined url" do @@ -11,18 +11,34 @@ defmodule ArcTest.Ecto.Definition do test "url appends timestamp to url with no query parameters" do updated_at = NaiveDateTime.from_erl!({{2015, 1, 1}, {1, 1, 1}}) - url = DummyDefinitionTwo.url({%{file_name: "test.png", updated_at: updated_at}, :scope}, :original, []) + + url = + DummyDefinitionTwo.url( + {%{file_name: "test.png", updated_at: updated_at}, :scope}, + :original, + [] + ) + assert url == "fallback?v=63587293261" end test "url appends timestamp to url with query parameters" do updated_at = NaiveDateTime.from_erl!({{2015, 1, 1}, {1, 1, 1}}) - url = DummyDefinitionTwo.url({%{file_name: "test.png", updated_at: updated_at}, :scope}, :signed, []) + + url = + DummyDefinitionTwo.url( + {%{file_name: "test.png", updated_at: updated_at}, :scope}, + :signed, + [] + ) + assert url == "fallback?a=1&b=2&v=63587293261" end test "url is unchanged if no timestamp is present" do - url = DummyDefinitionTwo.url({%{file_name: "test.png", updated_at: nil}, :scope}, :original, []) + url = + DummyDefinitionTwo.url({%{file_name: "test.png", updated_at: nil}, :scope}, :original, []) + assert url == "fallback" end end diff --git a/test/schema_test.exs b/test/schema_test.exs index e921b24..350a0d1 100644 --- a/test/schema_test.exs +++ b/test/schema_test.exs @@ -84,7 +84,7 @@ defmodule ArcTest.Ecto.Schema do end test_with_mock "allow_paths => true", DummyDefinition, [store: fn({"/path/to/my/file.png", %TestUser{}}) -> {:ok, "file.png"} end] do - changeset = TestUser.path_changeset(%TestUser{}, %{"avatar" => "/path/to/my/file.png"}) + TestUser.path_changeset(%TestUser{}, %{"avatar" => "/path/to/my/file.png"}) assert called DummyDefinition.store({"/path/to/my/file.png", %TestUser{}}) end end