Skip to content

Commit

Permalink
Return email sent in LocalAdapter with an open_email_in_browser_url c…
Browse files Browse the repository at this point in the history
…onfig (#590)

Commit 6dae907 fixed an issue
where the LocalAdapter.deliver function wasn't returning an `{:ok, any}` response. 

This commit improves upon that by returning the `email` returned from 
`SentEmail.push(email)` as the second argument in `{:ok, any}` -> `{:ok, email}`. 

It also adds a test ensuring that we're correctly returning an `{:ok, _}` tuple 
from the `LocalAdapter.deliver` function.
  • Loading branch information
minhajuddin committed Mar 10, 2021
1 parent 6dae907 commit 69d48e8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/bamboo/adapters/local_adapter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ defmodule Bamboo.LocalAdapter do

@doc "Adds email to `Bamboo.SentEmail`, can automatically open it in new browser tab"
def deliver(email, %{open_email_in_browser_url: open_email_in_browser_url}) do
%{private: %{local_adapter_id: local_adapter_id}} = SentEmail.push(email)

{:ok, open_url_in_browser("#{open_email_in_browser_url}/#{local_adapter_id}")}
delivered_email = SentEmail.push(email)
%{private: %{local_adapter_id: local_adapter_id}} = delivered_email
open_url_in_browser("#{open_email_in_browser_url}/#{local_adapter_id}")
{:ok, delivered_email}
end

def deliver(email, _config) do
Expand All @@ -45,6 +46,8 @@ defmodule Bamboo.LocalAdapter do

def supports_attachments?, do: true

defp open_url_in_browser("test://" <> _), do: :opened

defp open_url_in_browser(url) when is_binary(url) do
case :os.type() do
{:unix, :darwin} -> System.cmd("open", [url])
Expand Down
7 changes: 7 additions & 0 deletions test/lib/bamboo/adapters/local_adapter_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,11 @@ defmodule Bamboo.LocalAdapterTest do

assert [%Bamboo.Email{subject: "This is my email"}] = SentEmail.all()
end

test "using open_email_in_browser_url doesn't raise an error" do
email = new_email(subject: "This is my email")

assert {:ok, _response} =
email |> LocalAdapter.deliver(%{open_email_in_browser_url: "test://"})
end
end

0 comments on commit 69d48e8

Please sign in to comment.