Skip to content

Commit 11b7c2d

Browse files
author
José Valim
committed
Fixes to the guides
1 parent 6a47977 commit 11b7c2d

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

guides/howtos/Replicas and dynamic repositories.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ And now you are ready to work with primary and replicas, no hacks or complex dep
106106

107107
## Testing replicas
108108

109-
While all of the work we have done os far should fully work in development and production, it may not be enough for tests. Most developers testing Ecto applications are using a sandbox, such as the [Ecto SQL Sandbox](https://hexdocs.pm/ecto_sql/Ecto.Adapters.SQL.Sandbox.html).
109+
While all of the work we have done so far should fully work in development and production, it may not be enough for tests. Most developers testing Ecto applications are using a sandbox, such as the [Ecto SQL Sandbox](https://hexdocs.pm/ecto_sql/Ecto.Adapters.SQL.Sandbox.html).
110110

111111
When using a sandbox, each of your tests run in an isolated and independent transaction. Once the test is done, the transaction is rolled back. Which means we can trivially revert all of the changes done in a test in a very performant way.
112112

@@ -126,7 +126,7 @@ There are two options to tackle this problem: one is to change replicas and the
126126
One simple solution to the problem above is to use a custom `replica` implementation during tests that always return the primary repository, like this:
127127

128128
```elixir
129-
if Mix.env == :test do
129+
if Mix.env() == :test do
130130
def replica, do: __MODULE__
131131
else
132132
def replica, do: Enum.random(@replicas)
@@ -193,14 +193,14 @@ end
193193
There is even a better way! We can pass a `:default_dynamic_repo` option when we define the repository. In this case, we want to set the `:default_dynamic_repo` to `MyApp.Repo` only during the test environment. In your `lib/my_app/repo.ex`, do this:
194194

195195
```elixir
196-
dynamic_default_repo =
197-
if Mix.env() == :test do
198-
MyApp.Repo
199-
else
200-
__MODULE__
201-
end
202-
203196
for repo <- @replicas do
197+
dynamic_default_repo =
198+
if Mix.env() == :test do
199+
MyApp.Repo
200+
else
201+
repo
202+
end
203+
204204
defmodule repo do
205205
use Ecto.Repo,
206206
otp_app: :my_app,

0 commit comments

Comments
 (0)