Skip to content

Commit 1b9611f

Browse files
authored
added functionality to get letter opener save location from the mail (#207)
1 parent a2f5919 commit 1b9611f

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/letter_opener/message.rb

+2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ def render
5151
File.open(filepath, 'w') do |f|
5252
f.write ERB.new(template).result(binding)
5353
end
54+
55+
mail["location_#{type}"] = filepath
5456
end
5557

5658
def template

spec/letter_opener/message_spec.rb

+17
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,23 @@ def mail(options={}, &blk)
216216
end
217217
end
218218

219+
describe '#render' do
220+
it 'records the saved email path for plain content type' do
221+
mail = mail(:subject => 'test_mail')
222+
message = described_class.new(mail, location: location)
223+
message.render
224+
expect(mail['location_plain'].value).to end_with('tmp/letter_opener/plain.html')
225+
end
226+
227+
228+
it 'records the saved email path for rich content type' do
229+
mail = mail(:content_type => 'text/html', :subject => 'test_mail')
230+
message = described_class.new(mail, location: location)
231+
message.render
232+
expect(mail['location_rich'].value).to end_with('tmp/letter_opener/rich.html')
233+
end
234+
end
235+
219236
describe '.rendered_messages' do
220237
it 'uses configured default template if options not given' do
221238
allow(LetterOpener.configuration).to receive(:location) { location }

0 commit comments

Comments
 (0)