Skip to content

Commit

Permalink
Configure the default Money.Supervisor through the :mod key of applic…
Browse files Browse the repository at this point in the history
…ation in mix.exs
  • Loading branch information
kipcole9 committed Jun 22, 2020
1 parent d29f2be commit e62be56
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
9 changes: 7 additions & 2 deletions lib/money/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@ defmodule Money.Application do

@auto_start :auto_start_exchange_rate_service

def start(_type, _args) do
def start(_type, args) do
children = [
Money.ExchangeRates.Supervisor
]

opts = [strategy: :one_for_one, name: Money.Supervisor]
opts = if args == [] do
[strategy: :one_for_one, name: Money.Supervisor]
else
args
end

supervisor = Supervisor.start_link(children, opts)

if start_exchange_rate_service?() do
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ defmodule Money.Mixfile do

def application do
[
mod: {Money.Application, []},
mod: {Money.Application, [strategy: :one_for_one, name: Money.Supervisor]},
extra_applications: [:inets, :logger]
]
end
Expand Down
8 changes: 8 additions & 0 deletions test/application_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
defmodule Money.Application.Test do
use ExUnit.Case

test "That our default Application supervisor has the default options" do
{_app, options} = Application.spec(:ex_money) |> Keyword.get(:mod)
assert options == [strategy: :one_for_one, name: Money.Supervisor]
end
end

0 comments on commit e62be56

Please sign in to comment.