Skip to content

Instantly share code, notes, and snippets.

@chrismcg
Created August 4, 2015 17:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrismcg/10ca3b345a93244c65c0 to your computer and use it in GitHub Desktop.
Save chrismcg/10ca3b345a93244c65c0 to your computer and use it in GitHub Desktop.
defmodule AuthController do
# ...
def index(conn, _params) do
#...
twitter_client(conn).do_something
#...
end
# Allow replacing the module used to call twitter. This is used in tests to
# stub out the external service
defp twitter_client(conn) do
case conn.private[:twitter_client] do
nil -> Twitter
client -> client
end
end
end
# tests
conn = conn
|> put_private(:twitter_client, StubTwitter)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment