diff --git a/example/config/config.exs b/example/config/config.exs index 6db7ac79..708ac12d 100644 --- a/example/config/config.exs +++ b/example/config/config.exs @@ -2,13 +2,7 @@ # and its dependencies with the aid of the Mix.Config module. use Mix.Config -config :example, ecto_repos: [Example.Repo] - -config :example, Example.Repo, - adapter: Ecto.Adapters.Postgres, - database: "papertrail_example", - username: "postgres", - password: "postgres" +config :example, ecto_repos: [Repo] # This configuration is loaded before any dependency and is restricted # to this project. If another project depends on this project, this @@ -35,4 +29,5 @@ config :example, Example.Repo, # Configuration from the imported file will override the ones defined # here (which is why it is important to import them last). # -# import_config "#{Mix.env}.exs" + +import_config "#{Mix.env}.exs" diff --git a/example/config/development.exs b/example/config/development.exs new file mode 100644 index 00000000..ff4c4a67 --- /dev/null +++ b/example/config/development.exs @@ -0,0 +1,9 @@ +use Mix.Config + +config :example, Repo, + adapter: Ecto.Adapters.Postgres, + database: "papertrail_example_dev", + username: "postgres", + password: "postgres", + hostname: "localhost", + poolsize: 10 diff --git a/example/config/test.exs b/example/config/test.exs new file mode 100644 index 00000000..4b302d6c --- /dev/null +++ b/example/config/test.exs @@ -0,0 +1,9 @@ +use Mix.Config + +config :example, Repo, + adapter: Ecto.Adapters.Postgres, + username: "postgres", + password: "postgres", + database: "paper_trail_example_test", + hostname: "localhost", + pool: Ecto.Adapters.SQL.Sandbox diff --git a/example/lib/example.ex b/example/lib/example.ex index 49144f27..a25e75fa 100644 --- a/example/lib/example.ex +++ b/example/lib/example.ex @@ -1,3 +1,20 @@ -defmodule Example.Repo do - use Ecto.Repo, otp_app: :example +defmodule Example do + use Application + + def start(_type, _args) do + import Supervisor.Spec, warn: false + + children = [ + # Start the endpoint when the application starts + supervisor(Repo, []), + # Start the Ecto repository + # Here you could define other workers and supervisors as children + # worker(Caplair.Worker, [arg1, arg2, arg3]), + ] + + # See http://elixir-lang.org/docs/stable/elixir/Supervisor.html + # for other strategies and supported options + opts = [strategy: :one_for_one, name: Example.Supervisor] + Supervisor.start_link(children, opts) + end end diff --git a/example/lib/repo.ex b/example/lib/repo.ex new file mode 100644 index 00000000..7dca858b --- /dev/null +++ b/example/lib/repo.ex @@ -0,0 +1,3 @@ +defmodule Repo do + use Ecto.Repo, otp_app: :example +end diff --git a/example/mix.exs b/example/mix.exs index 40a52860..ec5ec896 100644 --- a/example/mix.exs +++ b/example/mix.exs @@ -14,7 +14,10 @@ defmodule Example.Mixfile do # # Type "mix help compile.app" for more information def application do - [applications: [:logger, :postgrex, :ecto]] + [ + mod: {Example, []}, + applications: [:logger, :postgrex, :ecto] + ] end # Dependencies can be Hex packages: diff --git a/example/mix.lock b/example/mix.lock index c1518277..8eb408b5 100644 --- a/example/mix.lock +++ b/example/mix.lock @@ -2,7 +2,7 @@ "db_connection": {:hex, :db_connection, "1.0.0-rc.3", "d9ceb670fe300271140af46d357b669983cd16bc0d01206d7d3222dde56cf038", [:mix], [{:sbroker, "~> 1.0.0-beta.3", [hex: :sbroker, optional: true]}, {:poolboy, "~> 1.5", [hex: :poolboy, optional: true]}, {:connection, "~> 1.0.2", [hex: :connection, optional: false]}]}, "decimal": {:hex, :decimal, "1.1.2", "79a769d4657b2d537b51ef3c02d29ab7141d2b486b516c109642d453ee08e00c", [:mix], []}, "ecto": {:hex, :ecto, "2.0.2", "b02331c1f20bbe944dbd33c8ecd8f1ccffecc02e344c4471a891baf3a25f5406", [:mix], [{:poison, "~> 1.5 or ~> 2.0", [hex: :poison, optional: true]}, {:sbroker, "~> 1.0-beta", [hex: :sbroker, optional: true]}, {:mariaex, "~> 0.7.7", [hex: :mariaex, optional: true]}, {:postgrex, "~> 0.11.2", [hex: :postgrex, optional: true]}, {:db_connection, "~> 1.0-rc.2", [hex: :db_connection, optional: true]}, {:decimal, "~> 1.0", [hex: :decimal, optional: false]}, {:poolboy, "~> 1.5", [hex: :poolboy, optional: false]}]}, - "paper_trail": {:hex, :paper_trail, "0.0.5", "796849525b627a469352d3f5a95fccd45841a0bd652f2ae7a33fcd986849a2f4", [:mix], [{:poison, "2.1.0", [hex: :poison, optional: false]}, {:ecto, "~> 2.0.2", [hex: :ecto, optional: false]}, {:postgrex, ">= 0.0.0", [hex: :postgrex, optional: false]}]}, + "paper_trail": {:hex, :paper_trail, "0.0.5", "720e15788bd6c5c40323ae54ded2fa80453e7e8668bc8f8044e01af2c3e9079d", [:mix], [{:poison, "2.1.0", [hex: :poison, optional: false]}, {:ecto, "~> 2.0.2", [hex: :ecto, optional: false]}, {:postgrex, ">= 0.0.0", [hex: :postgrex, optional: false]}]}, "poison": {:hex, :poison, "2.1.0", "f583218ced822675e484648fa26c933d621373f01c6c76bd00005d7bd4b82e27", [:mix], []}, "poolboy": {:hex, :poolboy, "1.5.1", "6b46163901cfd0a1b43d692657ed9d7e599853b3b21b95ae5ae0a777cf9b6ca8", [:rebar], []}, "postgrex": {:hex, :postgrex, "0.11.2", "139755c1359d3c5c6d6e8b1ea72556d39e2746f61c6ddfb442813c91f53487e8", [:mix], [{:connection, "~> 1.0", [hex: :connection, optional: false]}, {:db_connection, "~> 1.0-rc", [hex: :db_connection, optional: false]}, {:decimal, "~> 1.0", [hex: :decimal, optional: false]}]}} diff --git a/example/priv/repo/migrations/20160715113434_create_versions.exs b/example/priv/repo/migrations/20160715134921_add_versions.exs similarity index 86% rename from example/priv/repo/migrations/20160715113434_create_versions.exs rename to example/priv/repo/migrations/20160715134921_add_versions.exs index 002bb55f..425473bc 100644 --- a/example/priv/repo/migrations/20160715113434_create_versions.exs +++ b/example/priv/repo/migrations/20160715134921_add_versions.exs @@ -1,4 +1,4 @@ -defmodule Example.Repo.Migrations.CreateVersions do +defmodule Repo.Migrations.AddVersions do use Ecto.Migration def change do diff --git a/example/test/company_test.exs b/example/test/company_test.exs index 515e6ed2..c510b2f6 100644 --- a/example/test/company_test.exs +++ b/example/test/company_test.exs @@ -1,11 +1,12 @@ defmodule CompanyTest do use ExUnit.Case import Ecto.Query - alias Example.Repo doctest Company test "creating a company creates a company version with correct attributes" do + + # Mix.env |> inspect |> IO.puts new_company = Company.changeset(%Company{}, %{ name: "Acme LLC", is_active: true, city: "Greenwich" }) @@ -19,7 +20,7 @@ defmodule CompanyTest do select: count(company.id) ) - assert company_count == 1 + assert company_count == [1] # assert Map. # company |> inspect |> IO.puts