Skip to content

Commit 5dd2a09

Browse files
authored
Merge pull request #4 from codergeek121/html-template
Simple email template with all information
2 parents 2e97ed3 + 383d17b commit 5dd2a09

File tree

6 files changed

+47
-21
lines changed

6 files changed

+47
-21
lines changed

Gemfile

+2
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ gem "sqlite3"
1010

1111
# Start debugger with binding.b [https://github.com/ruby/debug]
1212
gem "debug", ">= 1.0.0"
13+
14+
gem "rails-dom-testing"
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<tr>
2-
<td><%= frame %></td>
2+
<td style="font-family: monospace; padding: 2px;"><%= frame %></td>
33
</tr>
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
1-
<h1><%= @error.class %></h1>
2-
<p><%= @error.message %></p>
3-
4-
<div>
5-
<table border="1">
6-
<%= render(partial: "frame", collection: @backtrace) || render("no_backtrace") -%>
7-
</table>
8-
</div>
1+
<html>
2+
<body style="max-width: 768px; margin: 0 auto;">
3+
<h1 style="margin-top: 12px; font-family: sans-serif; font-size: 19px;"><%= @error.class %></h1>
4+
<h2 style="font-family: sans-serif; font-size: 15px;"><%= @error.message %></h2>
5+
6+
<p data-test-id="source">Source: <%= @source ? @source : "No source present" %></p>
7+
<p data-test-id="handled">Handled: <%= @handled ? "✅" : "❌" %></p>
8+
9+
<details style="margin-bottom: 12px;">
10+
<summary>Stacktrace</summary>
11+
12+
<table data-test-id="backtrace" border="1" width="100%" style="margin-top: 12px; margin-bottom: 12px; border-collapse: collapse; border-color: #000000">
13+
<%= render(partial: "frame", collection: @backtrace) || render("no_backtrace") -%>
14+
</table>
15+
</details>
16+
17+
<details>
18+
<summary>Context</summary>
19+
<pre data-test-id="context" style="font-family: mono; background: #eeeeee;"><code><%= @context %></code></pre>
20+
</details>
21+
</body>
22+
</html>

test/dummy/config/application.rb

+1
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@ class Application < Rails::Application
2222
#
2323
# config.time_zone = "Central Time (US & Canada)"
2424
# config.eager_load_paths << Rails.root.join("extras")
25+
config.action_mailer.default_options = { from: '[email protected]' }
2526
end
2627
end

test/dummy/config/environments/test.rb

+2
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,6 @@
6161

6262
# Raise error when a before_action's only/except options reference missing actions
6363
config.action_controller.raise_on_missing_callback_actions = true
64+
65+
config.email_error_reporter.to = ["[email protected]"]
6466
end

test/error_mailer_test.rb

+19-12
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,6 @@ class EmailErrorReporter::ErrorMailerTest < ActionMailer::TestCase
55
@exception = Exception.new("some message")
66
end
77

8-
test "renders the template correctly" do
9-
assert_equal [], error_mail.to
10-
assert_equal read_fixture("error").join, error_mail.body.to_s
11-
end
12-
13-
test "renders a backtrace" do
14-
@exception.set_backtrace(["foo", "bar"])
15-
16-
assert_equal [], error_mail.to
17-
assert_equal read_fixture("error_with_backtrace").join, error_mail.body.to_s
18-
end
19-
208
test "severity: error" do
219
email = error_mail(severity: :error)
2210
assert_equal "🔥" + " Exception", email.subject
@@ -32,6 +20,21 @@ class EmailErrorReporter::ErrorMailerTest < ActionMailer::TestCase
3220
assert_equal "ℹ️" + " Exception", email.subject
3321
end
3422

23+
test "email content" do
24+
@exception.set_backtrace(["foo", "bar"])
25+
email = error_mail(handled: true, severity: :info).deliver_now
26+
assert_dom_email do
27+
assert_dom "h1", "Exception"
28+
assert_dom "h2", "some message"
29+
assert_dom test_id("source"), "Source: No source present"
30+
assert_dom test_id("handled"), "Handled: ✅"
31+
assert_dom test_id("context"), "{}"
32+
assert_dom "table" do
33+
assert_dom "tr", 2
34+
end
35+
end
36+
end
37+
3538
private
3639

3740
def error_mail(**kwargs)
@@ -43,4 +46,8 @@ def error_mail(**kwargs)
4346
**kwargs
4447
)
4548
end
49+
50+
def test_id(value)
51+
"[data-test-id='#{value}']"
52+
end
4653
end

0 commit comments

Comments
 (0)