Hi,
I am learning elixir and am a relative noob so this might seem basic - hope so
I am writing a package which is primarily a group of plugs which may or may not get used within phoenix, but I donāt want phoenix as a dependency.
However, one of the plugs which is optional, uses ecto.
This ecto plug may or may not get used by the developer so again, I dont want it as a hard dependency for the package but as a test dependency so that I can prove that the plug is building the query correctly.
I asked on the phoenix forum about mocking ecto and testing its generated queries but a few people advised against it and said to use ex_machina and go to the DB instead, so this is the strategy I have taken.
But, in my test, when I try and insert something into the repo, it comes back with this error :-
** (ArgumentError) argument error
(stdlib) :ets.lookup(MyPlugs.Repo.Pool, #PID<0.1616.0>)
(db_connection) lib/db_connection/ownership/manager.ex:53: DBConnection.Ownership.Manager.lookup/2
(db_connection) lib/db_connection/ownership.ex:120: DBConnection.Ownership.checkout/2
(db_connection) lib/db_connection.ex:716: DBConnection.checkout/2
(db_connection) lib/db_connection.ex:623: DBConnection.run/3
(db_connection) lib/db_connection.ex:671: DBConnection.transaction/3
(espec) lib/espec/example_runner.ex:67: ESpec.ExampleRunner.try_run/3
(espec) lib/espec/example_runner.ex:39: ESpec.ExampleRunner.run_example/2
I am thinking that this is because the repo (MyPlugs.Repo) isnāt started ? When I look at a phoenix app, it does :-
children = [
# Start the endpoint when the application starts
supervisor(Products.Endpoint, []),
# Start the Ecto repository
supervisor(Products.Repo, []),
# Here you could define other workers and supervisors as children
# worker(Products.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: Products.Supervisor]
Supervisor.start_link(children, opts)
but in my case, I do not really have an āapplicationā to put this code in (or do I and I just dont know it ?) as the package is just a set of plugs. Please excuse my ignorance on this one, I havenāt ventured into the world of supervised apps yet - I only have a basic understanding of them.
Assuming this is the problem, does anyone know how I can start my repo ? Or does anyone know the real cause of that error if I have assumed wrong ?
Thanks
Gary