diff --git a/.formatter.exs b/.formatter.exs
index e287cecf..02dc9964 100644
--- a/.formatter.exs
+++ b/.formatter.exs
@@ -1,7 +1,7 @@
# This file is synced with beam-community/common-config. Any changes will be overwritten.
[
- import_deps: [],
+ import_deps: [:plug],
inputs: ["*.{heex,ex,exs}", "{config,lib,priv,test}/**/*.{heex,ex,exs}"],
line_length: 120,
plugins: []
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
deleted file mode 100644
index 634c0661..00000000
--- a/.github/workflows/ci.yml
+++ /dev/null
@@ -1,67 +0,0 @@
-name: Elixir CI
-
-on:
- pull_request:
- push:
- branches:
- - main
-
-jobs:
- mix_test:
- name: mix test (Elixir ${{matrix.elixir}} | OTP ${{matrix.otp}})
- runs-on: ${{ matrix.os }}
- strategy:
- fail-fast: false
- matrix:
- include:
- - elixir: 1.9.x
- otp: 20
- os: ubuntu-20.04
- - elixir: 1.10.x
- otp: 21
- os: ubuntu-20.04
- - elixir: 1.11.x
- otp: 22
- os: ubuntu-20.04
- - elixir: 1.11.x
- otp: 23
- os: ubuntu-20.04
- - elixir: 1.12.x
- otp: 23
- os: ubuntu-20.04
- - elixir: 1.13.x
- otp: 24
- os: ubuntu-20.04
- - elixir: 1.14.x
- otp: 25
- os: ubuntu-latest
- env:
- MIX_ENV: test
- steps:
- - uses: actions/checkout@v2
- - uses: erlef/setup-beam@v1
- with:
- otp-version: ${{matrix.otp}}
- elixir-version: ${{matrix.elixir}}
- - name: Install Dependencies
- run: |
- mix local.hex --force
- mix local.rebar --force
- mix deps.get --only test
- - name: Cache build artifacts
- uses: actions/cache@v3
- with:
- path: |
- ~/.hex
- ~/.mix
- _build
- key: ${{ matrix.otp }}-${{ matrix.elixir }}-build
- - run: mix compile --warnings-as-errors
- if: matrix.warnings_as_errors
- env:
- CC: gcc-10
- CXX: g++-10
- - run: mix test
- env:
- CC: gcc-10
- CXX: g++-10
diff --git a/LICENSE.txt b/LICENSE.txt
deleted file mode 100644
index ca71df17..00000000
--- a/LICENSE.txt
+++ /dev/null
@@ -1,21 +0,0 @@
-The MIT License (MIT)
-
-Copyright (c) 2016 Paul Smith
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
diff --git a/lib/bamboo/adapters/local_adapter.ex b/lib/bamboo/adapters/local_adapter.ex
index 8d9f6291..4090ac84 100644
--- a/lib/bamboo/adapters/local_adapter.ex
+++ b/lib/bamboo/adapters/local_adapter.ex
@@ -1,3 +1,4 @@
+# credo:disable-for-this-file Credo.Check.Warning.LeakyEnvironment
defmodule Bamboo.LocalAdapter do
@moduledoc """
Stores emails locally. Can be queried to see sent emails.
@@ -25,11 +26,10 @@ defmodule Bamboo.LocalAdapter do
use Bamboo.Mailer, otp_app: :my_app
end
"""
+ @behaviour Bamboo.Adapter
alias Bamboo.SentEmail
- @behaviour Bamboo.Adapter
-
@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
delivered_email = SentEmail.push(email)
diff --git a/lib/bamboo/adapters/mailgun_adapter.ex b/lib/bamboo/adapters/mailgun_adapter.ex
index 4115d21f..1cee394a 100644
--- a/lib/bamboo/adapters/mailgun_adapter.ex
+++ b/lib/bamboo/adapters/mailgun_adapter.ex
@@ -44,14 +44,19 @@ defmodule Bamboo.MailgunAdapter do
base_uri: "https://api.eu.mailgun.net/v3"
"""
-
- @service_name "Mailgun"
- @default_base_uri "https://api.mailgun.net/v3"
@behaviour Bamboo.Adapter
- alias Bamboo.{Email, Attachment, AdapterHelper}
import Bamboo.ApiError
+ alias Bamboo.AdapterHelper
+ alias Bamboo.Attachment
+ alias Bamboo.Email
+
+ @default_base_uri "https://api.mailgun.net/v3"
+ @internal_fields ~w(attachments)a
+ @mailgun_message_fields ~w(from to cc bcc subject text html template recipient-variables)a
+ @service_name "Mailgun"
+
@doc false
def handle_config(config) do
config
@@ -60,20 +65,21 @@ defmodule Bamboo.MailgunAdapter do
|> Map.put_new(:base_uri, base_uri())
end
- defp base_uri() do
+ defp base_uri do
Application.get_env(:bamboo, :mailgun_base_uri, @default_base_uri)
end
defp get_setting(config, key) do
- config[key]
- |> case do
- {:system, var} ->
- System.get_env(var)
+ config_value =
+ case config[key] do
+ {:system, var} ->
+ System.get_env(var)
- value ->
- value
- end
- |> case do
+ value ->
+ value
+ end
+
+ case config_value do
value when value in [nil, ""] ->
raise_missing_setting_error(config, key)
@@ -95,13 +101,10 @@ defmodule Bamboo.MailgunAdapter do
def deliver(email, config) do
body = to_mailgun_body(email)
config = handle_config(config)
+ uri = full_uri(config)
+ headers = headers(email, config)
- case :hackney.post(
- full_uri(config),
- headers(email, config),
- body,
- AdapterHelper.hackney_opts(config)
- ) do
+ case :hackney.post(uri, headers, body, AdapterHelper.hackney_opts(config)) do
{:ok, status, _headers, response} when status > 299 ->
body = decode_body(body)
{:error, build_api_error(@service_name, response, body)}
@@ -171,9 +174,7 @@ defmodule Bamboo.MailgunAdapter do
defp put_bcc(body, %Email{bcc: bcc}), do: Map.put(body, :bcc, prepare_recipients(bcc))
defp prepare_recipients(recipients) do
- recipients
- |> Enum.map(&prepare_recipient(&1))
- |> Enum.join(",")
+ Enum.map_join(recipients, ",", &prepare_recipient(&1))
end
defp prepare_recipient({nil, address}), do: address
@@ -190,6 +191,7 @@ defmodule Bamboo.MailgunAdapter do
defp put_headers(body, %Email{headers: headers}) do
Enum.reduce(headers, body, fn {key, value}, acc ->
+ # credo:disable-for-this-file Credo.Check.Warning.UnsafeToAtom
Map.put(acc, :"h:#{key}", value)
end)
end
@@ -223,6 +225,7 @@ defmodule Bamboo.MailgunAdapter do
custom_vars = Map.get(private, :mailgun_custom_vars, %{})
Enum.reduce(custom_vars, body, fn {key, value}, acc ->
+ # credo:disable-for-this-file Credo.Check.Warning.UnsafeToAtom
Map.put(acc, :"v:#{key}", value)
end)
end
@@ -240,10 +243,7 @@ defmodule Bamboo.MailgunAdapter do
defp put_attachments(body, %Email{attachments: []}), do: body
defp put_attachments(body, %Email{attachments: attachments}) do
- attachment_data =
- attachments
- |> Enum.reverse()
- |> Enum.map(&prepare_file(&1))
+ attachment_data = Enum.map(attachments, &prepare_file(&1))
Map.put(body, :attachments, attachment_data)
end
@@ -252,14 +252,12 @@ defmodule Bamboo.MailgunAdapter do
{"", attachment.data, {"form-data", [{"name", ~s/"attachment"/}, {"filename", ~s/"#{attachment.filename}"/}]}, []}
end
- @mailgun_message_fields ~w(from to cc bcc subject text html template recipient-variables)a
- @internal_fields ~w(attachments)a
-
def filter_non_empty_mailgun_fields(body) do
- Enum.filter(body, fn {key, value} ->
+ body
+ |> Enum.filter(fn {key, value} ->
# Key is a well known mailgun field (including header and custom var field) and its value is not empty
(key in @mailgun_message_fields || key in @internal_fields ||
- String.starts_with?(Atom.to_string(key), ["h:", "v:", "o:", "t:"])) &&
+ key |> Atom.to_string() |> String.starts_with?(["h:", "v:", "o:", "t:"])) &&
!(value in [nil, "", []])
end)
|> Enum.into(%{})
diff --git a/lib/bamboo/adapters/mailgun_helper.ex b/lib/bamboo/adapters/mailgun_helper.ex
index 6d080ea5..c4ce6628 100644
--- a/lib/bamboo/adapters/mailgun_helper.ex
+++ b/lib/bamboo/adapters/mailgun_helper.ex
@@ -113,7 +113,7 @@ defmodule Bamboo.MailgunHelper do
|> MailgunHelper.substitute_variables(%{ "greeting" => "Hello!", "password_reset_link" => "https://example.com/123" })
"""
- def substitute_variables(%Email{headers: headers} = email, variables = %{}) do
+ def substitute_variables(%Email{headers: headers} = email, %{} = variables) do
custom_vars =
headers
|> Map.get(@mailgun_header_for_custom_vars, "{}")
diff --git a/lib/bamboo/adapters/mandrill_adapter.ex b/lib/bamboo/adapters/mandrill_adapter.ex
index fc17cadc..4505d951 100644
--- a/lib/bamboo/adapters/mandrill_adapter.ex
+++ b/lib/bamboo/adapters/mandrill_adapter.ex
@@ -21,15 +21,16 @@ defmodule Bamboo.MandrillAdapter do
use Bamboo.Mailer, otp_app: :my_app
end
"""
+ @behaviour Bamboo.Adapter
+
+ import Bamboo.ApiError
+
+ alias Bamboo.AdapterHelper
- @service_name "Mandrill"
@default_base_uri "https://mandrillapp.com"
@send_message_path "api/1.0/messages/send.json"
@send_message_template_path "api/1.0/messages/send-template.json"
- @behaviour Bamboo.Adapter
-
- alias Bamboo.AdapterHelper
- import Bamboo.ApiError
+ @service_name "Mandrill"
def deliver(email, config) do
api_key = get_key(config)
@@ -81,8 +82,7 @@ defmodule Bamboo.MandrillAdapter do
end
defp convert_to_mandrill_params(email, api_key) do
- %{key: api_key, message: message_params(email)}
- |> maybe_put_template_params(email)
+ maybe_put_template_params(%{key: api_key, message: message_params(email)}, email)
end
defp maybe_put_template_params(params, %{
@@ -97,8 +97,8 @@ defmodule Bamboo.MandrillAdapter do
defp message_params(email) do
%{
- from_name: email.from |> elem(0),
- from_email: email.from |> elem(1),
+ from_name: elem(email.from, 0),
+ from_email: elem(email.from, 1),
to: recipients(email),
subject: email.subject,
text: email.text_body,
@@ -113,7 +113,7 @@ defmodule Bamboo.MandrillAdapter do
{images, files} =
attachments
|> Enum.reverse()
- |> Enum.split_with(&is_inline_image?/1)
+ |> Enum.split_with(&inline_image?/1)
mandrill_message
|> Map.put(:attachments, format_attachments(files))
@@ -130,7 +130,7 @@ defmodule Bamboo.MandrillAdapter do
defp format_attachments(attachments) do
Enum.map(attachments, fn attachment ->
- name = if is_inline_image?(attachment), do: attachment.content_id, else: attachment.filename
+ name = if inline_image?(attachment), do: attachment.content_id, else: attachment.filename
%{
name: name,
@@ -140,10 +140,10 @@ defmodule Bamboo.MandrillAdapter do
end)
end
- defp is_inline_image?(%_{content_type: "image/" <> _, content_id: cid}) when not is_nil(cid),
+ defp inline_image?(%_{content_type: "image/" <> _, content_id: cid}) when is_binary(cid),
do: true
- defp is_inline_image?(_), do: false
+ defp inline_image?(_), do: false
defp recipients(email) do
[]
@@ -154,14 +154,14 @@ defmodule Bamboo.MandrillAdapter do
defp add_recipients(recipients, new_recipients, type: recipient_type) do
Enum.reduce(new_recipients, recipients, fn recipient, recipients ->
- recipients ++
- [
- %{
- name: recipient |> elem(0),
- email: recipient |> elem(1),
- type: recipient_type
- }
- ]
+ [
+ %{
+ name: elem(recipient, 0),
+ email: elem(recipient, 1),
+ type: recipient_type
+ }
+ | recipients
+ ]
end)
end
diff --git a/lib/bamboo/adapters/mandrill_helper.ex b/lib/bamboo/adapters/mandrill_helper.ex
index 5ee82062..8b0dca27 100644
--- a/lib/bamboo/adapters/mandrill_helper.ex
+++ b/lib/bamboo/adapters/mandrill_helper.ex
@@ -78,11 +78,12 @@ defmodule Bamboo.MandrillHelper do
}
end)
- email |> put_param("merge_vars", merge_vars)
+ put_param(email, "merge_vars", merge_vars)
end
defp merge_vars(e, fun) do
- fun.(e)
+ e
+ |> fun.()
|> Enum.map(fn {key, value} ->
%{
name: to_string(key),
diff --git a/lib/bamboo/adapters/send_grid_adapter.ex b/lib/bamboo/adapters/send_grid_adapter.ex
index 8121d185..d906809b 100644
--- a/lib/bamboo/adapters/send_grid_adapter.ex
+++ b/lib/bamboo/adapters/send_grid_adapter.ex
@@ -36,15 +36,18 @@ defmodule Bamboo.SendGridAdapter do
end
"""
-
- @service_name "SendGrid"
- @default_base_uri "https://api.sendgrid.com/v3/"
- @send_message_path "/mail/send"
@behaviour Bamboo.Adapter
- alias Bamboo.{Email, AdapterHelper, Formatter}
import Bamboo.ApiError
+ alias Bamboo.AdapterHelper
+ alias Bamboo.Email
+ alias Bamboo.Formatter
+
+ @default_base_uri "https://api.sendgrid.com/v3/"
+ @send_message_path "/mail/send"
+ @service_name "SendGrid"
+
def deliver(email, config) do
api_key = get_key(config)
@@ -165,7 +168,7 @@ defmodule Bamboo.SendGridAdapter do
end
end
- defp build_personalization(personalization = %{to: to}) do
+ defp build_personalization(%{to: to} = personalization) do
%{to: cast_addresses(to, :to)}
|> map_put_if(personalization, :cc, &cast_addresses(&1, :cc))
|> map_put_if(personalization, :bcc, &cast_addresses(&1, :bcc))
@@ -232,7 +235,7 @@ defmodule Bamboo.SendGridAdapter do
defp put_headers(body, _), do: body
- defp put_subject(body, %Email{subject: subject}) when not is_nil(subject),
+ defp put_subject(body, %Email{subject: subject}) when is_binary(subject),
do: Map.put(body, :subject, subject)
defp put_subject(body, _), do: body
@@ -240,7 +243,7 @@ defmodule Bamboo.SendGridAdapter do
defp put_content(body, email) do
email_content = content(email)
- if not Enum.empty?(email_content) do
+ if length(email_content) > 0 do
Map.put(body, :content, content(email))
else
body
@@ -292,9 +295,9 @@ defmodule Bamboo.SendGridAdapter do
defp put_dynamic_template_data(body, _), do: body
- defp put_custom_args(body, %Email{private: %{custom_args: custom_args}})
- when is_nil(custom_args) or length(custom_args) == 0,
- do: body
+ defp put_custom_args(body, %Email{private: %{custom_args: []}}), do: body
+
+ defp put_custom_args(body, %Email{private: %{custom_args: nil}}), do: body
defp put_custom_args(body, %Email{
private: %{custom_args: custom_args}
@@ -306,23 +309,20 @@ defmodule Bamboo.SendGridAdapter do
defp put_categories(body, %Email{private: %{categories: categories}})
when is_list(categories) and length(categories) <= 10 do
- body
- |> Map.put(:categories, categories)
+ Map.put(body, :categories, categories)
end
defp put_categories(body, _), do: body
defp put_send_at(body, %Email{private: %{sendgrid_send_at: send_at_timestamp}}) do
- body
- |> Map.put(:send_at, send_at_timestamp)
+ Map.put(body, :send_at, send_at_timestamp)
end
defp put_send_at(body, _), do: body
defp put_asm_group_id(body, %Email{private: %{asm_group_id: asm_group_id}})
when is_integer(asm_group_id) do
- body
- |> Map.put(:asm, %{group_id: asm_group_id})
+ Map.put(body, :asm, %{group_id: asm_group_id})
end
defp put_asm_group_id(body, _), do: body
@@ -334,8 +334,7 @@ defmodule Bamboo.SendGridAdapter do
|> Map.get(:mail_settings, %{})
|> Map.put(:bypass_list_management, %{enable: enabled})
- body
- |> Map.put(:mail_settings, mail_settings)
+ Map.put(body, :mail_settings, mail_settings)
end
defp put_bypass_list_management(body, _), do: body
@@ -343,15 +342,14 @@ defmodule Bamboo.SendGridAdapter do
defp put_google_analytics(body, %Email{
private: %{google_analytics_enabled: enabled, google_analytics_utm_params: utm_params}
}) do
- ganalytics = %{enable: enabled} |> Map.merge(utm_params)
+ ganalytics = Map.merge(%{enable: enabled}, utm_params)
tracking_settings =
body
|> Map.get(:tracking_settings, %{})
|> Map.put(:ganalytics, ganalytics)
- body
- |> Map.put(:tracking_settings, tracking_settings)
+ Map.put(body, :tracking_settings, tracking_settings)
end
defp put_google_analytics(body, _), do: body
@@ -362,8 +360,7 @@ defmodule Bamboo.SendGridAdapter do
|> Map.get(:tracking_settings, %{})
|> Map.put(:click_tracking, %{enable: enabled, enable_text: enabled})
- body
- |> Map.put(:tracking_settings, tracking_settings)
+ Map.put(body, :tracking_settings, tracking_settings)
end
defp put_click_tracking(body, _), do: body
diff --git a/lib/bamboo/adapters/send_grid_helper.ex b/lib/bamboo/adapters/send_grid_helper.ex
index 1972d336..eda7b5db 100644
--- a/lib/bamboo/adapters/send_grid_helper.ex
+++ b/lib/bamboo/adapters/send_grid_helper.ex
@@ -31,14 +31,12 @@ defmodule Bamboo.SendGridHelper do
## Example
- email
- |> with_template("80509523-83de-42b6-a2bf-54b7513bd2aa")
+ with_template(email, "80509523-83de-42b6-a2bf-54b7513bd2aa")
"""
def with_template(email, template_id) do
template = Map.get(email.private, @field_name, %{})
- email
- |> Email.put_private(@field_name, set_template(template, template_id))
+ Email.put_private(email, @field_name, set_template(template, template_id))
end
@doc """
@@ -56,8 +54,7 @@ defmodule Bamboo.SendGridHelper do
if is_binary(tag) do
template = Map.get(email.private, @field_name, %{})
- email
- |> Email.put_private(@field_name, add_substitution(template, tag, value))
+ Email.put_private(email, @field_name, add_substitution(template, tag, value))
else
raise "expected the tag parameter to be of type binary, got #{tag}"
end
@@ -80,8 +77,7 @@ defmodule Bamboo.SendGridHelper do
|> MapSet.new()
|> MapSet.to_list()
- email
- |> Email.put_private(@categories, Enum.slice(categories, 0, 10))
+ Email.put_private(email, @categories, Enum.slice(categories, 0, 10))
end
def with_categories(_email, _categories) do
@@ -121,8 +117,7 @@ defmodule Bamboo.SendGridHelper do
def add_dynamic_field(email, field, value) when is_binary(field) do
template = Map.get(email.private, @field_name, %{})
- email
- |> Email.put_private(@field_name, add_dynamic_field_to_template(template, field, value))
+ Email.put_private(email, @field_name, add_dynamic_field_to_template(template, field, value))
end
def add_dynamic_field(_email, field, _value),
@@ -139,8 +134,7 @@ defmodule Bamboo.SendGridHelper do
|> with_asm_group_id(1234)
"""
def with_asm_group_id(email, asm_group_id) when is_integer(asm_group_id) do
- email
- |> Email.put_private(@asm_group_id, asm_group_id)
+ Email.put_private(email, @asm_group_id, asm_group_id)
end
def with_asm_group_id(_email, asm_group_id) do
@@ -161,8 +155,7 @@ defmodule Bamboo.SendGridHelper do
|> with_bypass_list_management(true)
"""
def with_bypass_list_management(email, enabled) when is_boolean(enabled) do
- email
- |> Email.put_private(@bypass_list_management, enabled)
+ Email.put_private(email, @bypass_list_management, enabled)
end
def with_bypass_list_management(_email, enabled) do
@@ -188,9 +181,7 @@ defmodule Bamboo.SendGridHelper do
def with_google_analytics(email, enabled, utm_params)
when is_boolean(enabled) do
- utm_params =
- utm_params
- |> Map.take(@allowed_google_analytics_utm_params)
+ utm_params = Map.take(utm_params, @allowed_google_analytics_utm_params)
email
|> Email.put_private(@google_analytics_enabled, enabled)
@@ -235,17 +226,15 @@ defmodule Bamboo.SendGridHelper do
email
|> with_send_at(delivery_time)
"""
- @spec with_send_at(%Email{}, %DateTime{} | integer()) :: %Email{}
+ @spec with_send_at(Email.t(), DateTime.t() | integer()) :: Email.t()
def with_send_at(email, %DateTime{} = time) do
timestamp = DateTime.to_unix(time)
- email
- |> Email.put_private(@send_at_field, timestamp)
+ Email.put_private(email, @send_at_field, timestamp)
end
def with_send_at(email, unix_timestamp) when is_integer(unix_timestamp) do
- email
- |> Email.put_private(@send_at_field, unix_timestamp)
+ Email.put_private(email, @send_at_field, unix_timestamp)
end
def with_send_at(_email, _time) do
@@ -288,25 +277,21 @@ defmodule Bamboo.SendGridHelper do
"""
@spec add_personalizations(Bamboo.Email.t(), [map]) :: Bamboo.Email.t()
def add_personalizations(email, personalizations) when is_list(personalizations) do
- email
- |> Email.put_private(@additional_personalizations, personalizations)
+ Email.put_private(email, @additional_personalizations, personalizations)
end
defp set_template(template, template_id) do
- template
- |> Map.merge(%{template_id: template_id})
+ Map.merge(template, %{template_id: template_id})
end
defp add_substitution(template, tag, value) do
- template
- |> Map.update(:substitutions, %{tag => value}, fn substitutions ->
+ Map.update(template, :substitutions, %{tag => value}, fn substitutions ->
Map.merge(substitutions, %{tag => value})
end)
end
defp add_dynamic_field_to_template(template, field, value) do
- template
- |> Map.update(:dynamic_template_data, %{field => value}, fn dynamic_data ->
+ Map.update(template, :dynamic_template_data, %{field => value}, fn dynamic_data ->
Map.merge(dynamic_data, %{field => value})
end)
end
@@ -320,8 +305,7 @@ defmodule Bamboo.SendGridHelper do
|> with_ip_pool_name("my-ip-pool-name")
"""
def with_ip_pool_name(email, ip_pool_name) do
- email
- |> Email.put_private(@ip_pool_name_field, ip_pool_name)
+ Email.put_private(email, @ip_pool_name_field, ip_pool_name)
end
@doc """
@@ -336,11 +320,11 @@ defmodule Bamboo.SendGridHelper do
"""
def with_custom_args(email, custom_args) when is_map(custom_args) do
custom_args =
- Map.get(email.private, @custom_args, %{})
+ email.private
+ |> Map.get(@custom_args, %{})
|> Map.merge(custom_args)
- email
- |> Email.put_private(@custom_args, custom_args)
+ Email.put_private(email, @custom_args, custom_args)
end
def with_custom_args(_email, _custom_args) do
diff --git a/lib/bamboo/email.ex b/lib/bamboo/email.ex
index 4cadc33d..62d273f7 100644
--- a/lib/bamboo/email.ex
+++ b/lib/bamboo/email.ex
@@ -71,6 +71,12 @@ defmodule Bamboo.Email do
end
"""
+ alias Bamboo.Attachment
+ alias Bamboo.Email
+
+ @address_functions ~w(from to cc bcc)a
+ @attribute_pipe_functions ~w(subject text_body html_body)a
+
@type address :: {String.t(), String.t()}
@type address_list :: nil | address | [address] | any
@@ -100,11 +106,6 @@ defmodule Bamboo.Email do
private: %{},
blocked: false
- alias Bamboo.{Email, Attachment}
-
- @address_functions ~w(from to cc bcc)a
- @attribute_pipe_functions ~w(subject text_body html_body)a
-
@doc """
Used to create a new email
@@ -122,6 +123,7 @@ defmodule Bamboo.Email do
struct!(%__MODULE__{}, attrs)
end
+ # credo:disable-for-this-file Credo.Check.Readability.StrictModuleLayout
for function_name <- @address_functions do
@doc """
Sets the `#{function_name}` on the email.
diff --git a/lib/bamboo/formatter.ex b/lib/bamboo/formatter.ex
index 0c6e0aed..0004ac34 100644
--- a/lib/bamboo/formatter.ex
+++ b/lib/bamboo/formatter.ex
@@ -71,7 +71,7 @@ end
defimpl Bamboo.Formatter, for: List do
def format_email_address(email_addresses, opts) do
- email_addresses |> Enum.map(&Bamboo.Formatter.format_email_address(&1, opts))
+ Enum.map(email_addresses, &Bamboo.Formatter.format_email_address(&1, opts))
end
end
diff --git a/lib/bamboo/mailer.ex b/lib/bamboo/mailer.ex
index ea879e31..ccd876cc 100644
--- a/lib/bamboo/mailer.ex
+++ b/lib/bamboo/mailer.ex
@@ -52,15 +52,15 @@ defmodule Bamboo.Mailer do
You are now able to send emails with your mailer module where you see fit
within your application.
"""
+ require Logger
+
+ alias Bamboo.Formatter
@cannot_call_directly_error """
cannot call Bamboo.Mailer directly. Instead implement your own Mailer module
with: use Bamboo.Mailer, otp_app: :my_app
"""
- require Logger
- alias Bamboo.Formatter
-
defmacro __using__(opts) do
quote bind_quoted: [opts: opts] do
@spec deliver_now(Bamboo.Email.t(), Enum.t()) ::
@@ -294,9 +294,8 @@ defmodule Bamboo.Mailer do
defp validate(email, adapter) do
with :ok <- validate_from_address(email),
- :ok <- validate_recipients(email),
- :ok <- validate_attachment_support(email, adapter) do
- :ok
+ :ok <- validate_recipients(email) do
+ validate_attachment_support(email, adapter)
end
end
@@ -322,31 +321,30 @@ defmodule Bamboo.Mailer do
defp validate_from_address(_email), do: :ok
defp validate_recipients(%Bamboo.Email{} = email) do
- if Enum.all?(
- Enum.map([:to, :cc, :bcc], &Map.get(email, &1)),
- &is_nil_recipient?/1
- ) do
+ recipients = Enum.map([:to, :cc, :bcc], &Map.get(email, &1))
+
+ if Enum.all?(recipients, &nil_recipient?/1) do
{:error, Bamboo.NilRecipientsError.exception(email)}
else
:ok
end
end
- defp is_nil_recipient?(nil), do: true
- defp is_nil_recipient?({_, nil}), do: true
- defp is_nil_recipient?([]), do: false
+ defp nil_recipient?(nil), do: true
+ defp nil_recipient?({_, nil}), do: true
+ defp nil_recipient?([]), do: false
- defp is_nil_recipient?([_ | _] = recipients) do
- Enum.all?(recipients, &is_nil_recipient?/1)
+ defp nil_recipient?([_ | _] = recipients) do
+ Enum.all?(recipients, &nil_recipient?/1)
end
- defp is_nil_recipient?(_), do: false
+ defp nil_recipient?(_), do: false
defp apply_interceptors(email, config) do
interceptors = config[:interceptors] || []
Enum.reduce(interceptors, email, fn interceptor, email ->
- apply(interceptor, :call, [email])
+ interceptor.call(email)
end)
end
@@ -378,8 +376,9 @@ defmodule Bamboo.Mailer do
|> handle_adapter_config
end
- defp handle_adapter_config(base_config = %{adapter: adapter}) do
- adapter.handle_config(base_config)
+ defp handle_adapter_config(%{adapter: adapter} = base_config) do
+ base_config
+ |> adapter.handle_config()
|> Map.put_new(:deliver_later_strategy, Bamboo.TaskSupervisorStrategy)
end
end
diff --git a/lib/bamboo/plug/sent_email_api/sent_email_api_plug.ex b/lib/bamboo/plug/sent_email_api/sent_email_api_plug.ex
index 6e19dbd8..7e16ff4e 100644
--- a/lib/bamboo/plug/sent_email_api/sent_email_api_plug.ex
+++ b/lib/bamboo/plug/sent_email_api/sent_email_api_plug.ex
@@ -1,7 +1,4 @@
defmodule Bamboo.SentEmailApiPlug do
- use Plug.Router
- alias Bamboo.SentEmail
-
@moduledoc """
A plug that exposes delivered emails over a JSON API.
@@ -65,28 +62,27 @@ defmodule Bamboo.SentEmailApiPlug do
if the address didn't specify a name. The `to`, `cc` and `bcc` fields are
returned as arrays of these pairs.
"""
+ use Plug.Router
+
+ alias Bamboo.SentEmail
plug(:match)
plug(:dispatch)
get "/emails.json" do
- data =
- SentEmail.all()
- |> Enum.map(&format_json_email/1)
+ data = Enum.map(SentEmail.all(), &format_json_email/1)
- conn
- |> send_json(:ok, data)
+ send_json(conn, :ok, data)
end
post "/reset.json" do
SentEmail.reset()
- conn
- |> send_json(:ok, %{ok: true})
+ send_json(conn, :ok, %{ok: true})
end
defp send_json(conn, status, data) do
- body = data |> Bamboo.json_library().encode!()
+ body = Bamboo.json_library().encode!(data)
conn
|> Plug.Conn.put_resp_content_type("application/json")
@@ -103,7 +99,7 @@ defmodule Bamboo.SentEmailApiPlug do
end
defp format_json_email_addresses(addresses) do
- addresses |> Enum.map(&format_json_email_address/1)
+ Enum.map(addresses, &format_json_email_address/1)
end
defp format_json_email_address({name, address}) do
diff --git a/lib/bamboo/plug/sent_email_viewer/email_preview_plug.ex b/lib/bamboo/plug/sent_email_viewer/email_preview_plug.ex
index 2e421420..47f2eaf9 100644
--- a/lib/bamboo/plug/sent_email_viewer/email_preview_plug.ex
+++ b/lib/bamboo/plug/sent_email_viewer/email_preview_plug.ex
@@ -1,17 +1,4 @@
defmodule Bamboo.SentEmailViewerPlug do
- use Plug.Router
- require EEx
- alias Bamboo.SentEmail
-
- no_emails_template = Path.join(__DIR__, "no_emails.html.eex")
- EEx.function_from_file(:defp, :no_emails, no_emails_template)
-
- index_template = Path.join(__DIR__, "index.html.eex")
- EEx.function_from_file(:defp, :index, index_template, [:assigns])
-
- not_found_template = Path.join(__DIR__, "email_not_found.html.eex")
- EEx.function_from_file(:defp, :not_found, not_found_template, [:assigns])
-
@moduledoc """
A plug that can be used in your router to see delivered emails.
@@ -40,23 +27,37 @@ defmodule Bamboo.SentEmailViewerPlug do
Now if you visit your app at `/sent_emails` you will see a list of delivered
emails.
"""
+ use Plug.Router
+
+ require EEx
+
+ alias Bamboo.SentEmail
+
+ no_emails_template = Path.join(__DIR__, "no_emails.html.eex")
+ EEx.function_from_file(:defp, :no_emails, no_emails_template)
+
+ index_template = Path.join(__DIR__, "index.html.eex")
+ EEx.function_from_file(:defp, :index, index_template, [:assigns])
+
+ not_found_template = Path.join(__DIR__, "email_not_found.html.eex")
+ EEx.function_from_file(:defp, :not_found, not_found_template, [:assigns])
plug(:match)
plug(:dispatch)
get "/" do
if Enum.empty?(all_emails()) do
- conn |> render_no_emails
+ render_no_emails(conn)
else
- conn |> render_index(newest_email())
+ render_index(conn, newest_email())
end
end
get "/:id" do
if email = SentEmail.get(id) do
- conn |> render_index(email)
+ render_index(conn, email)
else
- conn |> render_not_found
+ render_not_found(conn)
end
end
@@ -66,7 +67,7 @@ defmodule Bamboo.SentEmailViewerPlug do
|> Plug.Conn.put_resp_content_type("text/html")
|> send_resp(:ok, email.html_body || "")
else
- conn |> render_not_found
+ render_not_found(conn)
end
end
@@ -82,7 +83,7 @@ defmodule Bamboo.SentEmailViewerPlug do
|> send_resp(:ok, attachment.data)
else
_ ->
- conn |> render_not_found
+ render_not_found(conn)
end
end
@@ -91,7 +92,7 @@ defmodule Bamboo.SentEmailViewerPlug do
end
defp newest_email do
- all_emails() |> List.first()
+ List.first(all_emails())
end
defp render_no_emails(conn) do
diff --git a/lib/bamboo/plug/sent_email_viewer/helper.ex b/lib/bamboo/plug/sent_email_viewer/helper.ex
index 1ad5d33d..8689ba66 100644
--- a/lib/bamboo/plug/sent_email_viewer/helper.ex
+++ b/lib/bamboo/plug/sent_email_viewer/helper.ex
@@ -1,8 +1,9 @@
defmodule Bamboo.SentEmailViewerPlug.Helper do
+ @moduledoc false
+
import Bamboo.SentEmail
- alias Plug.HTML
- @moduledoc false
+ alias Plug.HTML
def selected_email_class(email, selected_email) do
if get_id(email) == get_id(selected_email) do
@@ -13,9 +14,9 @@ defmodule Bamboo.SentEmailViewerPlug.Helper do
end
def email_addresses(email) do
- Bamboo.Email.all_recipients(email)
- |> Enum.map(&format_email_address/1)
- |> Enum.join(", ")
+ email
+ |> Bamboo.Email.all_recipients()
+ |> Enum.map_join(", ", &format_email_address/1)
end
def format_headers(values) when is_binary(values) do
diff --git a/lib/bamboo/sent_email.ex b/lib/bamboo/sent_email.ex
index e4dc5ea5..831da567 100644
--- a/lib/bamboo/sent_email.ex
+++ b/lib/bamboo/sent_email.ex
@@ -33,9 +33,7 @@ defmodule Bamboo.SentEmail do
end
defp email_list(emails) do
- emails
- |> Enum.map(&inspect/1)
- |> Enum.join("\n")
+ Enum.map_join(emails, "\n", &inspect/1)
end
end
@@ -92,7 +90,7 @@ defmodule Bamboo.SentEmail do
defp do_get(id) do
Enum.find(all(), nil, fn email ->
- email |> get_id |> String.downcase() == String.downcase(id)
+ email |> get_id() |> String.downcase() == String.downcase(id)
end)
end
@@ -118,11 +116,12 @@ defmodule Bamboo.SentEmail do
end
defp put_rand_id(email) do
- email |> Bamboo.Email.put_private(:local_adapter_id, rand_id())
+ Bamboo.Email.put_private(email, :local_adapter_id, rand_id())
end
defp rand_id do
- :crypto.strong_rand_bytes(@id_length)
+ @id_length
+ |> :crypto.strong_rand_bytes()
|> Base.url_encode64()
|> binary_part(0, @id_length)
end
diff --git a/lib/bamboo/strategies/task_supervisor_strategy.ex b/lib/bamboo/strategies/task_supervisor_strategy.ex
index cf5d4f3a..706b20f9 100644
--- a/lib/bamboo/strategies/task_supervisor_strategy.ex
+++ b/lib/bamboo/strategies/task_supervisor_strategy.ex
@@ -1,6 +1,4 @@
defmodule Bamboo.TaskSupervisorStrategy do
- @behaviour Bamboo.DeliverLaterStrategy
-
@moduledoc """
Default strategy. Sends an email in the background using `Task.Supervisor`.
@@ -17,6 +15,7 @@ defmodule Bamboo.TaskSupervisorStrategy do
Instead you can use `deliver_later/1` and it will be delivered in the background
so web requests remain snappy.
"""
+ @behaviour Bamboo.DeliverLaterStrategy
@doc false
def deliver_later(adapter, email, config) do
diff --git a/lib/bamboo/template.ex b/lib/bamboo/template.ex
index df11e90d..8236d46b 100644
--- a/lib/bamboo/template.ex
+++ b/lib/bamboo/template.ex
@@ -184,25 +184,25 @@ defmodule Bamboo.Template do
## Example
# renders both HTML and text emails
- new_email()
- |> render(:template_name)
+ render(new_email(), :template_name)
# renders HTML template
- new_email()
- |> render("template_name.html")
+ render(new_email(), "template_name.html")
# renders text template
- new_email()
- |> render("template_name.text")
+ render(new_email(), "template_name.text")
# renders with assigns
- new_email()
- |> render(:template_name, user: user)
+ render(new_email(), :template_name, user: user)
"""
def render(_email, _template_name, _assigns) do
raise "function implemented for documentation only, please call: `use Bamboo.Template`"
end
+ @spec assign(%{:assigns => any(), optional(any()) => any()}, maybe_improper_list() | map()) :: %{
+ :assigns => any(),
+ optional(any()) => any()
+ }
@doc """
Sets many assigns for an email. Accepts a map or a keyword list. See
`assign/3` for more.
@@ -247,7 +247,7 @@ defmodule Bamboo.Template do
end
"""
def put_html_layout(email, layout) do
- email |> put_private(:html_layout, layout)
+ put_private(email, :html_layout, layout)
end
@doc """
@@ -262,7 +262,7 @@ defmodule Bamboo.Template do
end
"""
def put_text_layout(email, layout) do
- email |> put_private(:text_layout, layout)
+ put_private(email, :text_layout, layout)
end
@doc """
@@ -300,7 +300,7 @@ defmodule Bamboo.Template do
end
"""
def put_view(email, view) do
- email |> put_private(:view_module, view)
+ put_private(email, :view_module, view)
end
@doc false
diff --git a/lib/bamboo/test.ex b/lib/bamboo/test.ex
index 98ce5a5e..79332408 100644
--- a/lib/bamboo/test.ex
+++ b/lib/bamboo/test.ex
@@ -1,6 +1,4 @@
defmodule Bamboo.Test do
- import ExUnit.Assertions
-
@moduledoc """
Helpers for testing email delivery.
@@ -96,6 +94,9 @@ defmodule Bamboo.Test do
send from inside of a Task, GenServer, or are running acceptance tests with a
headless browser like phantomjs.
"""
+
+ import ExUnit.Assertions
+
defmacro __using__(shared: true) do
quote do
setup tags do
@@ -223,7 +224,7 @@ defmodule Bamboo.Test do
timeout = get_timeout(opts)
assert_receive({:delivered_email, email}, timeout, flunk_no_emails_received())
- received_email_params = email |> Map.from_struct()
+ received_email_params = Map.from_struct(email)
assert Enum.all?(email_params, fn {k, v} -> do_match(received_email_params[k], v, k) end),
flunk_attributes_do_not_match(email_params, received_email_params)
@@ -279,7 +280,7 @@ defmodule Bamboo.Test do
end
end
- defp do_match(value1, value2 = %Regex{}, _type) do
+ defp do_match(value1, %Regex{} = value2, _type) do
Regex.match?(value2, value1)
end
@@ -460,7 +461,7 @@ defmodule Bamboo.Test do
end
defp using_shared_mode? do
- !!Application.get_env(:bamboo, :shared_test_process)
+ Application.get_env(:bamboo, :shared_test_process, false)
end
defp normalize_for_testing(email) do
diff --git a/lib/bamboo/view.ex b/lib/bamboo/view.ex
index e61d4a0e..9304ca0a 100644
--- a/lib/bamboo/view.ex
+++ b/lib/bamboo/view.ex
@@ -127,7 +127,7 @@ defmodule Bamboo.View do
render_within_layout(layout, email, template)
end
- defp render_within_layout(_layout = false, email, template) do
+ defp render_within_layout(false = _layout, email, template) do
module = email.private.view_module
module.render_template(template, email.assigns)
end
@@ -156,6 +156,7 @@ defmodule Bamboo.View do
defp compile(template, name) do
quoted_contents = EEx.compile_file(template, line: 1, engine: EEx.SmartEngine)
+ # credo:disable-for-this-file Credo.Check.Warning.UnsafeToAtom
function_name = String.to_atom(name)
quote do
diff --git a/lib/mix/start_sent_email_viewer_task.ex b/lib/mix/start_sent_email_viewer_task.ex
index 02579ca1..1cc0f6a3 100644
--- a/lib/mix/start_sent_email_viewer_task.ex
+++ b/lib/mix/start_sent_email_viewer_task.ex
@@ -1,7 +1,6 @@
defmodule Mix.Tasks.Bamboo.StartSentEmailViewer do
- use Mix.Task
-
@moduledoc false
+ use Mix.Task
# This could be used in the future by the public, but right now it's only
# suitable for development.
@@ -9,32 +8,35 @@ defmodule Mix.Tasks.Bamboo.StartSentEmailViewer do
def run(_) do
Mix.Task.run("app.start")
{:ok, _} = Application.ensure_all_started(:cowboy)
- Plug.Adapters.Cowboy.http(Bamboo.SentEmailViewerPlug, [], port: 4003)
+ Plug.Cowboy.http(Bamboo.SentEmailViewerPlug, [], port: 4003)
for index <- 0..5 do
- Bamboo.Email.new_email(
- from: "me@gmail.com",
- to: "someone@foo.com",
- subject: "#{index} - This is a long subject for testing truncation",
- html_body: """
- Check different tag styling
+ email =
+ Bamboo.Email.new_email(
+ from: "me@gmail.com",
+ to: "someone@foo.com",
+ subject: "#{index} - This is a long subject for testing truncation",
+ html_body: """
+ Check different tag styling
+
+
-
+
+ - List item
+
+ """,
+ text_body: """
+ This is the text part of an email. It should be pretty
+ long to see how it expands on to the next line
-
- - List item
-
- """,
- text_body: """
- This is the text part of an email. It should be pretty
- long to see how it expands on to the next line
+ Sincerely,
+ Me and html tag
+ """
+ )
- Sincerely,
- Me and html tag
- """
- )
+ email
|> add_attachments(index)
|> Bamboo.Mailer.normalize_addresses()
|> Bamboo.SentEmail.push()
diff --git a/mix.exs b/mix.exs
index ff0322d5..2f4b1e8e 100644
--- a/mix.exs
+++ b/mix.exs
@@ -59,15 +59,20 @@ defmodule Bamboo.Mixfile do
defp deps do
[
- {:plug, "~> 1.0"},
+ {:hackney, ">= 1.15.2"},
+ {:jason, "~> 1.0", optional: true},
{:mime, "~> 1.4 or ~> 2.0"},
- {:ex_machina, "~> 2.4", only: :test},
+ {:plug, "~> 1.0"},
+
+ # Dev & test dependencies
{:cowboy, "~> 1.0", only: [:test, :dev]},
+ {:credo, ">= 0.0.0", only: [:dev, :test]},
+ {:dialyxir, "~> 1.1", only: [:dev, :test], runtime: false},
+ {:ex_doc, "~> 0.23", only: :dev},
+ {:ex_machina, "~> 2.4", only: :test},
{:excoveralls, "~> 0.13", only: :test},
{:floki, "~> 0.29", only: :test},
- {:ex_doc, "~> 0.23", only: :dev},
- {:hackney, ">= 1.15.2"},
- {:jason, "~> 1.0", optional: true}
+ {:plug_cowboy, "~> 1.0", only: [:dev, :test]}
]
end
end
diff --git a/mix.lock b/mix.lock
index 65dd2dc4..8655d33c 100644
--- a/mix.lock
+++ b/mix.lock
@@ -1,29 +1,33 @@
%{
- "certifi": {:hex, :certifi, "2.5.2", "b7cfeae9d2ed395695dd8201c57a2d019c0c43ecaf8b8bcb9320b40d6662f340", [:rebar3], [{:parse_trans, "~>3.3", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm", "3b3b5f36493004ac3455966991eaf6e768ce9884693d9968055aeeeb1e575040"},
+ "bunt": {:hex, :bunt, "1.0.0", "081c2c665f086849e6d57900292b3a161727ab40431219529f13c4ddcf3e7a44", [:mix], [], "hexpm", "dc5f86aa08a5f6fa6b8096f0735c4e76d54ae5c9fa2c143e5a1fc7c1cd9bb6b5"},
+ "certifi": {:hex, :certifi, "2.12.0", "2d1cca2ec95f59643862af91f001478c9863c2ac9cb6e2f89780bfd8de987329", [:rebar3], [], "hexpm", "ee68d85df22e554040cdb4be100f33873ac6051387baf6a8f6ce82272340ff1c"},
"cowboy": {:hex, :cowboy, "1.1.2", "61ac29ea970389a88eca5a65601460162d370a70018afe6f949a29dca91f3bb0", [:rebar3], [{:cowlib, "~> 1.0.2", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "~> 1.3.2", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "f4763bbe08233eceed6f24bc4fcc8d71c17cfeafa6439157c57349aa1bb4f17c"},
"cowlib": {:hex, :cowlib, "1.0.2", "9d769a1d062c9c3ac753096f868ca121e2730b9a377de23dec0f7e08b1df84ee", [:make], [], "hexpm", "db622da03aa039e6366ab953e31186cc8190d32905e33788a1acb22744e6abd2"},
- "earmark": {:hex, :earmark, "1.3.2", "b840562ea3d67795ffbb5bd88940b1bed0ed9fa32834915125ea7d02e35888a5", [:mix], [], "hexpm", "e3be2bc3ae67781db529b80aa7e7c49904a988596e2dbff897425b48b3581161"},
- "earmark_parser": {:hex, :earmark_parser, "1.4.10", "6603d7a603b9c18d3d20db69921527f82ef09990885ed7525003c7fe7dc86c56", [:mix], [], "hexpm", "8e2d5370b732385db2c9b22215c3f59c84ac7dda7ed7e544d7c459496ae519c0"},
- "ex_doc": {:hex, :ex_doc, "0.23.0", "a069bc9b0bf8efe323ecde8c0d62afc13d308b1fa3d228b65bca5cf8703a529d", [:mix], [{:earmark_parser, "~> 1.4.0", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm", "f5e2c4702468b2fd11b10d39416ddadd2fcdd173ba2a0285ebd92c39827a5a16"},
- "ex_machina": {:hex, :ex_machina, "2.4.0", "09a34c5d371bfb5f78399029194a8ff67aff340ebe8ba19040181af35315eabb", [:mix], [{:ecto, "~> 2.2 or ~> 3.0", [hex: :ecto, repo: "hexpm", optional: true]}, {:ecto_sql, "~> 3.0", [hex: :ecto_sql, repo: "hexpm", optional: true]}], "hexpm", "a20bc9ddc721b33ea913b93666c5d0bdca5cbad7a67540784ae277228832d72c"},
- "excoveralls": {:hex, :excoveralls, "0.13.2", "5ca05099750c086f144fcf75842c363fc15d7d9c6faa7ad323d010294ced685e", [:mix], [{:hackney, "~> 1.16", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "1e7ed75c158808a5a8f019d3ad63a5efe482994f2f8336c0a8c77d2f0ab152ce"},
- "floki": {:hex, :floki, "0.29.0", "b1710d8c93a2f860dc2d7adc390dd808dc2fb8f78ee562304457b75f4c640881", [:mix], [{:html_entities, "~> 0.5.0", [hex: :html_entities, repo: "hexpm", optional: false]}], "hexpm", "008585ce64b9f74c07d32958ec9866f4b8a124bf4da1e2941b28e41384edaaad"},
- "hackney": {:hex, :hackney, "1.16.0", "5096ac8e823e3a441477b2d187e30dd3fff1a82991a806b2003845ce72ce2d84", [:rebar3], [{:certifi, "2.5.2", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "6.0.1", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.3.0", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.6", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm", "3bf0bebbd5d3092a3543b783bf065165fa5d3ad4b899b836810e513064134e18"},
- "html_entities": {:hex, :html_entities, "0.5.1", "1c9715058b42c35a2ab65edc5b36d0ea66dd083767bef6e3edb57870ef556549", [:mix], [], "hexpm", "30efab070904eb897ff05cd52fa61c1025d7f8ef3a9ca250bc4e6513d16c32de"},
- "idna": {:hex, :idna, "6.0.1", "1d038fb2e7668ce41fbf681d2c45902e52b3cb9e9c77b55334353b222c2ee50c", [:rebar3], [{:unicode_util_compat, "0.5.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "a02c8a1c4fd601215bb0b0324c8a6986749f807ce35f25449ec9e69758708122"},
- "jason": {:hex, :jason, "1.2.2", "ba43e3f2709fd1aa1dce90aaabfd039d000469c05c56f0b8e31978e03fa39052", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "18a228f5f0058ee183f29f9eae0805c6e59d61c3b006760668d8d18ff0d12179"},
- "makeup": {:hex, :makeup, "1.0.5", "d5a830bc42c9800ce07dd97fa94669dfb93d3bf5fcf6ea7a0c67b2e0e4a7f26c", [:mix], [{:nimble_parsec, "~> 0.5 or ~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "cfa158c02d3f5c0c665d0af11512fed3fba0144cf1aadee0f2ce17747fba2ca9"},
- "makeup_elixir": {:hex, :makeup_elixir, "0.15.0", "98312c9f0d3730fde4049985a1105da5155bfe5c11e47bdc7406d88e01e4219b", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.1", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "75ffa34ab1056b7e24844c90bfc62aaf6f3a37a15faa76b07bc5eba27e4a8b4a"},
+ "credo": {:hex, :credo, "1.7.7", "771445037228f763f9b2afd612b6aa2fd8e28432a95dbbc60d8e03ce71ba4446", [:mix], [{:bunt, "~> 0.2.1 or ~> 1.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "8bc87496c9aaacdc3f90f01b7b0582467b69b4bd2441fe8aae3109d843cc2f2e"},
+ "dialyxir": {:hex, :dialyxir, "1.4.3", "edd0124f358f0b9e95bfe53a9fcf806d615d8f838e2202a9f430d59566b6b53b", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "bf2cfb75cd5c5006bec30141b131663299c661a864ec7fbbc72dfa557487a986"},
+ "earmark_parser": {:hex, :earmark_parser, "1.4.39", "424642f8335b05bb9eb611aa1564c148a8ee35c9c8a8bba6e129d51a3e3c6769", [:mix], [], "hexpm", "06553a88d1f1846da9ef066b87b57c6f605552cfbe40d20bd8d59cc6bde41944"},
+ "erlex": {:hex, :erlex, "0.2.7", "810e8725f96ab74d17aac676e748627a07bc87eb950d2b83acd29dc047a30595", [:mix], [], "hexpm", "3ed95f79d1a844c3f6bf0cea61e0d5612a42ce56da9c03f01df538685365efb0"},
+ "ex_doc": {:hex, :ex_doc, "0.34.1", "9751a0419bc15bc7580c73fde506b17b07f6402a1e5243be9e0f05a68c723368", [:mix], [{:earmark_parser, "~> 1.4.39", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.0", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14 or ~> 1.0", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1 or ~> 1.0", [hex: :makeup_erlang, repo: "hexpm", optional: false]}, {:makeup_html, ">= 0.1.0", [hex: :makeup_html, repo: "hexpm", optional: true]}], "hexpm", "d441f1a86a235f59088978eff870de2e815e290e44a8bd976fe5d64470a4c9d2"},
+ "ex_machina": {:hex, :ex_machina, "2.8.0", "a0e847b5712065055ec3255840e2c78ef9366634d62390839d4880483be38abe", [:mix], [{:ecto, "~> 2.2 or ~> 3.0", [hex: :ecto, repo: "hexpm", optional: true]}, {:ecto_sql, "~> 3.0", [hex: :ecto_sql, repo: "hexpm", optional: true]}], "hexpm", "79fe1a9c64c0c1c1fab6c4fa5d871682cb90de5885320c187d117004627a7729"},
+ "excoveralls": {:hex, :excoveralls, "0.18.1", "a6f547570c6b24ec13f122a5634833a063aec49218f6fff27de9df693a15588c", [:mix], [{:castore, "~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "d65f79db146bb20399f23046015974de0079668b9abb2f5aac074d078da60b8d"},
+ "file_system": {:hex, :file_system, "1.0.0", "b689cc7dcee665f774de94b5a832e578bd7963c8e637ef940cd44327db7de2cd", [:mix], [], "hexpm", "6752092d66aec5a10e662aefeed8ddb9531d79db0bc145bb8c40325ca1d8536d"},
+ "floki": {:hex, :floki, "0.36.2", "a7da0193538c93f937714a6704369711998a51a6164a222d710ebd54020aa7a3", [:mix], [], "hexpm", "a8766c0bc92f074e5cb36c4f9961982eda84c5d2b8e979ca67f5c268ec8ed580"},
+ "hackney": {:hex, :hackney, "1.20.1", "8d97aec62ddddd757d128bfd1df6c5861093419f8f7a4223823537bad5d064e2", [:rebar3], [{:certifi, "~> 2.12.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "~> 6.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "~> 1.0.0", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~> 1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.4.1", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "~> 1.1.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}, {:unicode_util_compat, "~> 0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "fe9094e5f1a2a2c0a7d10918fee36bfec0ec2a979994cff8cfe8058cd9af38e3"},
+ "idna": {:hex, :idna, "6.1.1", "8a63070e9f7d0c62eb9d9fcb360a7de382448200fbbd1b106cc96d3d8099df8d", [:rebar3], [{:unicode_util_compat, "~> 0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "92376eb7894412ed19ac475e4a86f7b413c1b9fbb5bd16dccd57934157944cea"},
+ "jason": {:hex, :jason, "1.4.1", "af1504e35f629ddcdd6addb3513c3853991f694921b1b9368b0bd32beb9f1b63", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "fbb01ecdfd565b56261302f7e1fcc27c4fb8f32d56eab74db621fc154604a7a1"},
+ "makeup": {:hex, :makeup, "1.1.2", "9ba8837913bdf757787e71c1581c21f9d2455f4dd04cfca785c70bbfff1a76a3", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "cce1566b81fbcbd21eca8ffe808f33b221f9eee2cbc7a1706fc3da9ff18e6cac"},
+ "makeup_elixir": {:hex, :makeup_elixir, "0.16.2", "627e84b8e8bf22e60a2579dad15067c755531fea049ae26ef1020cad58fe9578", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "41193978704763f6bbe6cc2758b84909e62984c7752b3784bd3c218bb341706b"},
+ "makeup_erlang": {:hex, :makeup_erlang, "1.0.0", "6f0eff9c9c489f26b69b61440bf1b238d95badae49adac77973cbacae87e3c2e", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "ea7a9307de9d1548d2a72d299058d1fd2339e3d398560a0e46c27dab4891e4d2"},
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm", "69b09adddc4f74a40716ae54d140f93beb0fb8978d8636eaded0c31b6f099f16"},
- "mime": {:hex, :mime, "1.4.0", "5066f14944b470286146047d2f73518cf5cca82f8e4815cf35d196b58cf07c47", [:mix], [], "hexpm", "75fa42c4228ea9a23f70f123c74ba7cece6a03b1fd474fe13f6a7a85c6ea4ff6"},
- "mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm", "f278585650aa581986264638ebf698f8bb19df297f66ad91b18910dfc6e19323"},
- "mochiweb": {:hex, :mochiweb, "2.15.0", "e1daac474df07651e5d17cc1e642c4069c7850dc4508d3db7263a0651330aacc", [:rebar3], [], "hexpm", "b960d1cbcf40a30963eeee90ab7aeae074cbfa9a238561fb4434add1afc3075c"},
- "nimble_parsec": {:hex, :nimble_parsec, "1.1.0", "3a6fca1550363552e54c216debb6a9e95bd8d32348938e13de5eda962c0d7f89", [:mix], [], "hexpm", "08eb32d66b706e913ff748f11694b17981c0b04a33ef470e33e11b3d3ac8f54b"},
- "parse_trans": {:hex, :parse_trans, "3.3.0", "09765507a3c7590a784615cfd421d101aec25098d50b89d7aa1d66646bc571c1", [:rebar3], [], "hexpm", "17ef63abde837ad30680ea7f857dd9e7ced9476cdd7b0394432af4bfc241b960"},
- "phoenix_pubsub": {:hex, :phoenix_pubsub, "1.0.2", "bfa7fd52788b5eaa09cb51ff9fcad1d9edfeb68251add458523f839392f034c1", [:mix], [], "hexpm", "6f9193364c5de86b85e8d3a80294a134aecf6c5618adcbae668608749e00a7f7"},
- "plug": {:hex, :plug, "1.6.0", "90d338a44c8cd762c32d3ea324f6728445c6145b51895403854b77f1536f1617", [:mix], [{:cowboy, "~> 1.0.1 or ~> 1.1 or ~> 2.4", [hex: :cowboy, repo: "hexpm", optional: true]}, {:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}], "hexpm", "b6761cce9b0e369eb3d19da7f8805c1a55e0a7fdc2f65e2fc3802e9305481dea"},
- "poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm", "fec8660eb7733ee4117b85f55799fd3833eb769a6df71ccf8903e8dc5447cfce"},
+ "mime": {:hex, :mime, "2.0.5", "dc34c8efd439abe6ae0343edbb8556f4d63f178594894720607772a041b04b02", [:mix], [], "hexpm", "da0d64a365c45bc9935cc5c8a7fc5e49a0e0f9932a761c55d6c52b142780a05c"},
+ "mimerl": {:hex, :mimerl, "1.3.0", "d0cd9fc04b9061f82490f6581e0128379830e78535e017f7780f37fea7545726", [:rebar3], [], "hexpm", "a1e15a50d1887217de95f0b9b0793e32853f7c258a5cd227650889b38839fe9d"},
+ "nimble_parsec": {:hex, :nimble_parsec, "1.4.0", "51f9b613ea62cfa97b25ccc2c1b4216e81df970acd8e16e8d1bdc58fef21370d", [:mix], [], "hexpm", "9c565862810fb383e9838c1dd2d7d2c437b3d13b267414ba6af33e50d2d1cf28"},
+ "parse_trans": {:hex, :parse_trans, "3.4.1", "6e6aa8167cb44cc8f39441d05193be6e6f4e7c2946cb2759f015f8c56b76e5ff", [:rebar3], [], "hexpm", "620a406ce75dada827b82e453c19cf06776be266f5a67cff34e1ef2cbb60e49a"},
+ "plug": {:hex, :plug, "1.16.1", "40c74619c12f82736d2214557dedec2e9762029b2438d6d175c5074c933edc9d", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2 or ~> 2.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "a13ff6b9006b03d7e33874945b2755253841b238c34071ed85b0e86057f8cddc"},
+ "plug_cowboy": {:hex, :plug_cowboy, "1.0.0", "2e2a7d3409746d335f451218b8bb0858301c3de6d668c3052716c909936eb57a", [:mix], [{:cowboy, "~> 1.0", [hex: :cowboy, repo: "hexpm", optional: false]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "01d201427a8a1f4483be2465a98b45f5e82263327507fe93404a61c51eb9e9a8"},
+ "plug_crypto": {:hex, :plug_crypto, "2.1.0", "f44309c2b06d249c27c8d3f65cfe08158ade08418cf540fd4f72d4d6863abb7b", [:mix], [], "hexpm", "131216a4b030b8f8ce0f26038bc4421ae60e4bb95c5cf5395e1421437824c4fa"},
"ranch": {:hex, :ranch, "1.3.2", "e4965a144dc9fbe70e5c077c65e73c57165416a901bd02ea899cfd95aa890986", [:rebar3], [], "hexpm", "6e56493a862433fccc3aca3025c946d6720d8eedf6e3e6fb911952a7071c357f"},
- "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.6", "cf344f5692c82d2cd7554f5ec8fd961548d4fd09e7d22f5b62482e5aeaebd4b0", [:make, :mix, :rebar3], [], "hexpm", "bdb0d2471f453c88ff3908e7686f86f9be327d065cc1ec16fa4540197ea04680"},
- "unicode_util_compat": {:hex, :unicode_util_compat, "0.5.0", "8516502659002cec19e244ebd90d312183064be95025a319a6c7e89f4bccd65b", [:rebar3], [], "hexpm", "d48d002e15f5cc105a696cf2f1bbb3fc72b4b770a184d8420c8db20da2674b38"},
+ "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.7", "354c321cf377240c7b8716899e182ce4890c5938111a1296add3ec74cf1715df", [:make, :mix, :rebar3], [], "hexpm", "fe4c190e8f37401d30167c8c405eda19469f34577987c76dde613e838bbc67f8"},
+ "telemetry": {:hex, :telemetry, "1.2.1", "68fdfe8d8f05a8428483a97d7aab2f268aaff24b49e0f599faa091f1d4e7f61c", [:rebar3], [], "hexpm", "dad9ce9d8effc621708f99eac538ef1cbe05d6a874dd741de2e689c47feafed5"},
+ "unicode_util_compat": {:hex, :unicode_util_compat, "0.7.0", "bc84380c9ab48177092f43ac89e4dfa2c6d62b40b8bd132b1059ecc7232f9a78", [:rebar3], [], "hexpm", "25eee6d67df61960cf6a794239566599b09e17e668d3700247bc498638152521"},
}
diff --git a/test/lib/bamboo/adapters/local_adapter_test.exs b/test/lib/bamboo/adapters/local_adapter_test.exs
index 6287d9e0..fa067ba5 100644
--- a/test/lib/bamboo/adapters/local_adapter_test.exs
+++ b/test/lib/bamboo/adapters/local_adapter_test.exs
@@ -1,9 +1,11 @@
defmodule Bamboo.LocalAdapterTest do
use ExUnit.Case
- alias Bamboo.SentEmail
- alias Bamboo.LocalAdapter
+
import Bamboo.Email, only: [new_email: 1]
+ alias Bamboo.LocalAdapter
+ alias Bamboo.SentEmail
+
@config %{}
setup do
@@ -14,7 +16,7 @@ defmodule Bamboo.LocalAdapterTest do
test "sent emails has emails that were delivered synchronously" do
email = new_email(subject: "This is my email")
- {:ok, _response} = email |> LocalAdapter.deliver(@config)
+ {:ok, _response} = LocalAdapter.deliver(email, @config)
assert [%Bamboo.Email{subject: "This is my email"}] = SentEmail.all()
end
@@ -23,6 +25,6 @@ defmodule Bamboo.LocalAdapterTest do
email = new_email(subject: "This is my email")
assert {:ok, _response} =
- email |> LocalAdapter.deliver(%{open_email_in_browser_url: "test://"})
+ LocalAdapter.deliver(email, %{open_email_in_browser_url: "test://"})
end
end
diff --git a/test/lib/bamboo/adapters/mailgun_adapter_test.exs b/test/lib/bamboo/adapters/mailgun_adapter_test.exs
index 72f3f4f9..d1f8cb7e 100644
--- a/test/lib/bamboo/adapters/mailgun_adapter_test.exs
+++ b/test/lib/bamboo/adapters/mailgun_adapter_test.exs
@@ -13,6 +13,8 @@ defmodule Bamboo.MailgunAdapterTest do
defmodule FakeMailgun do
use Plug.Router
+ alias Plug.Cowboy
+
plug(
Plug.Parsers,
parsers: [:urlencoded, :multipart, :json],
@@ -28,7 +30,7 @@ defmodule Bamboo.MailgunAdapterTest do
Agent.update(__MODULE__, &Map.put(&1, :parent, parent))
port = get_free_port()
Application.put_env(:bamboo, :mailgun_base_uri, "http://localhost:#{port}")
- Plug.Adapters.Cowboy.http(__MODULE__, [], port: port, ref: __MODULE__)
+ Cowboy.http(__MODULE__, [], port: port, ref: __MODULE__)
end
defp get_free_port do
@@ -39,22 +41,24 @@ defmodule Bamboo.MailgunAdapterTest do
end
def shutdown do
- Plug.Adapters.Cowboy.shutdown(__MODULE__)
+ Cowboy.shutdown(__MODULE__)
end
post "/test.tt/messages" do
- case Map.get(conn.params, "from") do
- "INVALID_EMAIL" ->
- send_resp(
- conn,
- 500,
- "{\n \"message\": \"'from' parameter is not a valid address. please check documentation\"\n}"
- )
-
- _ ->
- send_resp(conn, 200, "SENT")
- end
- |> send_to_parent
+ conn =
+ case Map.get(conn.params, "from") do
+ "INVALID_EMAIL" ->
+ send_resp(
+ conn,
+ 500,
+ "{\n \"message\": \"'from' parameter is not a valid address. please check documentation\"\n}"
+ )
+
+ _ ->
+ send_resp(conn, 200, "SENT")
+ end
+
+ send_to_parent(conn)
end
defp send_to_parent(conn) do
@@ -103,7 +107,7 @@ defmodule Bamboo.MailgunAdapterTest do
System.put_env("MAILGUN_DOMAIN", "env_domain")
assert_raise ArgumentError, ~r/no api_key set/, fn ->
- new_email(from: "foo@bar.com") |> MailgunAdapter.deliver(@config_with_env_var_key)
+ [from: "foo@bar.com"] |> new_email() |> MailgunAdapter.deliver(@config_with_env_var_key)
end
assert_raise ArgumentError, ~r/no api_key set/, fn ->
@@ -117,7 +121,7 @@ defmodule Bamboo.MailgunAdapterTest do
System.put_env("MAILGUN_API_KEY", "env_api_key")
assert_raise ArgumentError, ~r/no domain set/, fn ->
- new_email(from: "foo@bar.com") |> MailgunAdapter.deliver(@config_with_env_var_key)
+ [from: "foo@bar.com"] |> new_email() |> MailgunAdapter.deliver(@config_with_env_var_key)
end
assert_raise ArgumentError, ~r/no domain set/, fn ->
@@ -155,7 +159,7 @@ defmodule Bamboo.MailgunAdapterTest do
end
test "deliver/2 sends the to the right url" do
- new_email() |> MailgunAdapter.deliver(@config)
+ MailgunAdapter.deliver(new_email(), @config)
assert_receive {:fake_mailgun, %{request_path: request_path}}
@@ -163,19 +167,15 @@ defmodule Bamboo.MailgunAdapterTest do
end
test "deliver/2 returns an {:ok, response} tuple" do
- {:ok, response} = new_email() |> MailgunAdapter.deliver(@config)
+ {:ok, response} = MailgunAdapter.deliver(new_email(), @config)
assert %{status_code: 200, headers: _, body: _} = response
end
test "deliver/2 sends from, subject, text body, html body, headers, custom vars and recipient variables" do
email =
- new_email(
- from: "from@foo.com",
- subject: "My Subject",
- text_body: "TEXT BODY",
- html_body: "HTML BODY"
- )
+ [from: "from@foo.com", subject: "My Subject", text_body: "TEXT BODY", html_body: "HTML BODY"]
+ |> new_email()
|> Email.put_header("X-My-Header", "my_header_value")
|> Email.put_header("Reply-To", "random@foo.com")
|> Email.put_private(:mailgun_custom_vars, %{my_custom_var: 42, other_custom_var: 43})
@@ -209,12 +209,8 @@ defmodule Bamboo.MailgunAdapterTest do
attachment_source_path = Path.join(__DIR__, "../../../support/attachment.txt")
email =
- new_email(
- from: "from@foo.com",
- subject: "My Subject",
- text_body: "TEXT BODY",
- html_body: "HTML BODY"
- )
+ [from: "from@foo.com", subject: "My Subject", text_body: "TEXT BODY", html_body: "HTML BODY"]
+ |> new_email()
|> Email.put_header("Reply-To", "random@foo.com")
|> Email.put_header("X-My-Header", "my_header_value")
|> Email.put_private(:mailgun_custom_vars, %{my_custom_var: 42, other_custom_var: 43})
@@ -253,7 +249,7 @@ defmodule Bamboo.MailgunAdapterTest do
bcc: [{"BCC", "bcc@bar.com"}]
)
- email |> MailgunAdapter.deliver(@config)
+ MailgunAdapter.deliver(email, @config)
assert_receive {:fake_mailgun, %{params: params}}
assert params["to"] == "To ,noname@bar.com"
@@ -263,12 +259,8 @@ defmodule Bamboo.MailgunAdapterTest do
test "deliver/2 correctly formats reply-to" do
email =
- new_email(
- from: "from@foo.com",
- subject: "My Subject",
- text_body: "TEXT BODY",
- html_body: "HTML BODY"
- )
+ [from: "from@foo.com", subject: "My Subject", text_body: "TEXT BODY", html_body: "HTML BODY"]
+ |> new_email()
|> Email.put_header("reply-to", "random@foo.com")
MailgunAdapter.deliver(email, @config)
@@ -280,12 +272,8 @@ defmodule Bamboo.MailgunAdapterTest do
test "deliver/2 correctly formats template and template options" do
email =
- new_email(
- from: "from@foo.com",
- subject: "My Subject",
- text_body: "TEXT BODY",
- html_body: "HTML BODY"
- )
+ [from: "from@foo.com", subject: "My Subject", text_body: "TEXT BODY", html_body: "HTML BODY"]
+ |> new_email()
|> Email.put_private(:template, "my_template")
|> Email.put_private(:"t:version", "v2")
|> Email.put_private(:"t:text", true)
@@ -302,7 +290,7 @@ defmodule Bamboo.MailgunAdapterTest do
test "returns an error if the response is not a success" do
email = new_email(from: "INVALID_EMAIL")
- {:error, %Bamboo.ApiError{} = error} = email |> MailgunAdapter.deliver(@config)
+ {:error, %Bamboo.ApiError{} = error} = MailgunAdapter.deliver(email, @config)
assert error.message =~ ~r/.*%{.*\"from\" => \"INVALID_EMAIL\".*}/
end
@@ -311,16 +299,16 @@ defmodule Bamboo.MailgunAdapterTest do
attachment_source_path = Path.join(__DIR__, "../../../support/attachment.txt")
email =
- new_email(from: "INVALID_EMAIL")
+ [from: "INVALID_EMAIL"]
+ |> new_email()
|> Email.put_attachment(attachment_source_path)
- {:error, %Bamboo.ApiError{} = error} = email |> MailgunAdapter.deliver(@config)
+ {:error, %Bamboo.ApiError{} = error} = MailgunAdapter.deliver(email, @config)
assert error.message =~ ~r/.*{.*\"from\", \"INVALID_EMAIL\".*}/
end
defp new_email(attrs \\ []) do
- attrs = Keyword.merge([from: "foo@bar.com", to: []], attrs)
- Email.new_email(attrs) |> Bamboo.Mailer.normalize_addresses()
+ [from: "foo@bar.com", to: []] |> Keyword.merge(attrs) |> Email.new_email() |> Bamboo.Mailer.normalize_addresses()
end
end
diff --git a/test/lib/bamboo/adapters/mailgun_helper_test.exs b/test/lib/bamboo/adapters/mailgun_helper_test.exs
index 382f4df8..11d3c4b2 100644
--- a/test/lib/bamboo/adapters/mailgun_helper_test.exs
+++ b/test/lib/bamboo/adapters/mailgun_helper_test.exs
@@ -1,45 +1,45 @@
defmodule Bamboo.MailgunHelperTest do
use ExUnit.Case
+
import Bamboo.Email
+
alias Bamboo.MailgunHelper
test "tag/2 puts a tag in private" do
- email = new_email() |> MailgunHelper.tag("new-tag")
+ email = MailgunHelper.tag(new_email(), "new-tag")
- assert Map.get(Map.get(email, :private, %{}), :"o:tag", nil) == "new-tag"
+ assert email |> Map.get(:private, %{}) |> Map.get(:"o:tag", nil) == "new-tag"
end
test "deliverytime/2 puts a deliverytime in private" do
- email = new_email() |> MailgunHelper.deliverytime(DateTime.from_unix!(1_422_057_007))
+ email = MailgunHelper.deliverytime(new_email(), DateTime.from_unix!(1_422_057_007))
- assert Map.get(Map.get(email, :private, %{}), :"o:deliverytime", nil) == 1_422_057_007
+ assert email |> Map.get(:private, %{}) |> Map.get(:"o:deliverytime", nil) == 1_422_057_007
end
test "adds template information to mailgun emails" do
- email =
- new_email()
- |> MailgunHelper.template("welcome")
+ email = MailgunHelper.template(new_email(), "welcome")
assert email.private == %{template: "welcome"}
end
test "adds template version to mailgun emails" do
- email = new_email() |> MailgunHelper.template_version("v2")
+ email = MailgunHelper.template_version(new_email(), "v2")
assert email.private == %{:"t:version" => "v2"}
end
test "enables template text" do
- email = new_email() |> MailgunHelper.template_text(true)
+ email = MailgunHelper.template_text(new_email(), true)
assert email.private == %{:"t:text" => true}
end
test "disables template text" do
- email = new_email() |> MailgunHelper.template_text(false)
+ email = MailgunHelper.template_text(new_email(), false)
assert email.private == %{:"t:text" => false}
end
test "disables template text with wrong arg" do
- email = new_email() |> MailgunHelper.template_text("string")
+ email = MailgunHelper.template_text(new_email(), "string")
assert email.private == %{:"t:text" => false}
end
@@ -63,8 +63,7 @@ defmodule Bamboo.MailgunHelperTest do
test "adds recipient variables to mailgun emails" do
email =
- new_email()
- |> MailgunHelper.recipient_variables(%{
+ MailgunHelper.recipient_variables(new_email(), %{
"user1@example.com" => %{unique_id: "ABC123456789"}
})
diff --git a/test/lib/bamboo/adapters/mandrill_adapter_test.exs b/test/lib/bamboo/adapters/mandrill_adapter_test.exs
index 98bff1ec..ada5f26b 100644
--- a/test/lib/bamboo/adapters/mandrill_adapter_test.exs
+++ b/test/lib/bamboo/adapters/mandrill_adapter_test.exs
@@ -1,9 +1,10 @@
defmodule Bamboo.MandrillAdapterTest do
use ExUnit.Case
+
alias Bamboo.Attachment
alias Bamboo.Email
- alias Bamboo.MandrillHelper
alias Bamboo.MandrillAdapter
+ alias Bamboo.MandrillHelper
@config %{adapter: MandrillAdapter, api_key: "123_abc"}
@config_with_bad_key %{adapter: MandrillAdapter, api_key: nil}
@@ -11,6 +12,8 @@ defmodule Bamboo.MandrillAdapterTest do
defmodule FakeMandrill do
use Plug.Router
+ alias Plug.Cowboy
+
plug(
Plug.Parsers,
parsers: [:urlencoded, :multipart, :json],
@@ -26,7 +29,7 @@ defmodule Bamboo.MandrillAdapterTest do
Agent.update(__MODULE__, &Map.put(&1, :parent, parent))
port = get_free_port()
Application.put_env(:bamboo, :mandrill_base_uri, "http://localhost:#{port}")
- Plug.Adapters.Cowboy.http(__MODULE__, [], port: port, ref: __MODULE__)
+ Cowboy.http(__MODULE__, [], port: port, ref: __MODULE__)
end
defp get_free_port do
@@ -37,7 +40,7 @@ defmodule Bamboo.MandrillAdapterTest do
end
def shutdown do
- Plug.Adapters.Cowboy.shutdown(__MODULE__)
+ Cowboy.shutdown(__MODULE__)
end
post "/api/1.0/messages/send.json" do
@@ -73,7 +76,7 @@ defmodule Bamboo.MandrillAdapterTest do
test "raises if the api key is nil" do
assert_raise ArgumentError, ~r/no API key set/, fn ->
- new_email(from: "foo@bar.com") |> MandrillAdapter.deliver(@config_with_bad_key)
+ [from: "foo@bar.com"] |> new_email() |> MandrillAdapter.deliver(@config_with_bad_key)
end
assert_raise ArgumentError, ~r/no API key set/, fn ->
@@ -82,7 +85,7 @@ defmodule Bamboo.MandrillAdapterTest do
end
test "deliver/2 sends the to the right url" do
- new_email() |> MandrillAdapter.deliver(@config)
+ MandrillAdapter.deliver(new_email(), @config)
assert_receive {:fake_mandrill, %{request_path: request_path}}
@@ -90,7 +93,7 @@ defmodule Bamboo.MandrillAdapterTest do
end
test "deliver/2 returns an {:ok, response} tuple on success" do
- {:ok, response} = new_email() |> MandrillAdapter.deliver(@config)
+ {:ok, response} = MandrillAdapter.deliver(new_email(), @config)
assert %{status_code: 200, headers: _, body: _} = response
end
@@ -107,12 +110,8 @@ defmodule Bamboo.MandrillAdapterTest do
file_path = Path.join(__DIR__, "../../../support/attachment.txt")
email =
- new_email(
- from: {"From", "from@foo.com"},
- subject: "My Subject",
- text_body: "TEXT BODY",
- html_body: "HTML BODY"
- )
+ [from: {"From", "from@foo.com"}, subject: "My Subject", text_body: "TEXT BODY", html_body: "HTML BODY"]
+ |> new_email()
|> Email.put_header("Reply-To", "reply@foo.com")
|> Email.put_attachment(file_path)
|> Email.put_attachment(Attachment.new(file_path, content_id: "my_fake_image", filename: "fake_image.jpg"))
@@ -126,14 +125,14 @@ defmodule Bamboo.MandrillAdapterTest do
140, 33, 0, 0, 0, 0, 73, 69, 78, 68, 174, 66, 96, 130>>
})
- email |> MandrillAdapter.deliver(@config)
+ MandrillAdapter.deliver(email, @config)
assert MandrillAdapter.supports_attachments?()
assert_receive {:fake_mandrill, %{params: params}}
assert params["key"] == @config[:api_key]
message = params["message"]
- assert message["from_name"] == email.from |> elem(0)
- assert message["from_email"] == email.from |> elem(1)
+ assert message["from_name"] == elem(email.from, 0)
+ assert message["from_email"] == elem(email.from, 1)
assert message["subject"] == email.subject
assert message["text"] == email.text_body
assert message["html"] == email.html_body
@@ -170,30 +169,30 @@ defmodule Bamboo.MandrillAdapterTest do
bcc: [{"BCC", "bcc@bar.com"}]
)
- email |> MandrillAdapter.deliver(@config)
+ MandrillAdapter.deliver(email, @config)
assert_receive {:fake_mandrill, %{params: %{"message" => message}}}
assert message["to"] == [
- %{"name" => "To", "email" => "to@bar.com", "type" => "to"},
+ %{"name" => "BCC", "email" => "bcc@bar.com", "type" => "bcc"},
%{"name" => "CC", "email" => "cc@bar.com", "type" => "cc"},
- %{"name" => "BCC", "email" => "bcc@bar.com", "type" => "bcc"}
+ %{"name" => "To", "email" => "to@bar.com", "type" => "to"}
]
end
test "deliver/2 adds extra params to the message " do
- email = new_email() |> MandrillHelper.put_param("important", true)
+ email = MandrillHelper.put_param(new_email(), "important", true)
- email |> MandrillAdapter.deliver(@config)
+ MandrillAdapter.deliver(email, @config)
assert_receive {:fake_mandrill, %{params: %{"message" => message}}}
assert message["important"] == true
end
test "deliver/2 puts template name and empty content" do
- email = new_email() |> MandrillHelper.template("hello")
+ email = MandrillHelper.template(new_email(), "hello")
- email |> MandrillAdapter.deliver(@config)
+ MandrillAdapter.deliver(email, @config)
assert_receive {:fake_mandrill,
%{
@@ -209,12 +208,11 @@ defmodule Bamboo.MandrillAdapterTest do
test "deliver/2 puts template name and content" do
email =
- new_email()
- |> MandrillHelper.template("hello", [
+ MandrillHelper.template(new_email(), "hello", [
%{name: ~c"example name", content: ~c"example content"}
])
- email |> MandrillAdapter.deliver(@config)
+ MandrillAdapter.deliver(email, @config)
assert_receive {:fake_mandrill,
%{
@@ -231,7 +229,7 @@ defmodule Bamboo.MandrillAdapterTest do
test "returns an error if the response is not a success" do
email = new_email(from: "INVALID_EMAIL")
- {:error, error} = email |> MandrillAdapter.deliver(@config)
+ {:error, error} = MandrillAdapter.deliver(email, @config)
assert %Bamboo.ApiError{} = error
end
@@ -239,13 +237,13 @@ defmodule Bamboo.MandrillAdapterTest do
test "removes api key from error output" do
email = new_email(from: "INVALID_EMAIL")
- {:error, error} = email |> MandrillAdapter.deliver(@config)
+ {:error, error} = MandrillAdapter.deliver(email, @config)
assert error.message =~ ~r/"key" => "\[FILTERED\]"/
end
defp new_email(attrs \\ []) do
attrs = Keyword.merge([from: "foo@bar.com", to: []], attrs)
- Email.new_email(attrs) |> Bamboo.Mailer.normalize_addresses()
+ attrs |> Email.new_email() |> Bamboo.Mailer.normalize_addresses()
end
end
diff --git a/test/lib/bamboo/adapters/mandrill_helper_test.exs b/test/lib/bamboo/adapters/mandrill_helper_test.exs
index 59732397..69694623 100644
--- a/test/lib/bamboo/adapters/mandrill_helper_test.exs
+++ b/test/lib/bamboo/adapters/mandrill_helper_test.exs
@@ -4,7 +4,7 @@ defmodule Bamboo.MandrillHelperTest do
alias Bamboo.MandrillHelper
test "put_param/3 puts a map in private.message_params" do
- email = new_email() |> MandrillHelper.put_param("track_links", true)
+ email = MandrillHelper.put_param(new_email(), "track_links", true)
assert email.private.message_params == %{"track_links" => true}
end
@@ -51,17 +51,16 @@ defmodule Bamboo.MandrillHelperTest do
end
test "adds tags to mandrill emails" do
- email = new_email() |> MandrillHelper.tag("welcome-email")
+ email = MandrillHelper.tag(new_email(), "welcome-email")
assert email.private.message_params == %{"tags" => ["welcome-email"]}
- email = new_email() |> MandrillHelper.tag(["welcome-email", "awesome"])
+ email = MandrillHelper.tag(new_email(), ["welcome-email", "awesome"])
assert email.private.message_params == %{"tags" => ["welcome-email", "awesome"]}
end
test "adds template information to mandrill emails" do
email =
- new_email()
- |> MandrillHelper.template("welcome", [
+ MandrillHelper.template(new_email(), "welcome", [
%{"name" => "example_name", "content" => "example_content"}
])
@@ -70,7 +69,7 @@ defmodule Bamboo.MandrillHelperTest do
template_content: [%{"name" => "example_name", "content" => "example_content"}]
}
- email = new_email() |> MandrillHelper.template("welcome")
+ email = MandrillHelper.template(new_email(), "welcome")
assert email.private == %{template_name: "welcome", template_content: []}
end
end
diff --git a/test/lib/bamboo/adapters/send_grid_adapter_test.exs b/test/lib/bamboo/adapters/send_grid_adapter_test.exs
index a6b97115..862d7f00 100644
--- a/test/lib/bamboo/adapters/send_grid_adapter_test.exs
+++ b/test/lib/bamboo/adapters/send_grid_adapter_test.exs
@@ -22,6 +22,8 @@ defmodule Bamboo.SendGridAdapterTest do
defmodule FakeSendgrid do
use Plug.Router
+ alias Plug.Cowboy
+
plug(
Plug.Parsers,
parsers: [:urlencoded, :multipart, :json],
@@ -37,7 +39,7 @@ defmodule Bamboo.SendGridAdapterTest do
Agent.update(__MODULE__, &Map.put(&1, :parent, parent))
port = get_free_port()
Application.put_env(:bamboo, :sendgrid_base_uri, "http://localhost:#{port}")
- Plug.Adapters.Cowboy.http(__MODULE__, [], port: port, ref: __MODULE__)
+ Cowboy.http(__MODULE__, [], port: port, ref: __MODULE__)
end
defp get_free_port do
@@ -48,7 +50,7 @@ defmodule Bamboo.SendGridAdapterTest do
end
def shutdown do
- Plug.Adapters.Cowboy.shutdown(__MODULE__)
+ Cowboy.shutdown(__MODULE__)
end
post "/mail/send" do
@@ -69,7 +71,7 @@ defmodule Bamboo.SendGridAdapterTest do
This is a private function that is referenced in `Bamboo.SendGridAdapterTest`
to test the config usage example of having a dynamic key
"""
- def sendgrid_secret(), do: @good_api_key
+ def sendgrid_secret, do: @good_api_key
setup do
FakeSendgrid.start_server(self())
@@ -84,7 +86,7 @@ defmodule Bamboo.SendGridAdapterTest do
describe "API key section" do
test "raises if the api key is nil" do
assert_raise ArgumentError, ~r/no API key set/, fn ->
- new_email(from: "foo@bar.com") |> SendGridAdapter.deliver(@config_with_bad_key)
+ [from: "foo@bar.com"] |> new_email() |> SendGridAdapter.deliver(@config_with_bad_key)
end
assert_raise ArgumentError, ~r/no API key set/, fn ->
@@ -113,7 +115,7 @@ defmodule Bamboo.SendGridAdapterTest do
System.delete_env("SENDGRID_API")
assert_raise ArgumentError, ~r/no API key set/, fn ->
- new_email(from: "foo@bar.com") |> SendGridAdapter.deliver(@config_with_env_var_key)
+ [from: "foo@bar.com"] |> new_email() |> SendGridAdapter.deliver(@config_with_env_var_key)
end
assert_raise ArgumentError, ~r/no API key set/, fn ->
@@ -123,13 +125,13 @@ defmodule Bamboo.SendGridAdapterTest do
end
test "deliver/2 returns an {:ok, response}" do
- {:ok, response} = new_email() |> SendGridAdapter.deliver(@config)
+ {:ok, response} = SendGridAdapter.deliver(new_email(), @config)
assert %{status_code: 200, headers: _, body: _} = response
end
test "deliver/2 sends the to the right url" do
- new_email() |> SendGridAdapter.deliver(@config)
+ SendGridAdapter.deliver(new_email(), @config)
assert_receive {:fake_sendgrid, %{request_path: request_path}}
@@ -138,22 +140,18 @@ defmodule Bamboo.SendGridAdapterTest do
test "deliver/2 sends from, html and text body, subject, headers and attachment" do
email =
- new_email(
- from: {"From", "from@foo.com"},
- subject: "My Subject",
- text_body: "TEXT BODY",
- html_body: "HTML BODY"
- )
+ [from: {"From", "from@foo.com"}, subject: "My Subject", text_body: "TEXT BODY", html_body: "HTML BODY"]
+ |> new_email()
|> Email.put_header("Reply-To", "reply@foo.com")
|> Email.put_attachment(Path.join(__DIR__, "../../../support/attachment.txt"))
- email |> SendGridAdapter.deliver(@config)
+ SendGridAdapter.deliver(email, @config)
assert SendGridAdapter.supports_attachments?()
assert_receive {:fake_sendgrid, %{params: params, req_headers: headers}}
- assert params["from"]["name"] == email.from |> elem(0)
- assert params["from"]["email"] == email.from |> elem(1)
+ assert params["from"]["name"] == elem(email.from, 0)
+ assert params["from"]["email"] == elem(email.from, 1)
assert params["subject"] == email.subject
assert Enum.member?(params["content"], %{"type" => "text/plain", "value" => email.text_body})
assert Enum.member?(params["content"], %{"type" => "text/html", "value" => email.html_body})
@@ -183,8 +181,7 @@ defmodule Bamboo.SendGridAdapterTest do
test "deliver/2 without custom args" do
email = new_email()
- email
- |> SendGridAdapter.deliver(@config)
+ SendGridAdapter.deliver(email, @config)
assert_receive {:fake_sendgrid, %{params: params}}
personalization = List.first(params["personalizations"])
@@ -199,7 +196,7 @@ defmodule Bamboo.SendGridAdapterTest do
bcc: [{"BCC", "bcc@bar.com"}]
)
- email |> SendGridAdapter.deliver(@config)
+ SendGridAdapter.deliver(email, @config)
assert_receive {:fake_sendgrid, %{params: params}}
addressees = List.first(params["personalizations"])
@@ -385,8 +382,7 @@ defmodule Bamboo.SendGridAdapterTest do
test "deliver/2 doesn't force a subject" do
email = new_email(from: {"From", "from@foo.com"})
- email
- |> SendGridAdapter.deliver(@config)
+ SendGridAdapter.deliver(email, @config)
assert_receive {:fake_sendgrid, %{params: params}}
refute Map.has_key?(params, "subject")
@@ -395,7 +391,7 @@ defmodule Bamboo.SendGridAdapterTest do
test "deliver/2 correctly formats reply-to from headers" do
email = new_email(headers: %{"reply-to" => "foo@bar.com"})
- email |> SendGridAdapter.deliver(@config)
+ SendGridAdapter.deliver(email, @config)
assert_receive {:fake_sendgrid, %{params: params}}
assert params["reply_to"] == %{"email" => "foo@bar.com"}
@@ -404,7 +400,7 @@ defmodule Bamboo.SendGridAdapterTest do
test "deliver/2 correctly formats Reply-To from headers" do
email = new_email(headers: %{"Reply-To" => "foo@bar.com"})
- email |> SendGridAdapter.deliver(@config)
+ SendGridAdapter.deliver(email, @config)
assert_receive {:fake_sendgrid, %{params: params}}
assert params["reply_to"] == %{"email" => "foo@bar.com"}
@@ -413,7 +409,7 @@ defmodule Bamboo.SendGridAdapterTest do
test "deliver/2 correctly formats Reply-To from headers with name and email" do
email = new_email(headers: %{"Reply-To" => {"Foo Bar", "foo@bar.com"}})
- email |> SendGridAdapter.deliver(@config)
+ SendGridAdapter.deliver(email, @config)
assert_receive {:fake_sendgrid, %{params: params}}
assert params["reply_to"] == %{"email" => "foo@bar.com", "name" => "Foo Bar"}
@@ -422,7 +418,7 @@ defmodule Bamboo.SendGridAdapterTest do
test "deliver/2 correctly formats reply-to from headers with name and email" do
email = new_email(headers: %{"reply-to" => {"Foo Bar", "foo@bar.com"}})
- email |> SendGridAdapter.deliver(@config)
+ SendGridAdapter.deliver(email, @config)
assert_receive {:fake_sendgrid, %{params: params}}
assert params["reply_to"] == %{"email" => "foo@bar.com", "name" => "Foo Bar"}
@@ -437,7 +433,7 @@ defmodule Bamboo.SendGridAdapterTest do
}
)
- email |> SendGridAdapter.deliver(@config)
+ SendGridAdapter.deliver(email, @config)
assert_receive {:fake_sendgrid, %{params: params}}
@@ -455,7 +451,7 @@ defmodule Bamboo.SendGridAdapterTest do
}
)
- email |> SendGridAdapter.deliver(@config)
+ SendGridAdapter.deliver(email, @config)
assert_receive {:fake_sendgrid, %{params: params}}
@@ -465,7 +461,7 @@ defmodule Bamboo.SendGridAdapterTest do
test "deliver/2 omits attachments key if no attachments" do
email = new_email()
- email |> SendGridAdapter.deliver(@config)
+ SendGridAdapter.deliver(email, @config)
assert_receive {:fake_sendgrid, %{params: params}}
refute Map.has_key?(params, "attachments")
@@ -498,20 +494,20 @@ defmodule Bamboo.SendGridAdapterTest do
}
email =
- new_email(
+ [
to: [{"To", "to@bar.com"}, {nil, "noname@bar.com"}],
cc: [{"CC", "cc@bar.com"}],
subject: "My Subject",
bcc: [{"BCC", "bcc@bar.com"}]
- )
+ ]
+ |> new_email()
|> Email.put_header("Reply-To", "reply@foo.com")
|> Bamboo.SendGridHelper.substitute("%foo%", "bar")
|> Bamboo.SendGridHelper.with_send_at(1_580_485_562)
|> Bamboo.SendGridHelper.add_personalizations([personalization2, personalization3])
|> Email.put_private(:custom_args, %{post_code: "123"})
- email
- |> SendGridAdapter.deliver(@config)
+ SendGridAdapter.deliver(email, @config)
assert_receive {:fake_sendgrid, %{params: params}}
personalizations = params["personalizations"]
@@ -575,8 +571,7 @@ defmodule Bamboo.SendGridAdapterTest do
|> Email.put_header("Reply-To", "reply@foo.com")
|> Bamboo.SendGridHelper.add_personalizations(personalizations)
- email
- |> SendGridAdapter.deliver(@config)
+ SendGridAdapter.deliver(email, @config)
assert_receive {:fake_sendgrid, %{params: params}}
personalizations = params["personalizations"]
@@ -603,7 +598,7 @@ defmodule Bamboo.SendGridAdapterTest do
|> Email.put_header("Reply-To", "reply@foo.com")
|> Bamboo.SendGridHelper.add_personalizations([%{subject: "This will fail"}])
- {:error, msg} = email |> SendGridAdapter.deliver(@config)
+ {:error, msg} = SendGridAdapter.deliver(email, @config)
assert msg =~ ~r/'to' field/
end
@@ -614,7 +609,7 @@ defmodule Bamboo.SendGridAdapterTest do
|> Email.put_header("Reply-To", "reply@foo.com")
|> Bamboo.SendGridHelper.add_personalizations([%{to: "foo@bar.com", send_at: "now"}])
- {:error, msg} = email |> SendGridAdapter.deliver(@config)
+ {:error, msg} = SendGridAdapter.deliver(email, @config)
assert msg =~ ~r/'send_at' time/
end
@@ -632,8 +627,7 @@ defmodule Bamboo.SendGridAdapterTest do
|> Email.put_header("Reply-To", "reply@foo.com")
|> Bamboo.SendGridHelper.add_personalizations([personalization])
- email
- |> SendGridAdapter.deliver(@config)
+ SendGridAdapter.deliver(email, @config)
assert_receive {:fake_sendgrid, %{params: params}}
[got_personalization] = params["personalizations"]
@@ -655,7 +649,7 @@ defmodule Bamboo.SendGridAdapterTest do
|> Email.put_header("Reply-To", "reply@foo.com")
|> Bamboo.SendGridHelper.add_personalizations([%{to: %{"name" => "Lou"}, send_at: "now"}])
- {:error, msg} = email |> SendGridAdapter.deliver(@config)
+ {:error, msg} = SendGridAdapter.deliver(email, @config)
assert msg =~ ~r/'email' field/
end
@@ -681,7 +675,7 @@ defmodule Bamboo.SendGridAdapterTest do
test "deliver/2 will set sandbox mode correctly" do
email = new_email()
- email |> SendGridAdapter.deliver(@config_with_sandbox_enabled)
+ SendGridAdapter.deliver(email, @config_with_sandbox_enabled)
assert_receive {:fake_sendgrid, %{params: params}}
assert params["mail_settings"]["sandbox_mode"]["enable"] == true
@@ -702,7 +696,7 @@ defmodule Bamboo.SendGridAdapterTest do
test "returns an error if the response is not a success" do
email = new_email(from: "INVALID_EMAIL")
- {:error, error} = email |> SendGridAdapter.deliver(@config)
+ {:error, error} = SendGridAdapter.deliver(email, @config)
assert %Bamboo.ApiError{} = error
end
@@ -710,13 +704,12 @@ defmodule Bamboo.SendGridAdapterTest do
test "removes api key from error output" do
email = new_email(from: "INVALID_EMAIL")
- {:error, error} = email |> SendGridAdapter.deliver(@config)
+ {:error, error} = SendGridAdapter.deliver(email, @config)
assert error.message =~ ~r/"key" => "\[FILTERED\]"/
end
defp new_email(attrs \\ []) do
- attrs = Keyword.merge([from: "foo@bar.com", to: []], attrs)
- Email.new_email(attrs) |> Bamboo.Mailer.normalize_addresses()
+ [from: "foo@bar.com", to: []] |> Keyword.merge(attrs) |> Email.new_email() |> Bamboo.Mailer.normalize_addresses()
end
end
diff --git a/test/lib/bamboo/adapters/send_grid_helper_test.exs b/test/lib/bamboo/adapters/send_grid_helper_test.exs
index 51f72bac..ab0f048f 100644
--- a/test/lib/bamboo/adapters/send_grid_helper_test.exs
+++ b/test/lib/bamboo/adapters/send_grid_helper_test.exs
@@ -11,7 +11,7 @@ defmodule Bamboo.SendGridHelperTest do
end
test "with_template/2 adds the correct template", %{email: email} do
- email = email |> with_template(@template_id)
+ email = with_template(email, @template_id)
assert email.private[:send_grid_template] == %{template_id: @template_id}
end
@@ -34,7 +34,7 @@ defmodule Bamboo.SendGridHelperTest do
test "substitute/3 raises on non-binary tag", %{email: email} do
assert_raise RuntimeError, fn ->
- email |> substitute(:name, "Jon Snow")
+ substitute(email, :name, "Jon Snow")
end
end
@@ -78,8 +78,7 @@ defmodule Bamboo.SendGridHelperTest do
test "dynamic_field/3 should work with atoms", %{email: email} do
email =
- email
- |> add_dynamic_field(:name, "Jon Snow")
+ add_dynamic_field(email, :name, "Jon Snow")
assert email.private[:send_grid_template] == %{
dynamic_template_data: %{
@@ -89,7 +88,7 @@ defmodule Bamboo.SendGridHelperTest do
end
test "with_categories/2 adds the correct property", %{email: email} do
- email = email |> with_categories(["category-1"])
+ email = with_categories(email, ["category-1"])
assert email.private[:categories] != nil
assert is_list(email.private[:categories])
assert length(email.private[:categories]) == 1
@@ -111,8 +110,7 @@ defmodule Bamboo.SendGridHelperTest do
test "with_categories/2 only sends the first 10 entries", %{email: email} do
email =
- email
- |> with_categories([
+ with_categories(email, [
"category-1",
"category-2",
"category-3",
@@ -130,24 +128,24 @@ defmodule Bamboo.SendGridHelperTest do
end
test "with_asm_group_id/2 adds the correct property", %{email: email} do
- email = email |> with_asm_group_id(1234)
+ email = with_asm_group_id(email, 1234)
assert email.private[:asm_group_id] == 1234
end
test "with_asm_group_id/2 raises on non-integer id", %{email: email} do
assert_raise RuntimeError, fn ->
- email |> with_asm_group_id("1234")
+ with_asm_group_id(email, "1234")
end
end
test "with_bypass_list_management/2 adds the correct property", %{email: email} do
- email = email |> with_bypass_list_management(true)
+ email = with_bypass_list_management(email, true)
assert email.private[:bypass_list_management] == true
end
test "with_bypass_list_management/2 raises on non-boolean parameter", %{email: email} do
assert_raise RuntimeError, fn ->
- email |> with_bypass_list_management(1)
+ with_bypass_list_management(email, 1)
end
end
@@ -160,14 +158,14 @@ defmodule Bamboo.SendGridHelperTest do
utm_content: "content"
}
- email = email |> with_google_analytics(true, utm_params)
+ email = with_google_analytics(email, true, utm_params)
assert email.private[:google_analytics_enabled] == true
assert email.private[:google_analytics_utm_params] == utm_params
end
test "with_google_analytics/3 with enabled set false", %{email: email} do
- email = email |> with_google_analytics(false)
+ email = with_google_analytics(email, false)
assert email.private[:google_analytics_enabled] == false
assert email.private[:google_analytics_utm_params] == %{}
@@ -179,7 +177,7 @@ defmodule Bamboo.SendGridHelperTest do
}
assert_raise RuntimeError, fn ->
- email |> with_google_analytics(1, utm_params)
+ with_google_analytics(email, 1, utm_params)
end
end
@@ -204,25 +202,25 @@ defmodule Bamboo.SendGridHelperTest do
describe "with_send_at/2" do
test "adds the correct property for a DateTime input", %{email: email} do
{:ok, datetime, _} = DateTime.from_iso8601("2020-01-31T15:46:00Z")
- email = email |> with_send_at(datetime)
+ email = with_send_at(email, datetime)
assert email.private[:sendgrid_send_at] == 1_580_485_560
end
test "adds the correct property for an integer input", %{email: email} do
timestamp = 1_580_485_560
- email = email |> with_send_at(timestamp)
+ email = with_send_at(email, timestamp)
assert email.private[:sendgrid_send_at] == 1_580_485_560
end
test "raises on incorrect input", %{email: email} do
assert_raise RuntimeError, fn ->
- email |> with_send_at("truck")
+ with_send_at(email, "truck")
end
end
end
test "with_ip_pool_name/2 adds the ip_pool_name", %{email: email} do
- email = email |> with_ip_pool_name(@ip_pool_name)
+ email = with_ip_pool_name(email, @ip_pool_name)
assert email.private[:ip_pool_name] == @ip_pool_name
end
@@ -246,7 +244,7 @@ defmodule Bamboo.SendGridHelperTest do
test "with_custom_args/2 raises on non-map parameter", %{email: email} do
assert_raise RuntimeError, fn ->
- email |> with_custom_args(["new arg"])
+ with_custom_args(email, ["new arg"])
end
end
end
diff --git a/test/lib/bamboo/adapters/test_adapter_test.exs b/test/lib/bamboo/adapters/test_adapter_test.exs
index 97b9d713..cda3a4c9 100644
--- a/test/lib/bamboo/adapters/test_adapter_test.exs
+++ b/test/lib/bamboo/adapters/test_adapter_test.exs
@@ -18,7 +18,7 @@ defmodule Bamboo.TestAdapterTest do
email = new_email()
config = %{}
- email |> TestAdapter.deliver(config)
+ TestAdapter.deliver(email, config)
email = TestAdapter.clean_assigns(email)
@@ -43,7 +43,7 @@ defmodule Bamboo.TestAdapterTest do
test "succeeds when email is sent" do
sent_email = new_email(from: "foo@bar.com", to: ["foo@bar.com"])
- sent_email |> TestMailer.deliver_now()
+ TestMailer.deliver_now(sent_email)
assert_delivered_email(sent_email)
end
@@ -51,7 +51,7 @@ defmodule Bamboo.TestAdapterTest do
test "flunks test when email does not match" do
sent_email = new_email(from: "foo@bar.com", to: ["foo@bar.com"])
- sent_email |> TestMailer.deliver_now()
+ TestMailer.deliver_now(sent_email)
assert_raise ExUnit.AssertionError, ~r/no matching emails/, fn ->
assert_delivered_email(%{sent_email | to: "oops"})
@@ -69,7 +69,7 @@ defmodule Bamboo.TestAdapterTest do
test "shows non-matching delivered emails" do
sent_email = new_email(from: "foo@bar.com", to: ["foo@bar.com"])
- sent_email |> TestMailer.deliver_now()
+ TestMailer.deliver_now(sent_email)
assert_raise ExUnit.AssertionError, ~r/#{sent_email.from}/, fn ->
assert_delivered_email(%{sent_email | to: "oops"})
@@ -102,7 +102,7 @@ defmodule Bamboo.TestAdapterTest do
sent_email = new_email(from: user_that_needs_to_be_formatted, to: "foo@bar.com")
- sent_email |> TestMailer.deliver_now()
+ TestMailer.deliver_now(sent_email)
assert_delivered_email(sent_email)
end
@@ -110,7 +110,7 @@ defmodule Bamboo.TestAdapterTest do
test "delivered emails have normalized assigns" do
email = new_email(from: "foo@bar.com", to: "bar@baz.com", assigns: :anything)
- email |> TestMailer.deliver_now()
+ TestMailer.deliver_now(email)
assert_delivered_email(%{email | assigns: :assigns_removed_for_testing})
end
@@ -118,7 +118,7 @@ defmodule Bamboo.TestAdapterTest do
test "accepts timeout" do
email = new_email(from: "foo@bar.com", to: "bar@baz.com")
- email |> TestMailer.deliver_now()
+ TestMailer.deliver_now(email)
assert_delivered_email(email, timeout: 1)
end
@@ -134,7 +134,7 @@ defmodule Bamboo.TestAdapterTest do
test "flunks when a test is sent" do
sent_email = new_email(from: "foo@bar.com", to: ["foo@bar.com"])
- sent_email |> TestMailer.deliver_now()
+ TestMailer.deliver_now(sent_email)
assert_raise ExUnit.AssertionError, ~r/Unexpectedly delivered a matching email/, fn ->
refute_delivered_email(sent_email)
@@ -162,7 +162,7 @@ defmodule Bamboo.TestAdapterTest do
test "succeeds when attributes match delivered email" do
sent_email = new_email(from: "foo@bar.com", to: ["foo@bar.com"])
- sent_email |> TestMailer.deliver_now()
+ TestMailer.deliver_now(sent_email)
assert_email_delivered_with(from: "foo@bar.com")
end
@@ -170,7 +170,7 @@ defmodule Bamboo.TestAdapterTest do
test "normalizes the email on assertion" do
sent_email = new_email(from: "foo@bar.com", to: ["foo@bar.com"])
- sent_email |> TestMailer.deliver_now()
+ TestMailer.deliver_now(sent_email)
assert_email_delivered_with(from: {nil, "foo@bar.com"})
end
@@ -178,7 +178,7 @@ defmodule Bamboo.TestAdapterTest do
test "flunks test if email attributes differ" do
sent_email = new_email(from: "foo@bar.com", to: ["foo@bar.com"])
- sent_email |> TestMailer.deliver_now()
+ TestMailer.deliver_now(sent_email)
assert_raise ExUnit.AssertionError, ~r/parameters given do not match/, fn ->
assert_email_delivered_with(from: "oops")
@@ -194,7 +194,7 @@ defmodule Bamboo.TestAdapterTest do
test "shows non-matching delivered email when failing test" do
sent_email = new_email(from: "foo@bar.com", to: ["foo@bar.com"])
- sent_email |> TestMailer.deliver_now()
+ TestMailer.deliver_now(sent_email)
try do
assert_email_delivered_with(to: "oops")
@@ -208,22 +208,16 @@ defmodule Bamboo.TestAdapterTest do
end
test "allows regex matching" do
- new_email(
- to: {nil, "foo@bar.com"},
- from: {nil, "foo@bar.com"},
- text_body: "I really like coffee"
- )
+ [to: {nil, "foo@bar.com"}, from: {nil, "foo@bar.com"}, text_body: "I really like coffee"]
+ |> new_email()
|> TestMailer.deliver_now()
assert_email_delivered_with(text_body: ~r/like/)
end
test "regex matching doesn't provide a false positive" do
- new_email(
- to: {nil, "foo@bar.com"},
- from: {nil, "foo@bar.com"},
- text_body: "I really like coffee"
- )
+ [to: {nil, "foo@bar.com"}, from: {nil, "foo@bar.com"}, text_body: "I really like coffee"]
+ |> new_email()
|> TestMailer.deliver_now()
assert_raise ExUnit.AssertionError, ~r/do not match/, fn ->
@@ -234,7 +228,7 @@ defmodule Bamboo.TestAdapterTest do
test "accepts timeout" do
email = new_email(from: "foo@bar.com", to: "bar@baz.com")
- email |> TestMailer.deliver_now()
+ TestMailer.deliver_now(email)
assert_email_delivered_with([from: "foo@bar.com"], timeout: 1)
end
@@ -320,7 +314,7 @@ defmodule Bamboo.TestAdapterTest do
assert_no_emails_delivered()
sent_email = new_email(from: "foo@bar.com", to: "whoever")
- sent_email |> TestMailer.deliver_now()
+ TestMailer.deliver_now(sent_email)
assert_raise ExUnit.AssertionError, fn ->
assert_no_emails_delivered()
@@ -329,7 +323,7 @@ defmodule Bamboo.TestAdapterTest do
test "accepts a timeout configuration" do
sent_email = new_email(from: "foo@bar.com", to: "whoever")
- sent_email |> TestMailer.deliver_now()
+ TestMailer.deliver_now(sent_email)
assert_raise ExUnit.AssertionError, fn ->
assert_no_emails_delivered(timeout: 1)
diff --git a/test/lib/bamboo/email_test.exs b/test/lib/bamboo/email_test.exs
index f60112b1..d1b7b638 100644
--- a/test/lib/bamboo/email_test.exs
+++ b/test/lib/bamboo/email_test.exs
@@ -39,7 +39,8 @@ defmodule Bamboo.EmailTest do
test "returns list of all recipients" do
email =
- new_email(from: "foo", to: "to@foo.com", cc: "cc@foo.com", bcc: "bcc@foo.com")
+ [from: "foo", to: "to@foo.com", cc: "cc@foo.com", bcc: "bcc@foo.com"]
+ |> new_email()
|> Bamboo.Mailer.normalize_addresses()
assert all_recipients(email) == [
@@ -75,7 +76,7 @@ defmodule Bamboo.EmailTest do
end
test "put_private/3 puts a key and value in the private attribute" do
- email = new_email() |> put_private("foo", "bar")
+ email = put_private(new_email(), "foo", "bar")
assert email.private["foo"] == "bar"
end
@@ -83,7 +84,7 @@ defmodule Bamboo.EmailTest do
describe "put_attachment/2" do
test "adds an attachment to the attachments list" do
attachment = %Bamboo.Attachment{filename: "attachment.docx", data: "content"}
- email = new_email() |> put_attachment(attachment)
+ email = put_attachment(new_email(), attachment)
assert [%Bamboo.Attachment{filename: "attachment.docx"}] = email.attachments
end
@@ -92,10 +93,10 @@ defmodule Bamboo.EmailTest do
attachment = %Bamboo.Attachment{filename: nil, data: "content"}
msg =
- "You must provide a filename for the attachment, instead got: %Bamboo.Attachment{content_id: nil, content_type: nil, data: \"content\", filename: nil, path: nil}"
+ "You must provide a filename for the attachment, instead got: %Bamboo.Attachment{filename: nil, content_type: nil, path: nil, data: \"content\", content_id: nil}"
assert_raise RuntimeError, msg, fn ->
- new_email() |> put_attachment(attachment)
+ put_attachment(new_email(), attachment)
end
end
@@ -103,17 +104,17 @@ defmodule Bamboo.EmailTest do
attachment = %Bamboo.Attachment{filename: "attachment.docx", data: nil}
msg =
- "The attachment must contain data, instead got: %Bamboo.Attachment{content_id: nil, content_type: nil, data: nil, filename: \"attachment.docx\", path: nil}"
+ "The attachment must contain data, instead got: %Bamboo.Attachment{filename: \"attachment.docx\", content_type: nil, path: nil, data: nil, content_id: nil}"
assert_raise RuntimeError, msg, fn ->
- new_email() |> put_attachment(attachment)
+ put_attachment(new_email(), attachment)
end
end
end
test "put_attachment/3 adds an attachment to the attachments list" do
path = Path.join(__DIR__, "../../support/attachment.docx")
- email = new_email() |> put_attachment(path)
+ email = put_attachment(new_email(), path)
assert [%Bamboo.Attachment{filename: "attachment.docx"}] = email.attachments
end
diff --git a/test/lib/bamboo/mailer_test.exs b/test/lib/bamboo/mailer_test.exs
index 114b2a6f..c7d0e9fe 100644
--- a/test/lib/bamboo/mailer_test.exs
+++ b/test/lib/bamboo/mailer_test.exs
@@ -169,84 +169,92 @@ defmodule Bamboo.MailerTest do
end
test "deliver_now/1 with no from address returns an error" do
- {:error, %Bamboo.EmptyFromAddressError{}} = Mailer.deliver_now(new_email(from: nil))
- {:error, %Bamboo.EmptyFromAddressError{}} = Mailer.deliver_now(new_email(from: {"foo", nil}))
+ {:error, %Bamboo.EmptyFromAddressError{}} = [from: nil] |> new_email() |> Mailer.deliver_now()
+ {:error, %Bamboo.EmptyFromAddressError{}} = [from: {"foo", nil}] |> new_email() |> Mailer.deliver_now()
end
test "deliver_now!/1 with no from address raises an error" do
assert_raise Bamboo.EmptyFromAddressError, fn ->
- Mailer.deliver_now!(new_email(from: nil))
+ [from: nil] |> new_email() |> Mailer.deliver_now!()
end
assert_raise Bamboo.EmptyFromAddressError, fn ->
- Mailer.deliver_now!(new_email(from: {"foo", nil}))
+ [from: {"foo", nil}] |> new_email() |> Mailer.deliver_now!()
end
end
test "deliver_now/1 with empty recipient lists does not deliver email" do
- {:ok, email} = new_email(to: [], cc: [], bcc: []) |> Mailer.deliver_now()
+ {:ok, email} = [to: [], cc: [], bcc: []] |> new_email() |> Mailer.deliver_now()
refute_received {:deliver, ^email, _}
- {:ok, email} = new_email(to: [], cc: nil, bcc: nil) |> Mailer.deliver_now()
+ {:ok, email} = [to: [], cc: nil, bcc: nil] |> new_email() |> Mailer.deliver_now()
refute_received {:deliver, ^email, _}
- {:ok, email} = new_email(to: nil, cc: [], bcc: nil) |> Mailer.deliver_now()
+ {:ok, email} = [to: nil, cc: [], bcc: nil] |> new_email() |> Mailer.deliver_now()
refute_received {:deliver, ^email, _}
- {:ok, email} = new_email(to: nil, cc: nil, bcc: []) |> Mailer.deliver_now()
+ {:ok, email} = [to: nil, cc: nil, bcc: []] |> new_email() |> Mailer.deliver_now()
refute_received {:deliver, ^email, _}
end
test "deliver_later/1 with empty lists for recipients does not deliver email" do
- new_email(to: [], cc: [], bcc: []) |> Mailer.deliver_later()
+ [to: [], cc: [], bcc: []] |> new_email() |> Mailer.deliver_later()
refute_received {:deliver, _, _}
- new_email(to: [], cc: nil, bcc: nil) |> Mailer.deliver_later()
+ [to: [], cc: nil, bcc: nil] |> new_email() |> Mailer.deliver_later()
refute_received {:deliver, _, _}
- new_email(to: nil, cc: [], bcc: nil) |> Mailer.deliver_later()
+ [to: nil, cc: [], bcc: nil] |> new_email() |> Mailer.deliver_later()
refute_received {:deliver, _, _}
- new_email(to: nil, cc: nil, bcc: []) |> Mailer.deliver_later()
+ [to: nil, cc: nil, bcc: []] |> new_email() |> Mailer.deliver_later()
refute_received {:deliver, _, _}
end
test "returns an error if all recipients are nil" do
{:error, %Bamboo.NilRecipientsError{}} =
- new_email(to: nil, cc: nil, bcc: nil)
+ [to: nil, cc: nil, bcc: nil]
+ |> new_email()
|> Mailer.deliver_now()
{:error, %Bamboo.NilRecipientsError{}} =
- new_email(to: {"foo", nil})
+ [to: {"foo", nil}]
+ |> new_email()
|> Mailer.deliver_now()
{:error, %Bamboo.NilRecipientsError{}} =
- new_email(to: [{"foo", nil}])
+ [to: [{"foo", nil}]]
+ |> new_email()
|> Mailer.deliver_now()
{:error, %Bamboo.NilRecipientsError{}} =
- new_email(to: [nil])
+ [to: [nil]]
+ |> new_email()
|> Mailer.deliver_now()
end
test "raises on deliver_now! if all recipients are nil" do
assert_raise Bamboo.NilRecipientsError, fn ->
- new_email(to: nil, cc: nil, bcc: nil)
+ [to: nil, cc: nil, bcc: nil]
+ |> new_email()
|> Mailer.deliver_now!()
end
assert_raise Bamboo.NilRecipientsError, fn ->
- new_email(to: {"foo", nil})
+ [to: {"foo", nil}]
+ |> new_email()
|> Mailer.deliver_now!()
end
assert_raise Bamboo.NilRecipientsError, fn ->
- new_email(to: [{"foo", nil}])
+ [to: [{"foo", nil}]]
+ |> new_email()
|> Mailer.deliver_now!()
end
assert_raise Bamboo.NilRecipientsError, fn ->
- new_email(to: [nil])
+ [to: [nil]]
+ |> new_email()
|> Mailer.deliver_now!()
end
end
@@ -299,7 +307,7 @@ defmodule Bamboo.MailerTest do
@tag adapter: AdapterWithoutAttachmentSupport
test "returns errors if adapter does not support attachments and attachments are sent" do
path = Path.join(__DIR__, "../../support/attachment.docx")
- email = new_email(to: "foo@bar.com") |> Email.put_attachment(path)
+ email = [to: "foo@bar.com"] |> new_email() |> Email.put_attachment(path)
assert {:error, error} = Mailer.deliver_now(email)
assert error =~ "does not support attachments"
@@ -311,7 +319,7 @@ defmodule Bamboo.MailerTest do
@tag adapter: AdapterWithoutAttachmentSupport
test "raise errors with deliver_x! if adapter does not support attachments and attachments are sent" do
path = Path.join(__DIR__, "../../support/attachment.docx")
- email = new_email(to: "foo@bar.com") |> Email.put_attachment(path)
+ email = [to: "foo@bar.com"] |> new_email() |> Email.put_attachment(path)
assert_raise RuntimeError, ~r/does not support attachments/, fn ->
Mailer.deliver_now!(email)
@@ -331,7 +339,7 @@ defmodule Bamboo.MailerTest do
@tag adapter: DefaultAdapter
test "does not raise if adapter supports attachments" do
path = Path.join(__DIR__, "../../support/attachment.docx")
- email = new_email(to: "foo@bar.com") |> Email.put_attachment(path)
+ email = [to: "foo@bar.com"] |> new_email() |> Email.put_attachment(path)
Mailer.deliver_now(email)
@@ -347,7 +355,7 @@ defmodule Bamboo.MailerTest do
end
def handle_config(config) do
- config |> Map.put(:custom_key, "Set by the adapter")
+ Map.put(config, :custom_key, "Set by the adapter")
end
end
diff --git a/test/lib/bamboo/plug/sent_email_api_plug_test.exs b/test/lib/bamboo/plug/sent_email_api_plug_test.exs
index 39cae254..fc423553 100644
--- a/test/lib/bamboo/plug/sent_email_api_plug_test.exs
+++ b/test/lib/bamboo/plug/sent_email_api_plug_test.exs
@@ -29,7 +29,7 @@ defmodule Bamboo.SentEmailApiPlugTest do
text_body: "hello world"
)
- conn = conn(:get, "/emails.json") |> AppRouter.call(nil)
+ conn = :get |> conn("/emails.json") |> AppRouter.call(nil)
assert conn.status == 200
assert {"content-type", "application/json; charset=utf-8"} in conn.resp_headers
@@ -38,7 +38,7 @@ defmodule Bamboo.SentEmailApiPlugTest do
assert Enum.count(json) == 1
- first_email = json |> Enum.at(0)
+ first_email = Enum.at(json, 0)
assert first_email["from"] == [nil, "from@example.com"]
assert first_email["to"] == [[nil, "to@example.com"], ["Alice", "alice@example.com"]]
assert first_email["cc"] == [[nil, "cc@example.com"]]
@@ -51,15 +51,15 @@ defmodule Bamboo.SentEmailApiPlugTest do
test "reset emails over API" do
normalize_and_push(:html_email)
- assert SentEmail.all() |> Enum.count() == 1
+ assert Enum.count(SentEmail.all()) == 1
- conn = conn(:post, "/reset.json") |> AppRouter.call(nil)
+ conn = :post |> conn("/reset.json") |> AppRouter.call(nil)
assert conn.status == 200
assert {"content-type", "application/json; charset=utf-8"} in conn.resp_headers
json = Bamboo.json_library().decode!(conn.resp_body)
assert json == %{"ok" => true}
- assert SentEmail.all() |> Enum.count() == 0
+ assert Enum.empty?(SentEmail.all())
end
end
diff --git a/test/lib/bamboo/plug/sent_email_viewer_plug_test.exs b/test/lib/bamboo/plug/sent_email_viewer_plug_test.exs
index e133882a..53b9f985 100644
--- a/test/lib/bamboo/plug/sent_email_viewer_plug_test.exs
+++ b/test/lib/bamboo/plug/sent_email_viewer_plug_test.exs
@@ -32,11 +32,11 @@ defmodule Bamboo.SentEmailViewerPlugTest do
refute showing_in_detail_pane?(conn, oldest_email())
for email <- emails do
- assert Floki.raw_html(sidebar(conn)) =~
+ assert conn |> sidebar() |> Floki.raw_html() =~
~s(href="/sent_emails/foo/#{SentEmail.get_id(email)}")
- assert Floki.text(sidebar(conn)) =~ email.subject
- assert Floki.text(sidebar(conn)) =~ Bamboo.Email.get_address(email.from)
+ assert conn |> sidebar() |> Floki.text() =~ email.subject
+ assert conn |> sidebar() |> Floki.text() =~ Bamboo.Email.get_address(email.from)
end
end
@@ -139,7 +139,7 @@ defmodule Bamboo.SentEmailViewerPlugTest do
end
defp selected_sidebar_email_text(conn) do
- sidebar(conn) |> Floki.find("a.selected-email") |> Floki.text()
+ conn |> sidebar() |> Floki.find("a.selected-email") |> Floki.text()
end
test "shows attachment icon in sidebar for email with attachments" do
@@ -150,7 +150,7 @@ defmodule Bamboo.SentEmailViewerPlugTest do
conn = AppRouter.call(conn, nil)
assert conn.status == 200
- assert sidebar(conn) |> Floki.find(".selected-email .email-attachment-icon") != []
+ assert conn |> sidebar() |> Floki.find(".selected-email .email-attachment-icon") != []
end
test "does not show attachment icon in sidebar for email without attachments" do
@@ -160,7 +160,7 @@ defmodule Bamboo.SentEmailViewerPlugTest do
conn = AppRouter.call(conn, nil)
assert conn.status == 200
- assert sidebar(conn) |> Floki.find(".selected-email .email-attachment-icon") == []
+ assert conn |> sidebar() |> Floki.find(".selected-email .email-attachment-icon") == []
end
test "does not show attachments if email has none" do
@@ -220,8 +220,8 @@ defmodule Bamboo.SentEmailViewerPlugTest do
assert conn.status == 200
assert {"content-type", "text/html; charset=utf-8"} in conn.resp_headers
- assert Floki.raw_html(sidebar(conn)) =~ ~s(href="/#{SentEmail.get_id(email)}")
- assert Floki.text(sidebar(conn)) =~ email.subject
+ assert conn |> sidebar() |> Floki.raw_html() =~ ~s(href="/#{SentEmail.get_id(email)}")
+ assert conn |> sidebar() |> Floki.text() =~ email.subject
end
test "shows notice if no emails exist" do
@@ -283,15 +283,15 @@ defmodule Bamboo.SentEmailViewerPlugTest do
end
defp newest_email do
- SentEmail.all() |> List.first()
+ List.first(SentEmail.all())
end
defp oldest_email do
- SentEmail.all() |> List.last()
+ List.last(SentEmail.all())
end
defp showing_in_detail_pane?(conn, email) do
- Floki.text(detail_pane(conn)) =~ email.subject
+ conn |> detail_pane() |> Floki.text() =~ email.subject
end
defp detail_pane(conn) do
@@ -313,6 +313,6 @@ defmodule Bamboo.SentEmailViewerPlugTest do
end
defp showing_in_attachments_container?(conn, attachment) do
- Floki.text(detail_pane_attachments_container(conn)) =~ attachment.filename
+ conn |> detail_pane_attachments_container() |> Floki.text() =~ attachment.filename
end
end
diff --git a/test/lib/bamboo/sent_email_test.exs b/test/lib/bamboo/sent_email_test.exs
index d9eabf11..3ee41508 100644
--- a/test/lib/bamboo/sent_email_test.exs
+++ b/test/lib/bamboo/sent_email_test.exs
@@ -1,16 +1,17 @@
defmodule Bamboo.SentEmailTest do
use ExUnit.Case
- alias Bamboo.SentEmail
import Bamboo.Email
+ alias Bamboo.SentEmail
+
setup do
Bamboo.SentEmail.reset()
:ok
end
test "get_id gets the emails id" do
- email = new_email() |> put_private(:local_adapter_id, 1)
+ email = put_private(new_email(), :local_adapter_id, 1)
assert SentEmail.get_id(email) == 1
end
@@ -30,7 +31,7 @@ defmodule Bamboo.SentEmailTest do
end
test "gets an email by id" do
- pushed_email = SentEmail.push(new_email(subject: "Something"))
+ pushed_email = [subject: "Something"] |> new_email() |> SentEmail.push()
email = pushed_email |> SentEmail.get_id() |> SentEmail.get()
@@ -38,7 +39,7 @@ defmodule Bamboo.SentEmailTest do
end
test "get is case-insensitive" do
- pushed_email = SentEmail.push(new_email(subject: "Something"))
+ pushed_email = [subject: "Something"] |> new_email() |> SentEmail.push()
id = SentEmail.get_id(pushed_email)
diff --git a/test/lib/bamboo/strategies/immediate_delivery_strategy_test.exs b/test/lib/bamboo/strategies/immediate_delivery_strategy_test.exs
index 8f51d8fa..365d9b95 100644
--- a/test/lib/bamboo/strategies/immediate_delivery_strategy_test.exs
+++ b/test/lib/bamboo/strategies/immediate_delivery_strategy_test.exs
@@ -1,12 +1,12 @@
defmodule Bamboo.ImmediateDeliveryStrategyTest do
use ExUnit.Case
+ @mailer_config %{}
+
defmodule FakeAdapter do
def deliver(_email, _config), do: send(self(), :delivered)
end
- @mailer_config %{}
-
test "deliver_later delivers right away" do
Bamboo.ImmediateDeliveryStrategy.deliver_later(
FakeAdapter,
diff --git a/test/lib/bamboo/strategies/task_supervisor_strategy_test.exs b/test/lib/bamboo/strategies/task_supervisor_strategy_test.exs
index 51ede5d2..98e13678 100644
--- a/test/lib/bamboo/strategies/task_supervisor_strategy_test.exs
+++ b/test/lib/bamboo/strategies/task_supervisor_strategy_test.exs
@@ -1,6 +1,8 @@
defmodule Bamboo.TaskSupervisorStrategyTest do
use ExUnit.Case
+ @mailer_config %{}
+
defmodule FakeAdapter do
def deliver(_email, _config) do
send(:task_supervisor_strategy_test, :delivered)
@@ -14,8 +16,6 @@ defmodule Bamboo.TaskSupervisorStrategyTest do
end
end
- @mailer_config %{}
-
test "deliver_later delivers the email" do
Process.register(self(), :task_supervisor_strategy_test)
diff --git a/test/lib/bamboo/template_test.exs b/test/lib/bamboo/template_test.exs
index f52cd251..bb9fc6c3 100644
--- a/test/lib/bamboo/template_test.exs
+++ b/test/lib/bamboo/template_test.exs
@@ -24,8 +24,7 @@ defmodule Bamboo.TemplateTest do
text_layout: {LayoutView, "app.text"}
def text_and_html_email do
- new_email()
- |> render(:text_and_html_email)
+ render(new_email(), :text_and_html_email)
end
end
@@ -33,8 +32,7 @@ defmodule Bamboo.TemplateTest do
use Bamboo.Template
def no_view do
- new_email()
- |> render(:text_and_html_email)
+ render(new_email(), :text_and_html_email)
end
end
@@ -48,13 +46,11 @@ defmodule Bamboo.TemplateTest do
end
def text_and_html_email do
- new_email()
- |> render(:text_and_html_email)
+ render(new_email(), :text_and_html_email)
end
def email_with_assigns(user) do
- new_email()
- |> render(:email_with_assigns, user: user)
+ render(new_email(), :email_with_assigns, user: user)
end
def email_with_already_assigned_user(user) do
@@ -70,18 +66,15 @@ defmodule Bamboo.TemplateTest do
end
def html_email do
- new_email()
- |> render("html_email.html")
+ render(new_email(), "html_email.html")
end
def text_email do
- new_email()
- |> render("text_email.text")
+ render(new_email(), "text_email.text")
end
def text_and_html_calling_view_function_email do
- new_email()
- |> render(:text_and_html_calling_view_function_email)
+ render(new_email(), :text_and_html_calling_view_function_email)
end
def text_and_html_from_different_view do
@@ -91,13 +84,11 @@ defmodule Bamboo.TemplateTest do
end
def no_template do
- new_email()
- |> render(:non_existent)
+ render(new_email(), :non_existent)
end
def invalid_template do
- new_email()
- |> render("template.foobar")
+ render(new_email(), "template.foobar")
end
end
@@ -198,16 +189,14 @@ defmodule Bamboo.TemplateTest do
describe "assign/2" do
test "it accepts a map of assigns" do
email =
- Bamboo.Email.new_email()
- |> Bamboo.Template.assign(%{name: "Jules"})
+ Bamboo.Template.assign(Bamboo.Email.new_email(), %{name: "Jules"})
assert %{name: "Jules"} = email.assigns
end
test "it accepts a list of assigns" do
email =
- Bamboo.Email.new_email()
- |> Bamboo.Template.assign(name: "Jules")
+ Bamboo.Template.assign(Bamboo.Email.new_email(), name: "Jules")
assert %{name: "Jules"} = email.assigns
end
@@ -224,9 +213,7 @@ defmodule Bamboo.TemplateTest do
describe "assign/3" do
test "sets given assign in list of assigns" do
- email =
- Bamboo.Email.new_email()
- |> Bamboo.Template.assign(:name, "Jules")
+ email = Bamboo.Template.assign(Bamboo.Email.new_email(), :name, "Jules")
assert %{name: "Jules"} = email.assigns
end