Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/courrier/email/layouts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ def build
def no_layouts? = @email.class.layouts.nil?

def layouts
FORMATS.map(&:to_sym).to_h do |format|
FORMATS.map(&:to_sym).filter_map do |format|
template = @email.class.layouts[format]

next if template.nil?

[format, render(template)]
end
end.to_h
end

def render(template)
Expand Down
20 changes: 20 additions & 0 deletions test/courrier/email/layouts_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,24 @@ def test_mixed_layouts

assert_equal expected, Courrier::Email::Layouts.new(email).build
end

def test_html_only_layout
email = TestEmailWithHtmlOnlyLayout.new(
from: "devs@railsdesigner.com",
to: "recipient@railsdesigner.com"
)

assert_equal [{ html: "<html>%{content}</html>" }], Courrier::Email::Layouts.new(email).build
assert_equal "<html><p>Body</p></html>", email.options.html
end

def test_text_only_layout
email = TestEmailWithTextOnlyLayout.new(
from: "devs@railsdesigner.com",
to: "recipient@railsdesigner.com"
)

assert_equal [{ text: "%{content}\n\nThanks!" }], Courrier::Email::Layouts.new(email).build
assert_equal "Body\n\nThanks!", email.options.text
end
end
13 changes: 13 additions & 0 deletions test/fixtures/test_email_with_single_format_layouts.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require "courrier/email"

class TestEmailWithHtmlOnlyLayout < Courrier::Email
layout html: "<html>%{content}</html>"

def html = "<p>Body</p>"
end

class TestEmailWithTextOnlyLayout < Courrier::Email
layout text: "%{content}\n\nThanks!"

def text = "Body"
end
Loading