Skip to content

Commit

Permalink
test environment configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
izelnakri committed Jul 15, 2016
1 parent ddef880 commit 1fbccdd
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 15 deletions.
11 changes: 3 additions & 8 deletions example/config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
9 changes: 9 additions & 0 deletions example/config/development.exs
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions example/config/test.exs
Original file line number Diff line number Diff line change
@@ -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
21 changes: 19 additions & 2 deletions example/lib/example.ex
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions example/lib/repo.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
defmodule Repo do
use Ecto.Repo, otp_app: :example
end
5 changes: 4 additions & 1 deletion example/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion example/mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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]}]}}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule Example.Repo.Migrations.CreateVersions do
defmodule Repo.Migrations.AddVersions do
use Ecto.Migration

def change do
Expand Down
5 changes: 3 additions & 2 deletions example/test/company_test.exs
Original file line number Diff line number Diff line change
@@ -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"
})
Expand All @@ -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

Expand Down

0 comments on commit 1fbccdd

Please sign in to comment.