forked from openSUSE/open-build-service
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix invalid byte sequence in UTF-8 in event mailer
Sometimes the build log contains invalid UTF-8 characters that raise an exception during email composing. Fixes openSUSE#6872
- Loading branch information
Showing
2 changed files
with
50 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe EventMailer, type: :mailer do | ||
describe '#event' do | ||
let(:expanded_payload) do | ||
{ | ||
'project' => 'project_2', | ||
'package' => 'package_2', | ||
'repository' => 'repository_2', | ||
'arch' => 'i585', | ||
'faillog' => "invalid byte sequence ->\xD3'" | ||
} | ||
end | ||
let(:from) { create(:confirmed_user) } | ||
let(:recipient) { create(:confirmed_user) } | ||
let(:event_stub) do | ||
double(:event, | ||
expanded_payload: expanded_payload, | ||
custom_headers: {}, | ||
template_name: 'build_fail', | ||
originator: from, | ||
subject: 'Test email', | ||
created_at: Time.now) | ||
end | ||
let(:mail) { EventMailer.event([recipient], event_stub) } | ||
|
||
it "renders the headers" do | ||
expect(mail.subject).to eq('Test email') | ||
expect(mail.to).to eq([recipient.email]) | ||
expect(mail.from).to eq([from.email]) | ||
end | ||
|
||
it "renders the body" do | ||
expect(mail.body.encoded).to match('Package project_2/package_2 failed to build in repository_2/i585') | ||
end | ||
end | ||
end |