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
| class InviteUser | |
| def initialize(mailer: Mailer.new, user_repo: UserRepo.new) | |
| @mailer = mailer | |
| @user_repo = user_repo | |
| end | |
| attr_reader :mailer | |
| attr_reader :user_repo | |
| def invite(email) |
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 InviteUser do | |
| def invite(email, mailer \\ Mailer) do | |
| user = create(email) | |
| mailer.send_activation_mail(user) | |
| end | |
| end |
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 InviteUser do | |
| def invite(email) do | |
| user = create(email) | |
| MyApp.Pact.get("mailer").send_activation_mail(user) | |
| end | |
| end |
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 MyTest do | |
| use ExUnit.Case, async: false | |
| import Mock | |
| test "multiple mocks" do | |
| with_mocks([ | |
| {HashDict, | |
| [], | |
| [get: fn(%{}, "http://example.com") -> "<html></html>" end]}, |
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 MyApp.Mailer do | |
| use Mailgun.Client, [ | |
| domain: Application.fetch_env!(:my_app, :mailgun_domain), | |
| key: Application.fetch_env!(:my_app, :mailgun_key) | |
| ] | |
| @from "support@myapp.com" | |
| def send_test_mail(email) do | |
| {:ok, _} = send_email [ |
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 MyApp.MailerTest do | |
| use ExUnit.Case | |
| test "it uses mock in tests" do | |
| MyApp.Mailer.Mock.clear | |
| MyApp.Mailer.send_test_mail("me@example.com") | |
| assert MyApp.Mailer.Mock.mails |> length == 1 | |
| [mail] = MyApp.Mailer.Mock.mails |
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
| $ mix test | |
| Compiling 16 files (.ex) | |
| == Compilation error on file lib/my_app/mailer.ex == | |
| ** (ArgumentError) application :my_app is not loaded, or the configuration parameter :mailgun_domain is not set | |
| (elixir) lib/application.ex:261: Application.fetch_env!/2 | |
| lib/my_app/mailer.ex:3: (module) | |
| (stdlib) erl_eval.erl:670: :erl_eval.do_apply/6 |
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 MyApp.Mailer do | |
| @from "support@myapp.com" | |
| @mailer_impl Application.fetch_env!(:my_app, :mailer) | |
| defmodule Behaviour do | |
| @callback send_mail([key: String.t]) :: :ok | |
| end | |
| def send_test_mail(email) do | |
| :ok = @mailer_impl.send_mail( |
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 MyApp.Mailer.Mailgun do | |
| @behaviour MyApp.Mailer.Behaviour | |
| use Mailgun.Client, [ | |
| domain: Application.fetch_env!(:my_app, :mailgun_domain), | |
| key: Application.fetch_env!(:my_app, :mailgun_key) | |
| ] | |
| def send_mail(mail) do | |
| {:ok, _} = send_email(mail) |
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
| $ mix test | |
| Compiling 18 files (.ex) | |
| == Compilation error on file lib/my_app/mailer/mailgun.ex == | |
| ** (ArgumentError) application :my_app is not loaded, or the configuration parameter :mailgun_domain is not set | |
| (elixir) lib/application.ex:261: Application.fetch_env!/2 | |
| lib/my_app/mailer/mailgun.ex:5: (module) | |
| (stdlib) erl_eval.erl:670: :erl_eval.do_apply/6 |