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
7 changes: 5 additions & 2 deletions lib/exception_notifier/email_notifier.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# encoding: utf-8

require "active_support/core_ext/hash/reverse_merge"
require 'action_mailer'
require 'action_dispatch'
Expand Down Expand Up @@ -74,8 +76,9 @@ def inspect_object(object)
when Hash, Array
object.inspect
else
object.to_s
end
object_str = object.to_s
object_str.frozen? ? object_str.dup : object_str
end.force_encoding(self.headers[:charset] || 'UTF-8')
end

def html_mail?
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<% filtered_env = @request.filtered_env -%>
<% max = filtered_env.keys.map(&:to_s).max { |a, b| a.length <=> b.length } -%>
<% filtered_env.keys.map(&:to_s).sort.each do |key| -%>
* <%= raw("%-*s: %s" % [max.length, key, inspect_object(filtered_env[key])]) %>
* <%= raw("%-*s: %s" % [max.length + 1, key, inspect_object(filtered_env[key])]) %>
<% end -%>
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</li>
<li>
<strong>Parameters:</strong>
<span><%= @request.filtered_parameters.inspect %></span>
<span><%= inspect_object(@request.filtered_parameters) %></span>
</li>
<li>
<strong>Timestamp:</strong>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
* URL : <%= raw @request.url %>
* HTTP Method: <%= raw @request.request_method %>
* IP address : <%= raw @request.remote_ip %>
* Parameters : <%= raw @request.filtered_parameters.inspect %>
* Timestamp : <%= raw Time.current %>
* Server : <%= raw Socket.gethostname %>
* URL : <%= raw inspect_object(@request.url) %>
* HTTP Method : <%= raw @request.request_method %>
* IP address : <%= raw @request.remote_ip %>
* Parameters : <%= raw inspect_object(@request.filtered_parameters) %>
* Timestamp : <%= raw Time.current %>
* Server : <%= raw Socket.gethostname %>
<% if defined?(Rails) && Rails.respond_to?(:root) %>
* Rails root : <%= raw Rails.root %>
* Rails root : <%= raw Rails.root %>
<% end %>
* Process: <%= raw $$ %>
* Process : <%= raw $$ %>
2 changes: 1 addition & 1 deletion test/dummy/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ../../..
specs:
exception_notification (4.1.0.rc1)
exception_notification (4.1.0)
actionmailer (>= 3.0.4)
activesupport (>= 3.0.4)

Expand Down
2 changes: 1 addition & 1 deletion test/dummy/test/functional/posts_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class PostsControllerTest < ActionController::TestCase
end

test "mail should contain timestamp of exception in body" do
assert @mail.encoded.include? "Timestamp : #{Time.current}"
assert @mail.encoded.include? "Timestamp : #{Time.current}"
end

test "mail should contain the newly defined section" do
Expand Down
29 changes: 29 additions & 0 deletions test/exception_notifier/email_notifier_request_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'test_helper'

class EmailNotifierRequestTest < ActiveSupport::TestCase
setup do
Time.stubs(:current).returns('Sat, 20 Apr 2013 20:58:55 UTC +00:00')

@email_notifier = ExceptionNotifier.registered_exception_notifier(:email)
begin
1/0
rescue => e
@exception = e
@mail = @email_notifier.create_email(
@exception,
:env => {
'REQUEST_METHOD' => 'GET'.freeze,
'HTTP_HOST' => 'example.com',
'QUERY_STRING' => 'data=привет&utf8=✓'.b,
'rack.input' => true
}
)
end
end

test "request mail should contain unicode in body" do
assert @mail.body.include? '✓'
assert @mail.body.include? 'привет'
end

end