Created
August 4, 2015 17:43
-
-
Save chrismcg/10ca3b345a93244c65c0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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