Skip to content

Commit

Permalink
added functionality to get letter opener save location from the mail (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jonmchan committed Feb 10, 2024
1 parent a2f5919 commit 1b9611f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/letter_opener/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ def render
File.open(filepath, 'w') do |f|
f.write ERB.new(template).result(binding)
end

mail["location_#{type}"] = filepath
end

def template
Expand Down
17 changes: 17 additions & 0 deletions spec/letter_opener/message_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,23 @@ def mail(options={}, &blk)
end
end

describe '#render' do
it 'records the saved email path for plain content type' do
mail = mail(:subject => 'test_mail')
message = described_class.new(mail, location: location)
message.render
expect(mail['location_plain'].value).to end_with('tmp/letter_opener/plain.html')
end


it 'records the saved email path for rich content type' do
mail = mail(:content_type => 'text/html', :subject => 'test_mail')
message = described_class.new(mail, location: location)
message.render
expect(mail['location_rich'].value).to end_with('tmp/letter_opener/rich.html')
end
end

describe '.rendered_messages' do
it 'uses configured default template if options not given' do
allow(LetterOpener.configuration).to receive(:location) { location }
Expand Down

0 comments on commit 1b9611f

Please sign in to comment.