diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..64aef49 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,18 @@ +language: elixir +elixir: + - 1.7 +otp_release: + - 20.2.4 +cache: + directories: + - _build + - deps +services: + - postgresql +env: + global: + - MIX_ENV=test +before_script: + - mix do ecto.create, ecto.migrate +script: + - mix test diff --git a/lib/alog.ex b/lib/alog.ex index b730d18..c967446 100644 --- a/lib/alog.ex +++ b/lib/alog.ex @@ -129,7 +129,7 @@ defmodule Alog do from( m in __MODULE__, where: m.entry_id == ^entry_id, - order_by: [desc: :inserted_at], + order_by: [desc: :updated_at], limit: 1, select: m ) @@ -179,7 +179,7 @@ defmodule Alog do end end) end).() - |> order_by([m], desc: m.inserted_at) + |> order_by([m], desc: m.updated_at) |> distinct([m], m.entry_id) |> select([m], m) @@ -209,7 +209,6 @@ defmodule Alog do |> Map.get(:data) |> @repo.preload(__MODULE__.__schema__(:associations)) |> Map.put(:id, nil) - |> Map.put(:inserted_at, nil) |> Map.put(:updated_at, nil) changeset @@ -251,7 +250,7 @@ defmodule Alog do sub = from(m in __MODULE__, distinct: m.entry_id, - order_by: [desc: :inserted_at], + order_by: [desc: :updated_at], select: m ) @@ -346,7 +345,7 @@ defmodule Alog do sub = from(mod in Map.get(module.__schema__(:association, assoc), :queryable), distinct: mod.entry_id, - order_by: [desc: :inserted_at], + order_by: [desc: :updated_at], select: mod ) diff --git a/mix.exs b/mix.exs index b7e96a5..a6e7b9e 100644 --- a/mix.exs +++ b/mix.exs @@ -4,7 +4,7 @@ defmodule Alog.MixProject do def project do [ app: :alog, - version: "0.4.2", + version: "0.5.0", elixir: "~> 1.7", elixirc_paths: elixirc_paths(Mix.env()), start_permanent: Mix.env() == :prod, diff --git a/test/all_test.exs b/test/all_test.exs index 6b89cdf..64b834a 100644 --- a/test/all_test.exs +++ b/test/all_test.exs @@ -18,5 +18,14 @@ defmodule AlogTest.AllTest do assert length(User.all()) == 2 end + + test "all return inserted_at original value" do + {:ok, user} = %User{} |> User.changeset(Helpers.user_3_params()) |> User.insert() + {:ok, user_updated} = user |> User.changeset(%{postcode: "W2 3EC"}) |> User.update() + + [user_all] = User.all() + assert user_all.inserted_at == user.inserted_at + assert user_all.postcode == user_updated.postcode + end end end diff --git a/test/get_by_test.exs b/test/get_by_test.exs index 7bf938a..34fb9ee 100644 --- a/test/get_by_test.exs +++ b/test/get_by_test.exs @@ -38,7 +38,7 @@ defmodule AlogTest.GetByTest do test "does not retrieve outdated results" do {:ok, user} = %User{} |> User.changeset(Helpers.user_1_params()) |> User.insert() - {:ok, updated_user} = user |> User.changeset(%{postcode: "EC3 RST"}) |> User.update() + {:ok, _updated_user} = user |> User.changeset(%{postcode: "EC3 RST"}) |> User.update() assert User.get_by(postcode: "E2 0SY") == nil end @@ -58,7 +58,7 @@ defmodule AlogTest.GetByTest do |> User.changeset(Map.put(Helpers.user_2_params(), :postcode, "E2 0SY")) |> User.insert() - {:ok, updated_user_2} = user_2 |> User.changeset(%{postcode: "EC3 RST"}) |> User.update() + {:ok, _} = user_2 |> User.changeset(%{postcode: "EC3 RST"}) |> User.update() assert User.get_by(postcode: "E2 0SY") == user end diff --git a/test/support/helpers.ex b/test/support/helpers.ex index 2f6e5b5..2374956 100644 --- a/test/support/helpers.ex +++ b/test/support/helpers.ex @@ -6,6 +6,8 @@ defmodule Alog.TestApp.Helpers do def user_2_params(), do: %{name: "Loki", username: "mschfmkr", postcode: "E1 6DR"} + def user_3_params(), do: %{name: "Bob", username: "bobuser", postcode: "E1 7DR"} + def seed_data() do {:ok, item_type} = %ItemType{} |> ItemType.changeset(%{type: "Weapon"}) |> ItemType.insert()